我很难从多ID返回文本,在夜行中使用elementIdText函数,它的优点来自于异步特性。
我得到了一个Web的数组,,并试图用来生成它们包含的文本数组。
我这样做是因为原始的getText函数不会迭代所有元素,而只是第一次出现。
我的共同职能:
module.exports = {
'ChildOf' : function(browser, path, callback) {
browser
.elements('css selector', path, function(elements) {
var array = [];
elements.value.forEach( function(element) {
array.push(element.ELEMENT);
})
//console.log(array); out: Final array filled; Works great
callback(array);
})
},
'getText' : function(browser, elements, callback) {
var array = [];
elements.forEach( function(element) {
browser.elementIdText(element, function(result) {
array.push(result.value);
//console.log(array); out: Multiple incremented arrays; Need the final array :\
})
//console.log(array); out: Multiple empty arrays; Doesn't work
})
//console.log(array); out: Single empty array; Doesn't work
callback(array);
}
]我的电话:
module.exports = {
'myStep' : function(browser, expect) {
common.ChildOf(browser, '.txt', function(elements) {
common.getText(browser, elements, function(result) {
//browser.verify.equal(result, expect)
})
})
}
};我需要从我的自定义getText函数中获得一个完整的字符串数组,我可以将它与另一个数组(数据驱动测试)进行比较,有什么想法吗?
发布于 2016-12-16 14:37:15
使用诺言(Q),添加了4行,这要感谢这 Nightwatchjs Github问题。
https://stackoverflow.com/questions/40980903
复制相似问题