【发布时间】:2017-06-02 12:17:59
【问题描述】:
考虑以下 sn-p:
getApiEndpoints.billingCycle()
.then(apiURL=>{
return RestClient.doGet(apiURL);
}).then(console.log(data))
在上面的 sn-p 中,getApiEndpoints.billingCycle() 和 RestClient.doGet(apiURL) 都返回承诺。上面的代码只是挂起 web 驱动程序,然后由于超时错误而崩溃。
这里有什么我遗漏的吗?
更新:RestClient.doGet(apiURL)
function doGet(url){
var defer = Helper.getPromise().defer();
request.get(url, (error, response, body) => {
if (response&&(response.statusCode == 200 || response.statusCode == 201)) {
defer.fulfill(JSON.parse(body));
} else {
defer.reject(error);
}
});
return defer.promise;
}
我尝试了什么
let flow = browser.controlFlow();
flow.execute(getApiEndpoints.billingCycle())
.then((apiURL)=> console.log(apiURL))
让我Failed: fn is not a function 错误...
【问题讨论】:
-
我不知道 Protractor,但 Promise 链对我来说看起来不错。
-
那么第二个中的
data是什么?我不知道你是否可以这样使用它:/ -
@echonax data 显然是响应......
-
你能像第一个一样试试
then((data)=>{console.log(data)})吗? -
我这样做了:同样的事情......:/
标签: angular promise protractor deferred