Protractor timeouts

前端 未结 2 1550
我在风中等你
我在风中等你 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:42

    This is the way if you want to perform any action when element present or want to wait until it present on page.

        element(by.id).isPresent().then(function(result) {
                if (result) {
                    nextButton.click();
                }
                else{
                    browser.wait(function () {
                        return browser.isElementPresent(element(by.id));
                    },50000);
                }
            }).then(function () {
                nextButton.click();
            });
    
        },
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题