Use cy.only in order to run only a single test in a cypress test suite

Tomasz Łakomy
InstructorTomasz Łakomy
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Developers need to focus to do their job right.

Cypress tests are no different - sometimes we have a large suite of cypress tests but unfortunately one of them is failing :(

We're lucky that it's only one, but when we dig in and debug, we find ourselves being slowed done because we need to wait for all those passing tests to finish in order to focus on the failing one.

In this quick lesson we're going to learn how to use .only in cypress suite in order to run only a single test that we've chosen.

Tomasz Łakomy: [0:00] Right now, we have a failing Cypress test. The problem is that we are trying to debug it but if I restart all those tests, unfortunately, one of those is a very long test. It is going to just wait for 10 seconds and do nothing at all. This makes us very slow. Instead, I would like to focus on this test alone in order to assert what exactly is going on here.

[0:18] In order to run a single test in a Cypress suit, we can just do it.only and save that. That is going to run this test alone, which makes it much easier for us to debug what is going on. Right now, we can see that we are expecting three elements and instead, we do have two elements over here.

[0:34] If I just go ahead and fix that, save and then start the test, it is going to pass. This allows us to focus on this test alone. If I remove that, it is going to execute all those tests.

egghead
egghead
~ 16 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today