1

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".

3
  • Does the all 299 rows are visible in one time? Or need enter next page or scroll down to make the rest rows are visible? Protractor only return visible elements when it interacting with. Commented Aug 23, 2020 at 2:08
  • Hi @yong you would have to scroll down the Angular Grid to see the remaining results Commented Aug 23, 2020 at 10:16
  • If in such case, Protractor worked as designed. Commented Aug 23, 2020 at 13:11

1 Answer 1

0

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(...)
})

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer. Is there a way to scroll down the angular grid also? As if a user scrolled to the bottom of the grid & saw all of the rows?
Also, is there a way you can apply this to my code above? I'm trying to apply it to the map within element.all but haven't been able to so far
Also, I replaced my code with yours above but am getting the same failure: Expected $.length = 30 to equal 299.
check the length of return NodeList by execute document.querySelectorAll('div.ag-cell[col-id="Spec"]') in browser devTool's console. Or you can give an example page url online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.