cypress-ag-grid
cypress-ag-grid copied to clipboard
Add re-tryability to getAgGridData
It would be great if re-tryability was built into the getAgGridData
function. Currently, the following example from the docs will fail if the grid data hasn't fully rendered at execution time.
cy.get(agGridSelector)
.getAgGridData({ onlyColumns: ["Year", "Make", "Model"] })
.then((actualTableData) => {
cy.get(agGridSelector).agGridValidateRowsSubset(actualTableData, expectedTableData);
});
});
I have a scenario using this exact syntax that fails intermittently, and it would be resolved if retries were built in.
Hi @westonsankey - for grids where the data takes a bit to load, you will need to wait for a cell to render. If you add the following before getting the data, it will work:
cy.get(“.ag-grid-cell”).should(“be.visible”)
I can work on a solution to have this baked in, but this check would fail on grids that are purposely empty. I’ll look into a reasonable solution and what may work best.
I've just started using this package on a project using
- Cypress v12.13.0
- ag-grid-angular v28.2.1
Unfortunately, the workaround no longer seems to apply.
I was able to modify your source to add re-tryability with the addQuery
API
e.g.
Cypress.Commands.addQuery('getAgGridDataWithRetry', getAgGridDataWithRetry);
and then something like this -
export const getAgGridDataWithRetry = (options = {}) => {
const getDataFn = (subject) => _getAgGrid(subject, options, false)
return (subject) => getDataFn(subject);
};
I forked your code and would create a PR for info, but then it caught my eye that the addQuery
will only work in Cypress v12 onwards so would not be backwards compatible.
Hi @BrookyNBS - Are you saying you are not able to successfully wait for a cell to render? We are using Cypress v13 and a newer version of ag-grid-angular, so you may possibly have a different selector other than .ag-grid-cell
.
Hey @kpmck - I'll see if I can review this again with newer versions, but iirc while the grid was loading, there was an empty cell with with this class 'ag-grid-cell' and I couldn't find an alternative selector. In the end, rather than change the library, I opted for some kind of check on the number of rows being displayed, this kept us moving at the time, but we were aware it wasn't bullet proof.
@BrookyNBS one thing we do at my org is we wait for the ag grid loaders to not exist before attempting any grid validations. This has been consistently successful for us - can you try and apply this check?
For us, it looks like this:
waitForGridToLoad(): void {
cy.log("waiting for Ag Grid to fully load data...").then(()=>{
const loaderSelector = 'ag-loading-text';
if (Cypress.$(loaderSelector){
cy.get(loaderSelector).should('not.exist', { timeout: 60000 });
}
})
}
hey @kpmck - I've just integrated that code and i'm running a few test cycles to see if they consistently pass. Your response was really timely as we've recently encountered a problem where when checking that data was ordered properly, our current tests were pulling back the grid data prior to it being properly rendered - so we were getting arrays of empty strings that were passing the ordering checks! I was having to force a short wait to help 'guarantee' the data was available.
So far so good though!