Protractor browser.wait doesn't wait

后端 未结 2 1332
走了就别回头了
走了就别回头了 2021-02-01 15:48

I am assuming that browser.wait should be a blocking call, but it is not working as I expected. Here is my sample:

descr         


        
2条回答
  •  余生分开走
    2021-02-01 16:23

    It is all about promises (actually every protractor question is about promises).

    browser.wait() is not a blocking call, it schedules a command to wait for a condition:

    Schedules a command to wait for a condition to hold, as defined by some user supplied function. If any errors occur while evaluating the wait, they will be allowed to propagate. In the event a condition returns a webdriver.promise.Promise, the polling loop will wait for it to be resolved and use the resolved value for evaluating whether the condition has been satisfied. The resolution time for a promise is factored into whether a wait has timed out.

    It would not call the function you are passing in immediately, it would schedule a command and wait for promise to be resolved (if the function inside returns a promise).

    You can use then() to have a correct order in this case:

    beforeEach(function() {
        browser.wait(function() {
            console.log('1 - BeforeEach WAIT');
            return true;
        }).then(function () {
            console.log('2 - BeforeEach after wait');
        });
    });
    

    See the use cases here:

    • How can I wait for a condition?

提交回复
热议问题