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
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. Why skip tryout in Cypress? How to cut examination? Conditional skips in Cypress Benefits of Cypress Disable Test In this blog, we will explore different shipway to disable tests and how to run examination conditionally 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: 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: 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: Implementation: Below is a screenshot from the tryout causa where the first tryout is skipped employ.skip(). 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. .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: 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. 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. You can also skip tests at the spherical level by making the changes in the config file: 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: 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 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 By making changes in the config file, you can change it at global level. 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: 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 Given you have already added the module to the support file. You can use below ways to conditional run test lawsuit in Cypress: 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: Code: In order to run the test case conditionally on specific browser, you can usecy.onlyOn (‘ browserName ’)exactly like testify below: 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: 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: Code: In order to run the test case conditionally on specific OS, you can usecy.skipOn (‘ OSName ’)but like shown below: 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. 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() Let ’ s understand with the below model: Scenario: Code: Code Walkthrough: In this suit, usingskipOn() and onlyOn(). In the first test lawsuit, have surpass 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 If a different browser is utilize, the trial case will be skipped. Execution: 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: Implementation: 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. 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: 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: For Cypress version above 10, you can use the below syntax: 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. 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: For Cypress version 10 and above: 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. On This Page # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Cypress Disable Test: How to use Skip and Only in Cypress
Overview
When to disable tests in Cypress?
Different ways to disable a test in Cypress
1. Using .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 ();});});2. Using .only
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 ==== ”)})})3. Use Config File
excludeSpecPattern: [“ cypress/e2e/ * * /homePage.cy.js ”, “ cypress/e2e/ * * /productPage.cy.js ”],
“ ignoreTestFiles ”: [“ * * /homePage.cy.js ” “ * * /productPage.cy.js ”],
npx cypress run
How to cut tests conditionally in Cypress?
npm install -D @ cypress/skip-test
Conditional omission test & # 8211; when module is added in support file
1. cy.onlyOn
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 ();});})2. cy.skipOn
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 ();});})Conditional skip test & # 8211; when module is not added in support file
import {onlyOn, skipOn} from ' @ cypress/skip-test '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 ();});});skipOn (‘ window ’)
onlyOn ('firefox ')
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
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 ();});How to exclude a test using Cypress CLI?
npx cypress run -- spec “ & lt; file_path & gt; ”
npx cypress run –spec “ cypress/integration/sanity.cy.js ”
npx cypress run –spec “ cypress/e2e/sanity.cy.js ”
Running multiple specFiles use Cypress CLI
npx cypress run –spec “ cypress/integration/ * .sanity.js ”
npx cypress run –spec “ cypress/e2e/ * .sanity.js ”
Related Guides
Automate This With SUSA
Test Your App Autonomously