为Angular App编写e2e测试,但我似乎无法理解异步编程和承诺。 我试图从第一列中获取每一行的值,并将其添加到数组中,最终将其从高到低排序,以获得最高值。 我在解决我的rows.each的承诺时遇到了一些麻烦,errormsg是: ' TypeError:undefined不是函数'
//This function will fetch the highest ID from the columns
this.getHighestScheduleId = (function(){
//Array to collect the ID's in
var idArray = [];
//Collects all the rows in our table
var rows = $$('#schedulesData');
//Goes through each row
rows.each(function(row){
//Collect all the row's elements in rowElems
var rowElems = row.$$('td');
console.log(rowElems[0].getText());
});
});
答案 0 :(得分:1)
map()
很适合这里:
rows.each(function(row) {
var rowElems = row.all('td').map(function (td) {
return td.getText();
});
// resolve the promise to see the output on the console
rowElems.then(function (values) {
console.log(values);
});
});