问题
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.
回答1:
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();
来源:https://stackoverflow.com/questions/60385480/cypress-canceling-an-api-request-upon-a-form-submit