simonsmith/cypress-image-snapshot

Retry snapshot until it passes or times out

alaney opened this issue · 3 comments

alaney commented

I'm looking for a way to retry matching a snapshot until it passes. I have tried using waitUntil like

  cy.waitUntil(() => cy.get('canvas').matchImageSnapshot());

but the test fails on the first snapshot.

For context, I'm trying to test a CesiumJS map and I want to wait until the map is loaded and rendered correctly before proceeding with the test.

Any help is appreciated!

You mention canvas specifically there, which is a tricky one. I've noted this article gives a good overview of some solutions - https://glebbahmutov.com/blog/canvas-testing/

It links to this package as well - https://github.com/bahmutov/cypress-recurse

alaney commented

Thanks for that resource.

I was able to use cypress-recurse successfully like this:

    cy.recurse(
      () => cy.get('canvas').matchImageSnapshot(),
      (n) => n.pass,
      {
        timeout: 20000,
        delay: 1000,
        limit: 4,
      }
    );

Nice, that might make a good addition to the documentation. I'll leave this ticket open for that