user9847788
user9847788

Reputation: 2445

Protractor test only testing some rows of Angular Grid

I am trying to write a Protractor test to validate the text within each cell in the first row of an Angular Grid.

The Angular Grid has 299 rows, but only 30 rows are being tested for some reason.

I have removed some of the Expected Results & error message below to make it easier to read.

Protractor Code:

it('should validate the Spec column(first column) in the Table', () => {
        element.all(by.css('div.ag-cell[col-id="Spec"]'))
            .map(function (cell) {
                return cell.getText();
            })
            .then(function (cellValues) {
                expect(cellValues).toEqual(["2205", "2205", "2304", "2507", "254SMO", "26-4-4", "29-4", "302", "304", "304H", "304L", "304N", "305", "308", "309", "309S", "310",
                    "310S", "316", "316H", "316L", "316N", "317", "317L", "321", "321H", "329", "330", "347", "3RE60", "405", "409", "410", "410S", "420", "430", "440A", "440B", "440C", "44LN",
                    "654SMO", " 70/30 CuNi", "7Mo Plus", plus a lot more expected results]);
            })
    });

Error Message:

    Expected $.length = 30 to equal 299.
    Expected $[30] = undefined to equal '405'.
    Expected $[31] = undefined to equal '409'.
    Plus a lot more

Can someone please tell me why it's only picking up a few of the cells?

Below, you can see one of the rows that is appearing undefined has col-id="Spec" so I don't know why that isn't being picked up in the test

enter image description here

Note: I've inspected the cells not being picked up & they have col-id="Spec".

Upvotes: 1

Views: 300

Answers (1)

yong
yong

Reputation: 13712

If you not strict on end to end (test case strict follow user experience), you can use browser.executeScript() to get all rows as following:

let _ = function(){
  cells = document.querySelectorAll('div.ag-cell[col-id="Spec"]')
  return Array.from(cells).map(function(cell){ return cell.textContent })
}

browser.executeScript(_).then(function(cellValues){
  expect(cellValues).toEqual(...)
})

Upvotes: 0

Related Questions