Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

getcurrentUrl|() #87

Closed
Douwe92 opened this issue Sep 12, 2013 · 6 comments
Closed

getcurrentUrl|() #87

Douwe92 opened this issue Sep 12, 2013 · 6 comments

Comments

@Douwe92
Copy link

Douwe92 commented Sep 12, 2013

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
Copy link
Author

Douwe92 commented Sep 12, 2013

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.

@stickel
Copy link

stickel commented Sep 12, 2013

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');
            });
    });

@juliemr
Copy link
Member

juliemr commented Sep 12, 2013

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.

@Douwe92
Copy link
Author

Douwe92 commented Sep 13, 2013

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?

@juliemr
Copy link
Member

juliemr commented Sep 13, 2013

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
Copy link
Member

juliemr commented Sep 13, 2013

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants