https://cypress.io logo
Wait for Animation to Complete
# i-need-help
e
Hey everyone! I'm having an issue with one of my tests and would love some advice. Currently the test is set to insure a user is able to download a file. All that works, but it is occasionally flaky due to our loading animation. It appears that Cypress is clicking the download button before the animation finishes and a request never gets sent, so my wait for a 200 in the response obviously fails. I've tried adding
should('not.be.visible')
for the svg elements of the animation but it always passes even though the animation is still going. Any input on how to handle this is much appreciated. If it helps our svg for this is:
Copy code
<svg xmlns="http://www.w3.org/2000/svg" width="80px" height="80px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
    <circle cx="50" cy="50" fill="none" stroke="#3F80F3" stroke-width="10" r="30" stroke-dasharray="141.37166941154067 49.12388980384689" transform="rotate(182.503 50 50)">
        <animateTransform attributeName="transform" type="rotate" calcMode="linear" values="0 50 50;360 50 50" keyTimes="0;1" dur="2s" begin="0s" repeatCount="indefinite" />
    </circle>
</svg>
g
but it keeps rotating no? Does the animation SVG get removed at the end? That is what you want to wait for, no?
e
Hey @gray-kilobyte-89541 First I just want to say thanks for all you do for the Cypress community. Your blog is very helpful and very well written. So even when the animation is finished I can still see the svg in the dom, so it doesn't seem like it's getting completely removed.
This is seen after animation is no longer loading on the page.
I know this isn't ideal, but here is how I was attempting to handle this in a custom command:
Copy code
Cypress.Commands.add('waitForSpinner', () => {
  cy.get('body').then((body) => {
    if (body.find('[id="SPINNER"]').length > 0) {
      cy.getById('SPINNER').should('not.be.visible');
    }
  });
});
g
I think there is a better way, but I don't understand what is happening. Can you make an HTML page showing the spinner and how it is removed? Does it go away when something loads? Does it stop?
e
It does go away from view once it stops, but it also doesn't seem to cover any elements from cypress to interact with. Hence the request never really getting sent when the download button is selected.
I'm pretty new to this so making an HTML page to show as an example would take a lot longer than it would be worth 😀
g
e
That's awesome! Thanks for doing that so quickly. I'll go into the code and see how that load icon is called and use the class like you have here to check for the
exist
e
Thanks again, that put me on the right track. I found that I was checking for elements within our Sprite sheet that was always getting rendered. Currently going in and adding a data-testid to use to check if it exists to continue with test.
10 Views