Sometimes the test fails and immediately passes on the next try. Cypress calls such tests “flakey” and has a built-in feature “test retries” to automatically deal with them. It is an opt-in feature; it lets you avoid blocking the CI pipeline without ignoring such random failures. Today, we will practice using test retries to get over simulated network failures. Try implementing “Spec 30: Handles test flake using the test retries” test.
New Blog Post
Don’t miss reading my new blog post “Cypress V12 Is A Big Deal”. I love the new query commands that retry the entire chain (even if I found a couple of issues #25134 and #25078).
cy.get('#prices li') // query ↰
.last() // query | retries
.should('contain', 'Potatoes') // assertion fails 」
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”
Day 2: 📡 “Spec 14: Reloads the page until it sees the word Bananas"Cypress
Day 3: 🔌 “Lesson a3: Log the messages from the test to the terminal“
Day 4: 📡 “Spec 04: The application is showing the loading element“
Day 5: 📡 “Spec 11: Test how the application makes a network request every minute”
Day 6: 🔌 “Lesson a7: Re-run the tests when the source files change with cypress-watch-and-reload plugin“
Day 7: 📡 “Spec 16: Get the fruits from the test using the cy.request command“
Day 8: 📡 “Spec 19: Intercept a specific request by matching the header”
Day 9: 🔌 “Lesson b1: Slow down the test commands using cypress-slow-down“
Day 10: 📡 “Spec 21: Modify the server response using cy.intercept”
Day 11: 📡 “Spec 22: Using cy.wait vs cy.get to access the intercepted request”
Day 12: 🔌 “Lesson l1: Confirm the attribute of the last item”
Day 13: 📡 “Spec 27: Simulate the server network error”
Hi Gleb,
thank you for the lesson. This one was nice and simple :)
I've found a strange moment in the lesson code:
if (something about the response) {
response.send( fixxture: 'success.json' })
}
Shouldn't it be:
if (something about the response) {
response.send({ fixture: 'success.json' })
}
?
And why did you use req.reply for 30% error response? Isn't it simpler to stub, like this:
cy.intercept('GET', '/fruit', Math.random() < 0.3 ? { statusCode: 500 } : undefined)
?