I got form and when I trigger click on submit button this cause to refresh current page. After that I would like to do some assertions. How I know that page finished refreshing and I can start to searching an element?
cy.get('#formButton').click() // adds new item and refresh page
// do assertions on page
This solution was posted by @msty on a similar GitHub issues:
// Navigate / submit form
cy.click('#someButtonToNavigateOnNewPage');
cy.location('pathname', {timeout: 10000})
.should('include', '/newPage');
// Do assertions here
cy.contains('h1', 'success')
Another solution from the Cypress Docs is:
// Wait for the route aliased as 'getAccount' to respond
// without changing or stubbing its response
cy.server()
cy.route('/accounts/*').as('getAccount')
cy.visit('/accounts/123')
cy.wait('@getAccount').then((xhr) => {
// we can now access the low level xhr
// that contains the request body,
// response body, status, etc
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With