vendredi 9 août 2019

Trying to use async/await instead of browser.sleep, but it does not work

I am new to protractor and starting with automated testing of an angular app. I have one test, where I need to use multiple browser.sleep() to actually wait for the elements to render and click on them. With the browser.sleep() it works fine, but when I try to use async/await, the test fails, because it does not wait for the element.

I did set the SELENIUM_PROMISE_MANAGER: false, before I use the async/await

This one works:

browser.get(http://localhost);
browser.sleep(1000);
element(by.cssContainingText('.title1, 'text1')).click();
browser.sleep(1000);
element(by.cssContainingText('.title2', 'text2')).click();

This one does not work and says the second element could not be found:

it('should navigate to screen', async function() {
    browser.get(http://localhost);
    browser.wait(function () {
      return element(by.css('.top-navigation')).isPresent();
    }, 5000);
    await element(by.cssContainingText('.title1', 'text1')).click();
    await element(by.cssContainingText('.title2', 'text2')).click();
  });

Aucun commentaire:

Enregistrer un commentaire