Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In previous questions I have seen that a nice way to wait for the url to change is to use:

browser.wait( function() {
    return browser.getCurrentUrl().then(function(url) {
        return /myURL/.test(url);
    });
}, 10000, "url has not changed");`

But I am trying to have a method that I can pass myURL as a variable (in case I need to use it with other sites) and is not working.

I am trying this in my Page Object file:

this.waitUrl = function(myUrl) {
    browser.wait( function(myUrl) {
        return browser.getCurrentUrl().then(function(url, myUrl) {
            return myUrl.test(url);
        });
    }, 10000, "url has not changed");
};

Any ideas if this is even possible and how to do it if so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
395 views
Welcome To Ask or Share your Answers For Others

1 Answer

Update (July 2016): with Protractor 4.0.0 you can solve it with urlIs and urlContains built-in Expected Conditions.


Original answer:

Don't pass myUrl inside the then function, it is available from the page object function scope:

browser.wait(function() {
    return browser.getCurrentUrl().then(function(url) {
        return myUrl.test(url);
    });
}, 10000, "url has not changed");

I would though define it as an Expected Condition:

function waitUrl (myUrl) {
    return function () {
        return browser.getCurrentUrl().then(function(url) {
            return myUrl.test(url);
        });
    }
}

So that you can then use it this way:

browser.wait(waitUrl(/my.url/), 5000);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...