0

Following code is returning the length of allRows[] as 3, because it has 3 arrays in it. I am trying to build one final array 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;
  }

Actually getRows() is returning an array of promises. Following changes to my code has fixed 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;
  }
kvm006
  • 2,100
  • 2
  • 14
  • 20
  • Possible duplicate of [How to merge two arrays in Javascript and de-duplicate items](http://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items) – kamal pal Jun 01 '16 at 16:59

1 Answers1

2

Pushing adds one index, what you want is concat()

epascarello
  • 185,306
  • 18
  • 175
  • 214