Understanding protractor's use of promises

后端 未结 1 542
迷失自我
迷失自我 2021-01-16 04:49

Essentially I am playing around with getting a library for preconditions set up (think user creation). As protractor is promise-based and magically does all the wrapping to

1条回答
  •  清酒与你
    2021-01-16 05:37

    It's not enough just to create a protractor.promise deferred object - you need to tell the control flow about it. This is usually done with protractor.promise.controlFlow().execute().

    function timeout(ms) {
      protractor.promise.controlFlow().execute(function() {
        var deferred = protractor.promise.defer();
        setTimeout(function() {
          console.log('qwer');
          deferred.fulfill(true);
        }, ms);
        return deferred.promise;
      });
    }
    

    Read through https://code.google.com/p/selenium/source/browse/javascript/webdriver/promise.js for all the magic behind the scenes here.

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