I’m writing a test on Cypress and I want to clear the field values before retries. How should I do it?
it('Fill info', { retries: 3 },function () {
cy
.get('#name')
.type('Test')
cy.intercept('POST', '**/api/**/Find')
.as('memberresponse')
cy
.get('.btn')
.click()
cy.wait('@memberresponse').then(xhr => {
cy.log(JSON.stringify(xhr.response.body));
cy.writeFile('***/memberinfo.json', xhr.response.body)
})
})
I want to clear the field value before retry in case of request doesn’t pass. What should I do?
2
Answers
Is this what you are looking for?
I presume clearing it every run (first or retry) is ok.
Otherwise you could include the page load (cy.visit) in the test.
Action before retry
I’ve used this pattern to handle repeating a
before()
hook when retry happens.You may be able to run your actions there.
Just add
clear
before typing like this: