Cypress Disable Test: How to use Skip and Only in Cypress

On This Page When to disable tests in Cypress?April 06, 2026 · 16 min read · Tool Comparison

Cypress Disable Test: How to use Skip and Only in Cypress

Disabling tests in Cypress is a useful proficiency that assist to continue tests form and trim the clip it conduct to run the test suite. It temporarily prevents a test from running or be included in your test suite. This can be useful when you are working on a new feature or bug and want to pore on a specific set of tests or when you need to temporarily hop-skip a failing test. The skipped test instance would be temporarily excluded piece running as piece of your test suite, but it continue piece of your test suite.

Overview

Why skip tryout in Cypress?

  • Temporarily exclude tests which are uncompleted or irrelevant.
  • Focus test runs on high-priority areas.

How to cut examination?

  • Use it.skip () to skip individual tests.
  • Use describe.skip () to skip the full test rooms.
  • Use .only () to run just specific tests.
  • Skip exam at the global level by making the changes in the config file

Conditional skips in Cypress

  • Use the cypress-select-tests plugin to filtrate and choose tests based on different conditions.
  • cy.skipOn () & # 8211; skips the test alone on specified conditions
  • cy.onlyOn () & # 8211; lead the examination only on specified conditions

Benefits of Cypress Disable Test

  • Run the former tests in the tryout suite without being blocked by bugs.
  • Disable tests temporarily to debug intermittent failure.
  • Run selected tests under specific conditions or environment.

In this blog, we will explore different shipway to disable tests and how to run examination conditionally in Cypress.

When to disable tests in Cypress?

Disabling tests in Cypress can be useful in many scenarios, from debug to execution optimisation. By temporarily disable tests, you can proceed your test suite organized, effective, and effective.

There are respective situations when it is appropriate to disable tests in Cypress. Below are the most common ones:

  1. Test Case Fails Due to a Bug:When a tryout cause fail due to a bug in your application, you can disable the test temporarily while developer work on secure the bug. This way, you can proceed to run the other tests in your test suite without be blocked by the failed tryout cause.
  2. Running a Subset of Tests:Cypress grant you to run a subset of tests in your test suite by specifying a particular test file or test case to run. However, if you want to run all the tests in your test rooms except for a few, you can disable the exam temporarily.
  3. Ignoring Tests in CI/CD Pipeline:When running tests in a CI/CD pipeline, you may need to skip certain tests that are known to be eccentric or unstable. In such cases, you can disable those tests temporarily so they are not fulfill as part of the pipeline.
  4. Debugging:If you are encountering an number with a trial, you can disable it temporarily while you debug it. Disabling tests temporarily can be helpful when you get a test that fails intermittently. By invalid this test, you can run the remain tests speedily and name the knotty trial, reducing the overall time taken to run the test cortege.
  5. Refactoring codification:If you are do change to the code be tested, you may need to temporarily disable tests that are affected by those modification.
  6. Testing under specific weather:In some scenario, you might need to run specific tests merely under specific conditions or on specific surround (For example, If you require to run alone on Chrome or if you want to run only on MAC). In such lawsuit, running tests conditionally in Cypress can be helpful.

Different ways to disable a test in Cypress

In Cypress, you can disable a test by using the .skip(), .only()or making changes in theconfig file.

Below is a detailed explanation of all the 3 approaches:

1. Using .skip

Skip comes from Mocha Framework in Cypress. You can add the .skipto a test usingit.skip() or an integral suite of tests usingdescribe.skip ()syntax to skip the performance of the tests.

If you add .skip to it block, the test will not run, and it will be marked as & # 8220;skipped& # 8221; in the test moon-curser. However, skipped tests will still appear in the test contrabandist interface, but they will be grayed out.

This can be useful if you want to temporarily exclude a trial from running or if you have tests that are not yet ready to run but you would want to keep in your test suite.

Using .skipallows you to focus on specific tests or temporarily skip exam that are failing without having to delete or alter the test codification. The disabled test will not be executed during the test run and will not affect the results.

Scenario:

  • There are 2 tryout cases to access the URL “https: //bstackdemo.com” and click on Add to Cart.
  • Skip the first suit from running.

Implementation:

Below is a screenshot from the tryout causa where the first tryout is skipped employ.skip().

