Today I will unlock the lesson “Spec 14” of the Cypress Network Testing Exercises course. This lesson teaches how to write recursive tests that repeat Cypress commands until some condition becomes true. I hope you like it! We are going to use the same application and the same repo with the test placeholders, so read the Advent Lesson Day 1 post, if you need to set them up.
Can you implement the test starting with this placeholder code?
it('reloads the page until it shows Bananas', () => {
// visit the page
// if it shows the fruit "Bananas", stop
// else
// wait for 1 second for clarity
// reload the page
// check again
// Tip: use recursion
})
Good luck!
Previous lessons
Lessons marked with 📡 are from the Cypress Network Testing Exercises course. Lessons marked with 🔌 are from the Cypress Plugins course.
Day 1: 📡 “Spec 08: Import the JSON fixture directly into the spec”
Got lost a bit because I was trying to use cypress-recurse :) and couldn't figure it out. But it was so simple the way you solved it by calling the function again in the else block.
I stubbed the /fruit endpoint instead of using cy.wait and was definitively stuck on how would I go about telling the browser reload until you see the expected text. I can already see a practical use I can implement on some of my tests, for instance one of them being that I have to reload a page until I get a response back and shows sent email icon. 👍