When I run the following code, it returns the length of allRows[] as 3 because there are 3 arrays in it. My goal is to create one final array called allRows.
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;
}
getRows() actually returns an array of promises. The changes I made to my code have resolved the issue.
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;
}