Cypress v6 network examples using cy.intercept
npm install
npx cypress open
See more information at:
- cy.intercept documentation page
- Network Requests example page
cy.intercept
recipe- Difference between cy.route and cy.route2 blog post (
cy.route2
was the experimental command name before it became the officialcy.intercept
)
Watch the video of the introduction at https://youtu.be/_wfKbYQlP_Y
See cypress/integration/spec.js, here is a fragment that stubs Ajax call to external domain to fetch three users:
// https://on.cypress.io/intercept
cy.intercept({
pathname: '/users',
query: {
_limit: '3'
}
}, {
fixture: 'users.json',
headers: {
'Access-Control-Allow-Origin': '*'
}
}).as('users')
cy.get('#load-users').click()
cy.wait('@users')