Best Practices for Writing and Debugging Cypress Tests

certificate
Recording and certification are available to Multipass and Full ticket holders only
Please login if you have one.
Rate this content
Bookmark

You probably know the story. You’ve created a couple of tests, and since you are using Cypress, you’ve done this pretty quickly. Seems like nothing is stopping you, but then – failed test. It wasn’t the app, wasn’t an error, the test was… flaky? Well yes. Test design is important no matter what tool you will use, Cypress included. The good news is that Cypress has a couple of tools behind its belt that can help you out. Join me on my workshop, where I’ll guide you away from the valley of anti-patterns into the fields of evergreen, stable tests. We’ll talk about common mistakes when writing your test as well as debug and unveil underlying problems. All with the goal of avoiding flakiness, and designing stable test.

This workshop has been presented at TestJS Summit 2023, check out the latest edition of this JavaScript Conference.

FAQ

Replay.IO is a project that Filip Hrits, a dev rel developer relations at Replay.IO and a Cypress ambassador, discusses during the workshop. It is described as a cool product that integrates well with the debugging process, particularly for Cypress tests. Replay.IO helps in recording and debugging applications, providing insights that go beyond traditional testing frameworks.

Currently, handling multiple tabs is not natively supported by Cypress. However, they have developed a workaround plugin that uses Puppeteer to manage multiple tabs as a temporary solution. This approach is still under evaluation to see if it meets user needs before potentially integrating it into Cypress natively.

Filip Hrits suggests using the Replay.IO tool to handle flaky tests in Cypress by recording tests and analyzing the recordings to understand and fix the root causes of the flakiness in the application code, rather than just in the tests themselves.

The workshop emphasizes understanding the application's behavior and using tools like Replay.IO to dig deeper into test failures. It also recommends using Cypress's native capabilities to time travel and debug tests, ensuring tests are not only passing but also reliable and indicative of the application's actual behavior in production.

Filip Hrits improves test reliability by using strategies like avoiding conditions in tests, ensuring tests are deterministic. For readability, he suggests using descriptive annotations within tests to make them easier to understand and debug, and employing tools like his Cypress plugin steps to visually annotate test steps in the Cypress runner.

Filip Hrits acknowledges that Playwright is catching up with Cypress in terms of features and might surpass it. However, he advises that if a project has a significant number of tests already in Cypress, migrating might not be beneficial solely for feature parity, especially if the existing tests are stable and well-maintained.

Filip Hric
Filip Hric
148 min
13 Dec, 2023

Comments

Sign in or register to post your comment.
  • Igor Gonak
    Igor Gonak
    Bonprix
    What is the duration of this workshop? I can't see it anywhere.

Video Summary and Transcription

The Workshop covered best practices and debugging of Cypress tests, including common mistakes and how to target the correct elements. The use of the 'contains' command was highlighted to ensure stable tests. Debugging and stability in Cypress tests were discussed, along with strategies for avoiding flaky tests and waiting for API calls. The importance of test readability and the use of tools like Cypress Plugin Steps and Replay for debugging were emphasized. The session command in Cypress was recommended for optimizing login sequences, and the differences between Cypress and Playwright were explored.
Video transcription and chapters available for users with access.