getcurrentUrl|()
it('should login to the backoffice', function () { var url = ptor.getCurrentUrl(); ptor.findElement(protractor.By.input('username')).sendKeys('username'); ptor.findElement(protractor.By.input('password')).sendKeys('lol'); ptor.findElement(protractor.By.id('login')).click(); var url2 = ptor.getCurrentUrl(); expect(url2).toEqual(url + 'site.lol'); });
Expected 'https://link.com//' to equal '[object Object]site.lol'
Somehow it doesn't want to see url in the toEqual?
The reason I want to save it to a variable is because the thing I need to test has test builds that change every so often.
It's seeing the URL in the toEqual, but getCurrentUrl() returns a promise.
Try this:
ptor.getCurrentUrl().
then(function(url) {
ptor.findElement(protractor.By.input('user')).sendKeys('user');
ptor.findElement(protractor.By.input('pass')).sendKeys('pass');
ptor.findElement(protractor.By.id('login')).click().
then(function(newUrl) {
expect(newUrl).toEqual(url + 'site.lol');
});
});
stickel's got it.
At the risk of TMI - it would be valid to say
expect(url2).toEqual(url);
because expect has been patched to understand promises. However, url + 'string' is not valid, since the + operator can't be patched to understand promises! Hope that helps.
So yeah it's working but the script is going so fast it's getting the url same as the first. Is there a way to make the script wait? while the page gets loaded?
Ah, getCurrentUrl() isn't currently one of the functions that Protractor waits for Angular to settle down before calling. You can do:
ptor.waitForAngular();
ptor.getCurrentUrl().then...
That should fix it. I'll consider adding getCurrentUrl() to the functions that automatically wait.
Made a separate bug to consolidate these issues - now duplicate of #92