Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

node.js - How to create and manipulate promises in Protractor?

I want to use the Node Http module to call my server directly in order to set up my Protractor tests. Http is callback based and I want to turn that into promises.

For example, I want to have this function return promise:

function callMyApi() {
  var promise = // somehow create promise;

  http.request({path: '/yada/yada', method: 'POST'}, function(resp) {
    promise.complete(resp);
  });

  return promise;
}

So, the question is: what do I need to require() and put in place of "somehow create promise" for this to work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Protractor uses WebDriver's promises and exposes that API globally on 'protractor'. So you should be able to do

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

For the full WebDriverJS Promise API, see the code at https://code.google.com/p/selenium/source/browse/javascript/webdriver/promise.js


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...