How to Filter Tests using Cypress Tags
On This Page What are Cypress Tags?Setting up Cypress shredMarch 22, 2026 · 10 min read · Tool Comparison
is an fabric for web applications. One of the powerful features of Cypress is the ability to filter tests using tags. By assigning tags to tests, it can be easily run or specific tests are omit based on their tag values. This can help preserve time and endeavour when running tests and make the exam suite more unionised and maintainable. What are Cypress tatter and how to use them? Grouping & amp; Combining Tags Best Practices In this article, let us explore how to use Cypress tags to filter tests and demonstrate how cypress tag tests can be an effective way to grapple the test suite. Cypress shred are label that can be impute to individual tests to categorize and radical them. Tags are utile for engineer tests and making it easier to find and run specific tests. By assigning Cypress tags to tests, you can grouping similar tests, making it easy to manage and maintain our test suite. Read More: In Cypress, tags are added to tests using a comment in the code. For example, to add the tag & # 8220; fume & # 8221; to a test, you would write the following codification: Here are the steps for setting up the Cypress tags: 1. Install Cypress:If you haven & # 8217; t already, install Cypress on your estimator by following the instructions on the Cypress site. 2. Create a exam file: Create a test file for your web application in the Cypress/integration folder. 3. Add mark to tests: To add tags to your tests, use the commentary syntax described in the section. You can add tags to individual tests or to a group of test within a describe block. 4. Run examination using rag:To run tests using tags, use the & # 8211; tag option when scat Cypress. For example, to run all tests with the tag & # 8220; smoke & # 8221;, use the following command: Note:Cypress also ply the ability to exclude tests with specific tags by use the & # 8211; exclude option. 5. Filter tests based on multiple tags: You can also filter tests based on multiple tags by using the & # 8211; tag choice multiple times. For example, to run all tests with the tags & # 8220; smoke & # 8221; and & # 8220; regression & # 8221;, use the following command: Note:Some tags like & # 8211; grouping, & # 8211; tag, & # 8211; ci-build-id, & # 8211; parallel, or -auto-cancel-after-failures flags can be used solely while recording. Where as tags lile You passed the & # 8211; ci-build-id, & # 8211; group, & # 8211; tag, & # 8211; parallel, or & # 8211; auto-cancel-after-failures masthead without also passing the & # 8211; record flag. 1. Open the trial file:Open the test file in which you want to add tags. 2. Add tags to tests:To add tags to a test, add a comment to the test with the ‘ tag: ’ syntax, followed by the tag name. For exemplar: For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users. 3. Add multiple tags: You can add multiple rag to a test by apply the’ tag: ‘ syntax multiple times. For example: When you run your tests utilise the cypress run bidding, you can filter tests ground on their tags using the‘ & # 8211; tag ‘option. For example, to run all tests with the tag& # 8220; smoke, & # 8221;use the following bidding: Using tag to group test in Cypress is a great way to organize your test suite and get it easier to run specific tests. Here & # 8217; s how you can use tags to group trial: Group tests based on the same tag: To group trial ground on tags, you can use the cypress run command with the& # 8211; tagselection. For example, to run all tests with the tag& # 8220; smoke & # 8221;, use the following dictation: Group multiple tests with different tags:You can also group test free-base on multiple rag by utilise the& # 8211; tagchoice multiple times. For example, to run all tests with the rag& # 8220; smoke & # 8221;and & # 8220; fixation & # 8221;, use the following command: Group tests based on multiple conditions: In addition to grouping tests based on tags, you can likewise radical tests based on other conditions, such as the exam file gens or the test title. For exemplar, to run all tests in a specific file, use the following bidding: By habituate tags and former conditions to group test, you can easy run specific tests and exclude specific tests from execution. This can save you time and better the efficiency of your test suite. Combine filter:To combine filter, merely use multiple options in the Cypress run bid. For example, to run all tryout with the tag & # 8220; smoke & # 8221; in a specific file, use the next command: By combining tag filtering with other Cypress filter, you can run specific tryout that meet multiple weather. This can be very useful when you have a large test suite and motive to run only a specific subset of tryout. Here are some best practices for using Cypress tatter: By following these best practices, you can effectively use Cypress tags to organize and care your test cortege. This can help you to run specific exam, except specific tests from execution, and improve the overall efficiency of your test suite. The BrowserStack Cypress plugin allows you to run your Cypress trial on the BrowserStack cloud infrastructure, cater you with admission to a encompassing range of browsers and devices. If you are using the BrowserStack Cypress plugin, you can nonetheless use Cypress ticket to organize and categorize your tests. Here are the steps to install and run cypress tags with the BrowserStack plugin. 1. 2. Once you have installed and set up the Browserstack Cypress plugin, you can add tags to your Cypress tests as usual. Here & # 8217; s an example In this example, the examination has two tags: & # 8220; login & # 8221; and & # 8220; error. & # 8221; You can add as many tags as you need to each test. 3. To run your tests with specific tags, you can use the Cypress CLI as usual. Here & # 8217; s an example: In this example, let us run the login.spec.js test file and run tests only with the & # 8220; login & # 8221; tag. The Browserstack Cypress plugin will run the tests on the BrowserStack cloud infrastructure, provide you with access to a wide range of browser and device. Using Cypress tags with the Browserstack Cypress plugin is a simple and effective way to organize and categorize your tests, making it easier to contend large test suites and run specific tests as needed. By follow these stairs, you can easily add tags to your Cypress tests and run them on the BrowserStack cloud substructure, providing you with approach to a panoptic range of browser and devices for comprehensive testing. Here are some common issues and solutions when troubleshooting tag filtering errors in Cypress: In conclusion, Cypress rag are a powerful tool for organizing and managing your. By impart tags to tests, you can group tests, run specific tests based on ticket, and except specific tests from performance. When habituate correctly, Cypress tags can help to amend the efficiency and reliability of your test suite. Read More: However, it is important to follow best practices for using Cypress ticket, such as using meaningful tags, limiting the number of tags, debar duplicating rag, and keeping tags up-to-date. By following these good practices, you can effectively use Cypress tatter to organize and manage your test suite. If you encounter any issues when filtering tests by tag in Cypress, there are troubleshooting tips available to facilitate you resolve most problems. By following these tips, you can ensure that your trial suite is decent organized and handle and that you are able to efficaciously trickle tests based on tag. Overall, Cypress tags are a valuable tool for any test suite, providing a convenient and flexile way to direct and handle tests. Whether you are just starting with Cypress or have been using it for a while, incorporating rag into your prove workflow can help to streamline and improve the overall efficiency of your testing process. Running Cypress tests on BrowserStack can aid you improve the calibre, reliability, and scalability of your testing efforts, which can ultimately take to a best user experience for your customers. 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.How to Filter Tests using Cypress Tags
Overview
What are Cypress Tags?
describe ('My test suite ', () = & gt; {it ('My test case ', () = & gt; {// tag: smoking // Test code here});});Setting up Cypress shred
cypress run –record -- tag smoke
cypress run –record -- tag smoking -- tag regression
Adding tags to Cypress tests
describe ('My test suite ', () = & gt; {it ('My tryout case ', () = & gt; {// tag: smoke // Test code here});});describe ('My tryout suite ', () = & gt; {it ('My test case ', () = & gt; {// tag: smoke // tag: regression // Test code here});});Filtering Cypress Tests by Tags
cypress run –record -- tag smoke
Using tags to group tests
cypress run –record -- tag smoke
cypress run –record -- tag smoking -- tag fixation
cypress run –record -- spec cypress/integration/my-test-file.spec.js
Combining tag filtering with former Cypress filters
cypress run –record -- tag fume -- spec cypress/integration/my-test-file.spec.js
Best practices for utilise Cypress tags
Use of Cypress tags with BrowserStack Cypress plugin
describe ('Login page ', () = & gt; {
it ('should display error message on invalid login ', () = & gt; {
// test logic
}, {shred: ['login ', 'error ']});
});cypress run -- spec cypress/integration/login.spec.js -- tag login
Troubleshooting tag filtering errors
Related Guides
Automate This With SUSA
Test Your App Autonomously