I am using Cypress to test a data export page which takes several minutes to generate an export. The page does not dynamically update, so I'd need to get Cypress to reload the page until the status shows as completed. I've looked through the Cypress docs and can't see a way to check if an element exists without throwing an exception if it doesn't.
I tried using jQuery but this resulted in an infinite loop:
describe('test reloading', function () {
it('testSelector reload', function () {
cy.visit('https://docs.cypress.io/api/utilities/$.html#Usage');
let found = false;
while (!found) {
const nonExistent = Cypress.$('.fake-selector');
if (!nonExistent.length) {
cy.reload();
} else {
found = true;
}
}
});
});
whileloop. - Gogowitsch