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

How to use browser.wait() to wait for URL to change? #610

@mcalthrop

Description

@mcalthrop

Hi

I want to write a Protractor test that waits until the current URL to change, so I have been looking at browser.wait(), combined with browser.getCurrentUrl().

However, I am not sure of how to use the two together: the browser.wait() method accepts as its first parameter a function that will return a boolean value – however, browser.getCurrentUrl() returns a promise.

My first attempt, which failed (as I expected), looks like this:

var currentUrl;
browser.getCurrentUrl().then(function (url) {
    currentUrl = url;
}).then(function () {
    return browser.wait(function () {
        return browser.getCurrentUrl().then(function (url) {
            return url !== currentUrl;
        });
    });
}).then(function () {
    // continue testing
});

Can anyone help?

many thanks

Matt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions