vendredi 26 février 2021

Make Cypress wait for all requests to finish

I started with the following snippet. I noticed that some of the requests were being cancelled early because .click() only waits for a specific element to reach an actionable state (Cypress Docs) - instead of waiting for all of the page requests to finish.

  cy.visit('/about');
  cy.get('.favorite').click()
  cy.visit('');
  cy.get('.favorites').children().its('length').should('eq', 1);

I wrote the following as a way to intercept all requests and make sure that they finish before moving to the next action. However, it does not seem to work as requests are still being cancelled.

  cy.visit('/about');
  cy.intercept({method: 'GET', url: '**'}).as('getAbout');
  cy.wait('@getAbout');

  cy.get('.favorite').click()
  cy.intercept({method: 'GET', url: '**'}).as('favorite');
  cy.wait('@favorite');

  cy.visit('');
  cy.intercept({method: 'GET', url: '**'}).as('getBaseUrl');
  cy.wait('@getBaseUrl');

  cy.get('.favorites').children().its('length').should('eq', 1);

How do I make cypress wait for ALL requests to finish?

Is there a way to accomplish this in such a way that I do not have to add .wait() after every single page visit or button click?

Thanks

Aucun commentaire:

Enregistrer un commentaire