0

As part of a Protractor test on my Angular app, I am trying to count the number of rows in an Angular Grid.

I am able to count the number of columns using ag-header-cell as each header / column has that CSS class:

let list = element.all(by.css('div.ag-header-cell'));
expect(list.count()).toBe(3);

But when I try to apply the same logic to the rows within the grid, 0 rows are being returned.

My code:

let list = element.all(by.css('div.ag-row'));
expect(list.count()).toBe(10);

My error message: Expected 0 to be 10.

As you can see from the below snippet, several divs have the ag-row CSS class, so I don't know why it's not picking up any:

codeSnippet

user9847788
  • 2,135
  • 5
  • 31
  • 79
  • 1
    Maybe the `div.ag-row`'s get painted at a small time later and your code queries the dom too early. Try putting a pause of 5 seconds, then `let list = element.all(bycss('div.ag-row'))`. If this passes, then you know the grid is getting painted at a later point in time and you need to take care of this somehow. For unit tests (where I have this issue), I return a promise that resolves only when the whole grid is painted (by checking that number of rows and columns is good in the dom). Once this promise resolves, I continue with my assertions. – AliF50 Aug 17 '20 at 20:21
  • 1
    Hi @AliF50, before I saw your comment, I just tried using `browser.sleep(5000)` to see if that was the issue & that managed to show the correct count. I'll add a promise like you've mentioned above to deal with this. Thanks a lot! – user9847788 Aug 17 '20 at 20:26

0 Answers0