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

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.