protractor icon indicating copy to clipboard operation
protractor copied to clipboard

getcurrentUrl|()

Open Douwe92 opened this issue 13 years ago • 6 comments

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?

Douwe92 avatar Sep 12 '13 07:09 Douwe92

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.

Douwe92 avatar Sep 12 '13 10:09 Douwe92

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 avatar Sep 12 '13 18:09 stickel

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.

juliemr avatar Sep 12 '13 18:09 juliemr

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?

Douwe92 avatar Sep 13 '13 07:09 Douwe92

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.

juliemr avatar Sep 13 '13 18:09 juliemr

Made a separate bug to consolidate these issues - now duplicate of #92

juliemr avatar Sep 13 '13 18:09 juliemr