Thunfische
Thunfische

Reputation: 1157

Protractor how to wait until browser.get to a url

    await browser.wait(function() {
        return browser.getCurrentUrl().then(function(url) {
          return `cars/detail.aspx${browser.baseUrl}`;
        });
      }, 5000, "url err"); 

How do I make protractor wait until cars/detail.aspx${browser.baseUrl} is loaded?

Upvotes: 0

Views: 326

Answers (3)

Joaquin Casco
Joaquin Casco

Reputation: 734

You can read the Protractor's API documentation for further information on different ways of waiting for an element (url in this case) https://www.protractortest.org/#/api
You have 2 ways actually:

const EC = protractor.ExpectedConditions;
const myUrl = 'cars/detail.aspx${browser.baseUrl}';  

then:

return browser.wait(EC.urlIs(myUrl));

OR

return browser.wait(EC.urlContains(myUrl));

Upvotes: 0

Kuba Lubas
Kuba Lubas

Reputation: 91

I'm using this method, maybe it will be helpful

export function waitForUrlContains(url: string, customTimeout: number = E2E_TIMEOUT) {
    return browser.getCurrentUrl().then(myUrl => {
      return browser.wait(protractor.ExpectedConditions.urlContains(url), customTimeout, `URL do not contain: ${url}, and is: ${myUrl}`);
    });
  }

Upvotes: 0

demouser123
demouser123

Reputation: 4264

I think you can use the urlContains expected condition in protractor to wait until the url contains something specific. You can refer to the documentation here.

Upvotes: 1

Related Questions