describe (“ Disable Cypress Test ”, () = & gt; {it.skip (“ Tc1 - Disable test using .skip () ”, function () {cy.visit (“ https: //bstackdemo.com/ ”); cy.get (“ div.shelf-item_buy-btn ”) .first () .click ();}); it (“ Tc2 - Disable test employ .skip () ”, function () {cy.visit (“ https: //bstackdemo.com/ ”); cy.get (“ div.shelf-item_buy-btn ”) .eq (1) .click ();});});

Code Walkthrough:

To hop-skip the exam example from bunk, useit.skip(). It will not run this case while the executing of the abovespecFile. It will be prove in the command log but will be grayed out.

Execution:

In the below screenshot, it is clearly visible only the 2nd test case got pass, and the first one got skipped. Test cases which are cut will be marked in grey colour and test cases which are passed appear in green colour.

It & # 8217; s significant to observe that .skipshould be expend judiciously, as it makes it easier for test failures to go unnoticed. It is recommend to re-enable tests as soon as possible and to keep your test entourage as comprehensive as possible.

2. Using .only

.only()can be added to test lawsuit (it block) using theit.only()or to the test suite (describe) usingdescribe.only ()to run simply the select tests. Only the tests or suites that get the solitary iris will be run, and all former exam or suite will be cut.

This function is utile for temporarily focusing on a specific test or set of tests without having to comment on the others.

To use .only(), simply add it before a tryout or test suite that you want to run exclusively.

Scenario:

  • There ’ s a test retinue with 3 test cases which opens URL- “https: //bstackdemo.com/
  • Run merely the inaugural and tertiary test cases.

Implementation:

Below is a screenshot from the test entourage where the 2nd test case would be cut, and the first and third would be run.

describe (‘ My test retinue ’, () = & gt; {it.only (‘ TC1 - test case ’, () = & gt; {cy.visit (“ https: //bstackdemo.com/ ”) cy.log (“ === test event 1 ==== ”)}) it (‘ TC2 - Skipped test example ’, () = & gt; {cy.visit (“ https: //bstackdemo.com/ ”) cy.log (“ === test case 2 ==== ”)}) it.only (‘ TC3 - test case ’, () = & gt; {cy.visit (“ https: //bstackdemo.com/ ”) cy.log (“ === test case 3 ==== ”)})})

Code Walkthrough:

In order to run the specific examination case, useit.only ().For the first and third test cases,it.only()is used, which would run only the 2 test cases.

Execution:

In the below screenshot, it is shown that only Test Case 1 and Test Case 3 are fulfill.

When we use.only, the remaining tryout cases are not even shown in the dictation log, as shown above. Only the focused exam cases are visible while executing.

3. Use Config File

You can also skip tests at the spherical level by making the changes in the config file:

  • cypress.config.js(Cypress version 10 and above)
  • cypress.json(Cypress edition below 10)

You can specify which tests you want to run or skip. You can use the name of your tests or use patterns to pluck which tests should run.

Read More:

Scenario:

For Example, There are 3specFilesand run only 1specFile (in former words, snub the other 2specFiles). So, in this suit, you can handle it globally from the config file.

Below is the screenshot of 3specFilesfrom e2e in Cypress:

For Cypress edition 10 and above.

To disable a test globally in Cypress version 10 and above, you can use theexcludeSpecPatternalternative in your config file & # 8211;cypress.config.jsfile. Just pass the examination case name which you require to exclude while action.

Below is an example of how to exclude a test incypress.config.js:

excludeSpecPattern: [“ cypress/e2e/ * * /homePage.cy.js ”, “ cypress/e2e/ * * /productPage.cy.js ”],

Code Walkthrough:

In the Cypress/e2e directory, there are three testspecFiles: homePage.cy.js, loginPage.cy.js, and productPage.cy.js. As seen in the screenshot above, two of thesespecFiles (homePage.cy.js and productPage.cy.js) feature be omit from execution via the config file & # 8217; sexcludeSpecPattern setting.

Therefore, if you were to run the Cypress tests, only onespecFilewould be usable for execution, as the other two have been excluded.

Execution:

If you run “npx cypress open”, you will see only 1 specFile seem in CypressspecRunner screen (loginPage.cy.js)

Similarly, if you be to run the exam in headless mode employ the command & # 8220;npx cypress run, & # 8221; only one test event would be executed, as the early two experience been excluded.

Although, there are 3 test cases due to config changes incypress.config.js. It shut the former 2 test specFiles and executed only one.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

For Cypress version below 10:

In Cypress edition prior to 10, you can globally disable a test by lend its name to theignoreTestFilesoption in yourcypress.jsonfile. This will exclude the specific trial case from execution.

Below is an example of how to omit a test incypress.json

“ ignoreTestFiles ”: [“ * * /homePage.cy.js ” “ * * /productPage.cy.js ”],

Code Walkthrough:

In the Cypress/integration directory, there are three trialspecFiles: homePage.cy.js, loginPage.cy.js, andproductPage.cy.js. As realise in the screenshot above, two of thesespecFiles (homePage.cy.js and productPage.cy.js) have been excluded from execution via the config file & # 8217; signoreTestFiles setting.

Therefore, if you be to run the Cypress tests, only onespecFilewould be available for performance, as the other two have been shut.

Execution:

If you open Cypress in lead mode, you will observe only 1 test case in Cypress specification Runner

Similarly, it would display 1 test case even while running it in headless mode using

npx cypress run

By making changes in the config file, you can change it at global level.

How to cut tests conditionally in Cypress?

Sometimes, it may be necessary to skip a test based on sure conditions. For instance, you may desire to skip a exam if it is running on a specific environment or if a certain OS is present. One of the way to run Cypress tests conditionally found on various conditions is to use thecypress-select-testsplugin. This plugin allows you to filter and select tests ground on different weather, such as the operating system, the browser, or URL.

Below are the measure to postdate for using thecypress-select-tests plugin:

1). Install plugincypress-select-testsusing the command:

npm install -D @ cypress/skip-test

2). Add the module (require (& # 8216; @ cypress/skip-test/support & # 8217;) to indorse file in order to use it as custom Cypress commands ascy.skip and cy.onlyOn

For Cypress version 10 and above, add itsupport & gt; e2e.js

For Cypress version below 10, add insupport & gt; index.js

Conditional omission test & # 8211; when module is added in support file

Given you have already added the module to the support file. You can use below ways to conditional run test lawsuit in Cypress:

1. cy.onlyOn

It runs the test only on specified weather provided insidecy.onlyOn (). You can skip the other test cases and run merely specific condition-based tests.

Let ’ s understand with the below example:

Scenario:

  • You have 2 test event where you are open the URL ”https: //bstackdemo.com/” and clicking on “ Add to Cart ” in both the test cases.
  • You want to run the first examination event alone on Chrome and the 2nd one on Firefox.

Code:

In order to run the test case conditionally on specific browser, you can usecy.onlyOn (‘ browserName ’)exactly like testify below:

describe (“ Conditionally disable test in cypress using plugin ”, () = & gt; {it (“ Only on Chrome, Open URL and add product to cart ’, () = & gt; {cy.onlyOn (‘ chrome ’) cy.visit (“ https: //bstackdemo.com/ ”) cy.get (‘ .shelf-item_buy-btn ’) .first () .click ();}); it (‘ Only on Firefox, Open URL and add product to hale ”, () = & gt; {cy.onlyOn (‘ firefox ’) cy.visit (“ https: //bstackdemo.com/ ”) cy.get (‘ .shelf-item_buy-btn ’) .first () .click ();});})

Execution:

On executing the above test cause on Chrome browser, only 1st test lawsuit would be executed because we have passedcy.onlyOn (‘ chrome ’) for that.

If the above test instance is run in the Chrome browser, the second test will be skipped. However, if the same test case is run in the Firefox browser, the second tryout will be executed, and the first test will be hop-skip, as shown below:

2. cy.skipOn

It skips the test only on specified conditions provided insidecy.skipOn (). The other test case would be executed successfully and only those event would be skipped which have specific weather.

Let ’ s understand with the below example:

Scenario:

  • You experience 2 test cases where you am opening the URL ”https: //bstackdemo.com/” and clicking on “ Add to Cart ” in both the test example.
  • You want to skip the initiative test suit if it is run on Windows OS and skip the second one if it is on Mac OS.

Code:

In order to run the test case conditionally on specific OS, you can usecy.skipOn (‘ OSName ’)but like shown below:

describe (‘ conditionally disable examination in Cypress using plugin ”, () = & gt; {it (“ Skip on Window, Open URL and add merchandise to hale ”, () = & gt; {cy.skipOn (‘ windows ’) cy.visit (“ https: //bstackdemo.com/ ”) cy.get (‘ .shelf-item_buy-btn ’) .first () .click ();}); it (“ skip on MAC, Open URL and add product to cart ”, () = & gt; {cy.skipOn (‘ mac ’) cy.visit (“ https: //bstackdemo.com/ ”) cy.get (‘ .shelf-item_buy-btn ’) .first () .click ();});})

Execution:

On executing the above test event onmac and Linux OS, only the 1st test case would be executed because you have legislatecy.skipOn (‘ windows ’)in a test which means if the OS is former than windows, the test cause would be executed.

Running a test event on a mac machine. So, the inaugural test cause got executed and the second one got hop-skip.

Conditional skip test & # 8211; when module is not added in support file

You can also run the conditional examination without importing it in the support file. In that case, you can directly spell it in tryout case file and use.onlyOn() and .skipOn()

import {onlyOn, skipOn} from ' @ cypress/skip-test '

Let ’ s understand with the below model:

Scenario:

  • You have 2 test suit where you are open the URL ”https: //bstackdemo.com/” and tick on “ Add to Cart ” in both the test instance.
  • You need to skip first test case if it is running on Windows OS and run second one, only if it is running on firefox browser

Code:

significance {onlyOn, skipOn} from ‘ @ cypress/skip-test ’ describe (“ conditionally disable test in cypress using plugin ”, () = & gt; {it (“ Skip on Windows - Open website and click on product ”, () = & gt; {skipOn (‘ windows ’) cy.visit (“ https: //bstackdemo.com/ ”) cy.get (‘ .shelf-item_buy-btn ’) .first () .click ();}); it (“ Only on Firefox - Unfastened website and clink on product ”, () = & gt; {onlyOn (‘ firefox ’) cy.visit (“ https: //bstackdemo.com/ ”) cy.get (‘ .shelf-item_buy-btn ’) .first () .click ();});});

Code Walkthrough:

In this suit, usingskipOn() and onlyOn().

In the first test lawsuit, have surpass

skipOn (‘ window ’)

This means the maiden test case would only run if the OS is other than windows (i.e mac/ Linux).

In the second scenario, the exam example will exclusively fulfil if the specified browser is Firefox, as indicated by passing

onlyOn ('firefox ')

If a different browser is utilize, the trial case will be skipped.

Execution:


As shown in the above screenshot, both test cases were executed successfully because the operating system used was mac, satisfying the first condition. Additionally, the second precondition was besides met as the test instance was executed utilise the Firefox browser. Therefore, the exam case was not skipped.

Run/Skip trial based on multiple weather

If you wish to execute or skip a test based on multiple weather, you can concatenation the conditions together. This approach can be beneficial when you want to test on specific browsers and operating systems simultaneously.

Let ’ s try to understand with below representative:

Scenario:

Continuing with the same instance:

  • I receive a test example where I am opening the URL ”https: //bstackdemo.com/” and bring a product to Cart.
  • I need to skip the examination case if the browser is Firefox
  • I require to run it alone when OS is MAC and browser is Chrome

Implementation:

significance {onlyOn, skipOn} from ‘ @ cypress/skip-test ’ describe (“ Conditionally disable exam in cypress utilize plugin ”, () = & gt; {it (“ omission on Firefox, Run merely on Mac and Browser Chrome ”, () = & gt; {cy.skinOn (‘ firefox ’) cy.onlyOn (“ mac ”) .onlyOn (‘ chrome ’) cy.visit (“ https: //bstackdemo.com/ ”) cy.get (‘ .shelf-item_but-btn ’) .first () .click ();});

Execution:

If we run the above test cause on Firefox browser, it would get skipped

If I run the same trial lawsuit in Chrome browser and MAC OS, it would be executed successfully

Likewise, you can add multiple weather and disable/run test cause based on those conditions.

How to exclude a test using Cypress CLI?

In Cypress, you can run a specific test by using the& # 8211; specificationoption in the Cypress CLI. This option enables you to run only the tests that are specified, excluding any other tests that are not mentioned. Below is the syntax:

npx cypress run -- spec “ & lt; file_path & gt; ”

Running single specFile cases using Cypress CLI:

Let ’ s understand with an illustration: If you have five spec files namedsanity.cy.js, regression.cy.js, api.cy.js, ui.cy.js, and performance.cy.js. If you require to run merely thesanity.cy.jsfile and skip all the others, you can use the following command.

For Cypress edition below 10, it can be employ as below:

npx cypress run –spec “ cypress/integration/sanity.cy.js ”

For Cypress version above 10, you can use the below syntax:

npx cypress run –spec “ cypress/e2e/sanity.cy.js ”

Code Walkthrough:

The above command will fulfil entirely the specFiles that are explicitly specified in the sanity.cy.js and ignore all former specFiles in the project.Similarly, you can run other spec files besides by specifying their file paths with the & # 8211; spec option.

Running multiple specFiles use Cypress CLI

To run multiple specFiles simultaneously using Cypress CLI, you can use the following approach: Rename all the specFiles with the same file propagation and surpass a form while executing them through Cypress CLI.

Scenario:

For example, if we have 5 specFiles with the file extensionregression.jsand 4 specFiles withsanity.jsfile propagation, you can use the& # 8211; specoption to fix which specifies you need to run using * .js file to run.

Execution:

To 4 specFiles with sanity.js file extension, use the below command:

For Cypress version below 10:

npx cypress run –spec “ cypress/integration/ * .sanity.js ”

For Cypress version 10 and above:

npx cypress run –spec “ cypress/e2e/ * .sanity.js ”

This way, you can run multiple specFiles using Cypress CLI while cut the otherspecFiles.

Conclusion

In this blog, we have explored respective approaches to exclude tests during Cypress test execution.In order to create the most of Cypress and keep your test suites organized, it & # 8217; s important to know how to exclude tests when necessary.

Tags
41,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free