赛普拉斯在提交表单后取消api请求 [英] cypress canceling an api request upon a form submit
本文介绍了赛普拉斯在提交表单后取消api请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有一个表单提交给图ql api。当我单击提交按钮时,我看到cypress取消了对api的请求之一,然后它才能获得响应。任何想法如何防止这种情况?
编辑:我尝试添加cy.wait(6000);或cy.wait('apiAlias'),单击后提交,都没有帮助。
此处
function preventFormSubmitDefault(selector){
cy.get(selector).then(form $ => {
form $ .on( submit,e => ; {
e.preventDefault();
});
});
}
然后在测试中:
preventFormSubmitDefault( form);
cy.get(’[data-test = submitButton]’)。click();
Hello I have a form submit to a graph ql api. When I click the submit button I see that cypress cancels one of the requests to the api before it's able to get a response. Any idea how to prevent this? Edit: I've tried adding cy.wait(6000); or cy.wait('apiAlias'), post click submit, and neither help.
解决方案
Fixed this by preventing the default behavior of the form submit as suggested here
function preventFormSubmitDefault(selector) {
cy.get(selector).then(form$ => {
form$.on("submit", e => {
e.preventDefault();
});
});
}
And then in the test:
preventFormSubmitDefault("form");
cy.get('[data-test="submitButton"]').click();
这篇关于赛普拉斯在提交表单后取消api请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文