protractor - how to get the result of an array of promises into another array(量角器 - 如何将一组承诺的结果放入另一个数组)
问题描述
我从这段代码中得到了一系列承诺:element.all(by.repeater('unit in units')),我发现很难将数据放入另一个数组:
I got an array of promises from this code: element.all(by.repeater('unit in units')), and I am finding it really difficult to get the data into another array:
element.all(by.repeater('unit in units')).then(function (arr) {
var items = [];
for (var i = 0; i < arr.length; i++) {
arr[i].getText().then(function(text) {
items.push(text);
});
}
//PROBLEM ITEMS is Empty
console.log(items);
});
推荐答案
设法以更简单的方式获得相同的结果,避免使用 Q 和中继器.使用内置地图就可以了.
Managed to get the same result on a simpler way avoiding using Q and the repeater. Using the inbuilt map does the trick.
var tabs = element.all(by.css('.unitTabs li a')).map(function (elm) {
return elm.getText();
});
tabs.then(function (result) {
var sorted = _.sortBy(result, function (name) { return name; });
for (var i = 0; i < result.length; i++) {
expect(result[i]).toBe(sorted[i]);
}
});
这篇关于量角器 - 如何将一组承诺的结果放入另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:量角器 - 如何将一组承诺的结果放入另一个数组
基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
