问题描述
我正在尝试从使用不必要的指定wait()时间转换自定义cypress命令。我具有此登录功能:
Cypress.Commands.add("login",(email,password,app_form_id) =>{
cy.server()
cy.route(('https://web.fulcrumapp.com/dash/' + app_form_id)).as('getForm')
cy.visit('https://web.fulcrumapp.com/dash/' + app_form_id) //formid
cy.on('uncaught:exception',(err,runnable) => {
expect(err.message).to.include('ajax')
done()
//return false
})
cy.get("body").then($body => {
if ($body.find("#user_email").length > 0) { //if redirected to login
cy.get("#user_email").type(email) //Email
cy.get("#user_password").type(password) //password
cy.get('#user_remember_me').click()
cy.get(".login-action").click()//login and wait
Cypress.Cookies.defaults({
preserve: ['_fulcrum_session','remember_user_token','intercom-session-nxff46cx','membership']
})
}
cy.wait('@getForm')
});
})
基本上,当您初次运行测试时,它会将您重定向到登录页面,而不是将其带到指定的URL,如果发生这种情况,它将登录您,然后将您带回到原始URL。每当赛普拉斯尝试访问登录页面时,总是会发生2个Ajax错误,这些错误必须忽略,否则测试将失败。在所有这些之后,我指定了wait命令,因为我希望它等待URL的页面加载。该函数可以很好地完成所有这些工作,但是最后的wait()命令似乎不起作用,因为它不会等待页面加载并始终返回以下错误:
CypressError: Timed out retrying: `cy.wait()` timed out waiting `5000ms` for the 1st request to the route: `getForm`. No request ever occurred.
51 | cy.visit('https://web.fulcrumapp.com/dash/' + app_form_id) //formid
52 | cy.on('uncaught:exception',runnable) => {
> 53 | expect(err.message).to.include('ajax')
| ^
54 | done()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)