Dallin
Dallin

Reputation: 1074

How to wait for rows to load with Protractor

I'm trying to use protractor to select a row, count rows, etc. This doesn't seem to be working:

var GridTestUtils = require('./gridObjectTestUtils.spec.js');

var GridTestObj = new GridTestUtils('exampleGrid');
var Grid = GridTestObj.getGrid();

browser.wait(function(){

    return Grid.isPresent();

}, 1000).then(function(){

    GridTestObj.expectRowCount( 25 );

});

It seems as though it's trying to find the rows before they're loaded. The test keeps failing with 'Expected 0 to equal 25'.

I can get it to work if I use browser.sleep but there has to be a better solution than that.

How do I tell protractor to wait for Angular ui-grid to load completely?

Upvotes: 1

Views: 1706

Answers (1)

alecxe
alecxe

Reputation: 473833

I would do that with browser.wait() and a custom Expected Condition:

var rows = Grid.element( by.css('.ui-grid-render-container-body')).all( by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index') );

browser.wait(function () {
    return rows.count().then(function (countValue) { 
        return countValue > 0;
    });
}, 5000);

In this case, protractor would execute the function passed into browser.wait() continuously until it evaluates to true or the timeout happens (in 5 seconds).

Upvotes: 2

Related Questions