How to run specific test in Cypress
Related Product On This Page Why do specific tests in Cypress?June 14, 2026 · 12 min read · Tool Comparison
Running specific tests in Cypress is important for effective debugging and quick feedback during maturation. Cypress let you to isolate and run only the or test files you ’ re focused on, Instead of executing the integral test suite, saving time and resource. In this guide, learn how to run specific exam in Cypress along with the best practices. Running specific tests in Cypress is significant for speeding up evolution workflows, isolating issue, and increase test efficiency. When working on turgid test suites, re-running the entire suite for every small code change can be time-consuming and unnecessary. By targeting case-by-case specs, developer can quickly formalise functionality, debug failure, and iterate on test code without waiting for unrelated examination to complete. This helps to improve productivity and provides faster feedback during ontogenesis and CI runs. Key Benefits: Read More: To run a specific trial file in Cypress, use the& # 8211; spec flagwith thenpx cypress run command. This narrate Cypress to execute only the specified test file, rather than running the entire test suite. Here ’ s the canonic syntax: Example: This command runs only the login.cy.js test file. A user can also provide a relative or absolute path to the spec file. For targeting multiple file, use global patterns like: Read More: Let & # 8217; s search how to use Cypress to test a web coating now that we are relatable with what it is and its advantages. Before beginning, make sure you clone the GitHub seed. Adding Cypress to our project is step one. The rattling initiative motility you must do is access the projection leaflet you just cloned in the pole and run the following command to install all of its dependencies: After the command has finished running, we & # 8217; ll need to add Cypress to it by using the command that goes like this: Go to the labor & # 8217; s rootage and chance thepackage.jsonfile. Inside the & # 8220; playscript, & # 8221; add the chase: The final measure is to launch Cypress directly from the npm command: A local instance of the website should be opened by your browser, along with a Cypress window, which you may now close. The local server might be cease as well. If a server is already running, Cypress just has to be depart using npx Cypress outdoors. However, you may use npm run test to get the default server. Learn how you can Run Cypress Tests with this Get the BrowserStack CLI instal. A command-line program called the BrowserStack & # 8211; Cypress CLI is used to facilitate communication between Cypress and BrowserStack. Install the BrowserStack & # 8211; Cypress CLI as follow using the npm bidding: Check out the Official Documentation to memorize how to Let & # 8217; s write our inaugural test now that Cypress has been introduced to our project. Navigate to/cypress/integration and add a mycart_spec.jsfile to it. We & # 8217; ll insert the following code into this file: With this, a 1366 & # 215; 900 viewport will be employ to access our local page. Then, by catch themycart.readycase, we establish a hope to wait for themycartbook to cease loading. Under the globularcyobject you can see above, all of Cypress & # 8217; s functionalities are accessible. No async/await is required. With the exception of the mycart case, which must be awaited since we need to capture the run document for this, tests run one measure at a time, expect for the completion of the preceding one. Let & # 8217; s run our initial test now that it has been make. The trial we construct ought to be seeable in the Cypress window. Simply click it to get it running. This will launch a tonic window of the browser and launching the test mechanically. We & # 8217; ll test a single-page application (SPA) in this presentment that make use of the React frontend framework. Users may add, edit, and remove tasks using the coating & # 8217; s simple task manager. Installing sure dependencies is the first pace. The following are necessary: With npm, we can set up these dependencies: Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. We can now useCreate React App:to create a new React app. The undermentioned additional Cypress dependencies must be installed next: We can now publish our tests after install our dependencies. In thecypress/integrationbrochure, create a new file namedtasks.spec.jsand occupy it with the following content: Before each test in the specification, the beforeEach function executes. In this instance, we are navigating to the main application URL, which ishttp: //localhost:3000. The ‘ it ’ function holds the location of our actual test code. A callback function containing our test code is the second arguing, and the first argument is a description of the examination scenario. This exam verifies that when tasks are subject via the form, our task management application appropriately lend them to the leaning. To do this, we first enter some information into the form fields, and so we submit it. There ’ s now one job in the list employ anticipate. Using npm, you may execute tests from a terminal window. Reliable results need pass all tests on existent browsers. With BrowserStack, you can start testing the 30+ almost recent browser versions on Windows and Mac. To reach quicker results without compromising caliber, use instant, hassle-free parallelization. By using BrowserStack to test the software under, bugs can be ground before users do. Running specific test file using Cypress CLI is an efficient way to target only the relevant exam, specially when debugging or working on a focussed feature. Cypress furnish the& # 8211; spec flagto control which test files are execute. Step 1: Open your depot and check for the task radical directory. Step 2: Use the & # 8211; spec masthead with npx cypress run to orient to the exact test file for running: Step 3: Use glob patterns for running multiple files that tally a certain structure: Step 4: Target multiple specific files by severalize them with comma: Step 5: Combine with other options like delineate browser or head manner: Read More: You can start discourse with our discord community The helps to run, debug, and inspect your tests interactively in a existent browser. It ’ s specially useful during development for unrecorded reloading, visual debugging, and audit test output in existent time. Here are the steps to be postdate for running tests utilise the Cypress Test Runner: Step 1: In your terminal, run: This launches the Cypress Test Runner UI. Step 2: In Cypress 10+, select a testing case from: Here, you can select E2E Testing and continue. Step 3: Select the browser to run the tests (e.g. Chrome, Firefox, Edge). Step 4: Pick the test file from the lean shown in the UI. Click on any .cy.js or .cy.ts file to run it. Step 5: The examination will open in an literal browser window where you can: Step 6: Any modification made to the test code will mechanically recharge the test in the smuggler. In Cypress, this.skip () is an efficient way to skip exam within abefore, beforeEach, or any test hook. It allows you to dynamically decide whether a test or a group of tests should run based on runtime conditions, such as environment variables, lineament flags, or API answer. This is useful when certain exam are only relevant in specific environs or when a test suit should be temporarily bypassed without commenting it out. Example: In this use case, the test runs only in the staging environment and is skipped in all others using a runtime condition. Read More: To increase the productiveness of Cypress screen workflows, Visual Studio Code (VS Code) ply several extensions that allow running specific tryout or trial file forthwith from the editor, without switching to the depot. One of the virtually popular and effective extension for this purpose is Cypress Snippets in combination with Cypress Test Runner or Cypress Helper. These extensions furnish features like inline trial running, code lense activeness above trial blocks, and simple navigation to test files. Democratic VS Code Extensions for Cypress Here are some of the democratic VS Code extensions expend for Cypress: 1. Cypress Test Runner for Visual Studio Code Example: 2. Cypress Snippets They provide useful auto-completions and easy-to-modify test templates. While they don ’ t run exam directly, they speeds up test penning. 3. Code Runner If configured correctly, with a codification moon-curser, a exploiter can map custom Cypress run hand to VS Code project. Read More: Cypress is a fantastic end-to-end testing creature that too has top-notchBetter Practices documentation. Here is a second I & # 8217; ve written that proceed into more point on Best practices. In essence: Pro-Tip:Integrate your Test Suite with. On a motley of literal mobile and pad devices, such as the iPhone, iPad, Samsung Galaxy, Google Pixel, Nexus, and others, test your aboriginal and hybrid apps. For your disunited online and mobile audience, create unbelievable application. BrowserStack is a cloud-based testing program that lets you run Cypress test efficiently across multiple device-OS-browser combinations. Here are a few reasons why you should choose BrowserStack: Without the hassles; Cypress can be set up in a matter of minutes. Cypress & # 8217; s declamatory user community is e'er eager to offer its expertise and perceptiveness. The syntax used in Cypress tests is pretty easygoing and simple to translate and write. You will be capable to write effective UI tests with a little recitation. For those who wish to develop pertinent end-to-end tests fast and efficiently, Cypress is a outstanding option. It too makes problem-solving very simple. Understanding Cypress Use Cases Tool Comparisons 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.Related Product
How to run specific test in Cypress
Why do specific tests in Cypress?
Command to Run Specific Test File in Cypress
npx cypress run -- spec `` cypress/e2e/ & lt; file-name & gt; .cy.js ''
npx cypress run -- spec `` cypress/e2e/login.cy.js ''
npx cypress run -- spec `` cypress/e2e/auth/ *.cy.js"
Beginning with Cypress
npm install
npm install cypress -- save-dev
`` cypress: exposed '': `` cypress open '', '' cypress: run '': `` cypress run ''
npm run test
cypress run -- spec 'path/to/files/ * .spec.js '
cypress run -- spec path/to/file.spec.js
Launch your first BrowserStack Cypress test using Command Line
# Install the BrowserStack Cypress CLI npm install -g browserstack-cypress-cli
Creating a test in Cypress
describe (`` Test Ecommerce features '', () = & gt; {it (`` Test Ecommerce features '', () = & gt; {cy.viewport (1366, 900); cy.visit (`` localhost:3000 ''); waitForSnipcartReady (); cy.get (`` # la-gioconda '') .click (); cy.get (`` .total '') .should (`` contain '', `` 79.99 '', {timeout: 30000}); expect (cy.get (`` .mycart-modal '') .should (`` exist ''));});npm run test
Testing a Single-Page Application
npm install -- relieve react react-dom create-react-app cypress
create-react-app my-app
cd my-app npm install -- save-dev cypress
describe ('Tasks ', use () {beforeEach (use () {cy.visit ('http: //localhost:3000 ');}); it ('should add a task ', mapping () {// Enter task details into form and submit cy.get ('input [name= '' taskName ''] ') .type ('My Task '); cy.get ('textarea [name= '' taskDescription ''] ') .type ('My Description '); cy.get ('form ') .submit (); expect (cy.get ('.tasks li ') .its ('length ')) .to.equal (1);});});npm run e2e npm run e2e: open
How to Specify Specific Test Files employ Cypress CLI?
npx cypress run -- spec `` cypress/e2e/login.cy.js ''
npx cypress run -- spec `` cypress/e2e/auth/ * .cy.js ''
npx cypress run -- spec `` cypress/e2e/login.cy.js, cypress/e2e/register.cy.js ''
npx cypress run -- spec `` cypress/e2e/login.cy.js '' -- lead -- browser chrome
Like what you are reading?
How to execute Cypress Tests with Cypress Test Runner?
Steps to Run Tests Using the Cypress Test Runner
npx cypress open
this.skip () for Running Specific Tests in Cypress
describe ('Admin Panel Tests ', function () {before (role () {if (Cypress.env ('userRole ')! == 'admin ') {this.skip ();}}); it ('should expose the admin splashboard ', () = & gt; {cy.visit ('/admin '); cy.contains ('Welcome, Admin ') .should ('be.visible ');});});Use Case: Conditionally Skip a Single Test
it ('should solely run in staging ', function () {if (Cypress.env ('ENV ')! == 'staging ') {this.skip ();} cy.visit ('/beta-feature '); cy.contains ('Staging Feature ') .should ('exist ');});Visual Studio Code Extension for Running Specific Tests in Cypress
describe ('Login Page ', () = & gt; {it ('should log in successfully ', () = & gt; {cy.visit ('/login '); cy.get ('input [name= '' username ''] ') .type ('user '); cy.get ('input [name= '' parole ''] ') .type ('pass '); cy.get ('.login-button ') .click (); cy.url () .should ('include ', '/dashboard ');});});Best Practices to run Specific Tests in Cypress
Why Choose BrowserStack for Cypress Testing
Conclusion
Utilitarian Resources for Cypress
Related Guides
Automate This With SUSA
Test Your App Autonomously