如何创建和操纵量角器的承诺? [英] How to create and manipulate promises in Protractor?

查看:116
本文介绍了如何创建和操纵量角器的承诺?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用的节点HTTP模块直接调用我的服务器,以建立我的量角器测试。 HTTP是基于回调,我想将其转换成的承诺。

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?

推荐答案

量角器使用的webdriver的承诺,并在全球范围公开了API的量角器。所以,你应该能够做到

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;

有关完整WebDriverJS无极API,见code。在<一个href=\"https://$c$c.google.com/p/selenium/source/browse/javascript/webdriver/promise.js\">https://$c$c.google.com/p/selenium/source/browse/javascript/webdriver/promise.js

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

这篇关于如何创建和操纵量角器的承诺?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