单击后如何在cypress中等待页面完成重新加载?
我得到了表单,当我触发时,点击提交按钮,这会导致刷新当前页面。在那之后,我想做一些断言。我如何知道该页面已完成刷新,并且可以开始搜索元素单击后如何在cypress中等待页面完成重新加载?,cypress,Cypress,我得到了表单,当我触发时,点击提交按钮,这会导致刷新当前页面。在那之后,我想做一些断言。我如何知道该页面已完成刷新,并且可以开始搜索元素 cy.get('#formButton').click() // adds new item and refresh page // do assertions on page 5种方式: 1) 在不刷新的情况下制作SPA,更改DOM后使用回调/承诺 2) 设置cookie,刷新页面,每次页面加载时使用条件如下: if (existsRefreshCooki
cy.get('#formButton').click() // adds new item and refresh page
// do assertions on page
5种方式:
1) 在不刷新的情况下制作SPA,更改DOM后使用回调/承诺
2) 设置cookie,刷新页面,每次页面加载时使用条件如下:
if (existsRefreshCookieAfterFormSubmit()) { ...
3) 只需阻止表单发送,如:
form.onsubmit = function() { return false; };
4) 使用
代替
或
5) 不要将
用作输入的父级,仅使用输入。此解决方案是:
另一个解决方案是:
勾选此问题,可能会有帮助:
// Navigate / submit form
cy.click('#someButtonToNavigateOnNewPage');
cy.location('pathname', {timeout: 10000})
.should('include', '/newPage');
// Do assertions here
cy.contains('h1', 'success')
// 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
})