Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add re-tryability to getAgGridData #25

Open
wessankey opened this issue Jul 19, 2022 · 7 comments
Open

Add re-tryability to getAgGridData #25

wessankey opened this issue Jul 19, 2022 · 7 comments

Comments

@wessankey
Copy link

wessankey commented Jul 19, 2022

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.

@kpmck
Copy link
Owner

kpmck commented Jul 19, 2022

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.

@BrookyNBS
Copy link

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.

@kpmck
Copy link
Owner

kpmck commented Oct 4, 2023

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.

@BrookyNBS
Copy link

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.

@kpmck
Copy link
Owner

kpmck commented Jan 21, 2024

@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 });
    }
  })
}

@BrookyNBS
Copy link

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!

@wandering-tales
Copy link
Contributor

@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 });
    }
  })
}

Couldn't this check cause race issues if the loader itself doesn't show up in time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants