Le code suivant renvoie la longueur de allRows [] en tant que 3, car il contient 3 tableaux. J'essaye de construire un tableau final allRows.Le fait de pousser plusieurs tableaux en un seul constitue un tableau à deux dimensions
getRows() {
return this.element.all(by.css(".xyz")).getText();
}
getTotalRows() {
const allRows = [];
for (let i = 0; i < 3; i++) {
allRows.push(this.getRows());
this.scrollDown();
this.waitToLoad();
}
return allRows;
}
En fait getRows() est de renvoyer un tableau de promesses. À la suite des modifications à mon code a résolu le problème
getRows() {
return this.pinnedRows.getText();
}
getTotalRows() {
const defer = Promise.defer();
let allRows = [];
for (let i = 0; i < 3; i++) {
this.getRows().then((rows) => {
allRows = allRows.concat(rows);
this.scrollDown();
this.waitToLoad();
if (i === 2) {
defer.resolve(allRows);
}
});
}
return defer.promise;
}
double possible de [Comment fusionner deux tableaux en Javascript et de-double items] (http://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items) –