creating and resolving promises in protractor

后端 未结 3 1998
抹茶落季
抹茶落季 2020-12-05 07:36

I am writing a test case for adding store information in the page for Angular app using Protractor, where initially I am counting the number of stores I already have and aft

3条回答
  •  独厮守ぢ
    2020-12-05 08:06

    Creation

    For creating a promise in protractor, you have to write:

    var deferred = protractor.promise.defer();
    var promise = deferred.promise;
    

    Callbacks

    The callbacks are invoked asynchronously. You can register one (or more) "on success" callbacks:

    promise.then(function() {
       ...
    });
    

    you can also register one (or more) "on error" callback:

    promise.then(null, function() {
       ...
    });
    

    These registrations could be chained:

    promise.then(function() {
       ...
    }).then(function() {
       ...
    }).then(null, function() {
       ...
    }).then(function() {
    
    }, function() {
       ...
    }).then(onSuccess, onFailure);
    

    Resolution

    Success

    The "on success" callbacks are invoked when the promise is resolved successfully:

    deferred.fulfill(value);
    

    Failure

    The "on failure" callbacks are invoked when the promise is resolved successfully:

    deferred.reject(new Error('a problem occurs'));
    

    In your code

    you missed the resolution step. You have to fulfill the promise.

    A more complete reference is available in the Webdriver.js documentation

提交回复
热议问题