Protractor timeouts

前端 未结 2 1549
我在风中等你
我在风中等你 2021-02-04 12:00

I\'ve been developing automated tests in Protractor for quite some time and like many of you, I\'ve run into gaps which can only be crossed with the browser.sleep()

2条回答
  •  别跟我提以往
    2021-02-04 12:47

    If you can devise some sort of test to determine if whatever you're waiting for has completed, you can use browser.wait. Taking ideas from from http://docsplendid.com/archives/209, you can pass a function that returns a promise that resolves to true or false, such as one that uses isPresent

    browser.wait(function() {
      return element(by.id('some-element')).isPresent();
    }, 1000);
    

    or if you have some more complicated condition you can use promise chaining:

    browser.wait(function() {
      return element(by.id('some-element')).isPresent().then(function(isPresent) {
        return !isPresent;
      });
    }, 1000);
    

    and the command flow will wait, repeatedly calling the function passed to wait, until the promise it returns resolves to true.

提交回复
热议问题