waiting.spec.js 992 B

12345678910111213141516171819202122232425262728293031
  1. /// <reference types="cypress" />
  2. context('Waiting', () => {
  3. beforeEach(() => {
  4. cy.visit('https://example.cypress.io/commands/waiting')
  5. })
  6. // BE CAREFUL of adding unnecessary wait times.
  7. // https://on.cypress.io/best-practices#Unnecessary-Waiting
  8. // https://on.cypress.io/wait
  9. it('cy.wait() - wait for a specific amount of time', () => {
  10. cy.get('.wait-input1').type('Wait 1000ms after typing')
  11. cy.wait(1000)
  12. cy.get('.wait-input2').type('Wait 1000ms after typing')
  13. cy.wait(1000)
  14. cy.get('.wait-input3').type('Wait 1000ms after typing')
  15. cy.wait(1000)
  16. })
  17. it('cy.wait() - wait for a specific route', () => {
  18. // Listen to GET to comments/1
  19. cy.intercept('GET', '**/comments/*').as('getComment')
  20. // we have code that gets a comment when
  21. // the button is clicked in scripts.js
  22. cy.get('.network-btn').click()
  23. // wait for GET comments/1
  24. cy.wait('@getComment').its('response.statusCode').should('be.oneOf', [200, 304])
  25. })
  26. })