How to getText from all rows & columns in an infinite scrolling ng-grid using protractor?

ε祈祈猫儿з 提交于 2019-12-03 09:39:30
kvm006

I am able to scroll through the grid and get the data from all rows in the following way. I got the scrollDown code from Protractor: Scrolling a table and testing for infinite scroll (thanks @alecxe)

There is little hard coding in the for loop. I should find out a way to know how many times I should scrollDown the table. Also the final result have some duplicates will need to clean it up.

  
    scrollDown() {
    return browser.executeScript("return arguments[0].offsetTop;", this.lastRow.getWebElement()).then((offset) => {
      browser.executeScript("arguments[0].scrollTop = arguments[1];", element(by.className("ag-body-viewport")).getWebElement(), offset);
    });
  }

  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;
  }

  waitToLoad() {
    waitFor.elementToBeVisible(this.pinnedRows.get(15));
    browser.waitForAngular();
  }

In the spec:

  getTotalRows().then((data) => {
      log.info(`TOTAL ROWS: ${data}`);
      log.info(`TOTAL NUMBER OF ROWS : ${data.length}`);
      expect(data.length).toBeGreaterThan(50);
    });

You need to find the last row from the dom and use scrollintoview javascript function. please find the example below.

var last_row=element.all(by.css(".ag-row")).last() //this will give you the last row from the grid
browser.executeScript("arguments[0].scrollIntoView();",last_row.getWebElement());

This will scroll the entire grid.Now you can get all the text from row by

element.all(by.css(".ag-row")).getText().then(function(RowValueArray) { 
         //do whatever you want to do with the values.
})

Hope it helps you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!