Chris Hansen
Chris Hansen

Reputation: 8657

Is there a way to wait for a url to contain a certain value in nightwatch

There is a function waitForElementVisible to wait for an element to be visible. Is there a way to wait for a url to chain to a specific value using the nightwatch API?

Upvotes: 1

Views: 4573

Answers (2)

alcoforado
alcoforado

Reputation: 556

You can use assertions to wait for the url change by calling

browser.assert.urlEquals(newUrl)

The trick here is that Assertions can be globally set to poll many times during a time interval until the required condition is met. After that period it will finally give up and return an error. The time interval can be set using the property waitForConditionTimeout in nightwatch.json globals section. An example follows

    "test_settings" : {
  "chrome" : {
    "launch_url" : "http://localhost",
    "selenium_port"  : 9515,
    "selenium_host"  : "localhost",
    "silent": true,
    "driver": "chrome",
    "default_path_prefix": "",
    "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions" : {
          "args" : ["--no-sandbox","window-size=1280,800"]
        }
    },
    "globals": {
      "waitForConditionTimeout": 5000,
      "retryAssertionTimeout": 20000
    }}}

Upvotes: 2

Bao Tran
Bao Tran

Reputation: 626

Currently we dont have waitForUrlEqual() , but if url change ,you should wait for a specific element visible/present.

Eg: after you log in, the element ('input.password') will be not present, so that : instead of browser.waitForUrlEqual(newurl) ,

we can try

browser .waitForElementNotPresent('@password',5000) .verify.url(newUrl)

Upvotes: 0

Related Questions