
Running Cypress tests for a large application can be overwhelming. You often spend a lot of time waiting for the entire suite to finish, even when your changes affect only a small part of the app. This can make debugging frustrating and slow down development, especially when tests fail in areas unrelated to your work.
However, you do not have to run every test every time. Cypress specific tests let you focus only on the files or scenarios that matter. You can filter by keywords, skip irrelevant tests, and run only the parts you are actively working on, which saves time and makes your workflow more efficient.
In this article, you will learn how to cypress run specific tests and manage targeted test execution step by step.
Running the full test suite every time can quickly become a bottleneck, especially for large applications. You may make a small change, but then wait minutes for unrelated tests to complete. Failures in unrelated tests can distract you, and repeated long waits make debugging frustrating. Targeting specific tests solves these issues and keeps your workflow efficient.
Here are practical reasons to run specific tests in Cypress:
Before you can run specific tests, you need a working Cypress setup. Installing Cypress is straightforward, but a proper configuration ensures smooth test execution and makes targeting individual tests easier.
Here’s how to get started:
npm install cypress --save-dev in your project folder. This ensures Cypress is added as a development dependency and stays consistent across your team.npx cypress open to launch the Test Runner. Cypress will automatically create a cypress/ folder with example tests and the default configuration.With Cypress installed and configured, you can now write tests that are easy to target and manage. Proper setup ensures you spend less time troubleshooting setup issues and more time running the tests that actually matter.
Before you can run specific tests, you need a test to target. Creating a well-structured test ensures it can be easily isolated, skipped, or filtered when running only a subset of your suite. Here’s how to get started:
Step 1: Create a new test file
Inside your cypress/e2e/ folder, create a new file for your test. For example, login.spec.js. Structuring tests by feature or module helps later when you want to run just a single file.
Step 2: Import Cypress and describe your test suite
Start by using the describe block to define your test suite. For example:
describe('Login Feature', () => {
// tests will go here
})
The describe block groups related tests, making it easier to filter or run them selectively.
Step 3: Write your first test case
Use the it block to write individual test cases. For example:
it('should allow a user to login with valid credentials', () => {
cy.visit('/login')
cy.get('input[name=username]').type('testuser')
cy.get('input[name=password]').type('password123')
cy.get('button[type=submit]').click()
cy.url().should('include', '/dashboard')
})
Each it block represents a single test scenario, which you can target later using keywords or file names.
Step 4: Save and run
Once your test is written, save the file. You can now run it using the Test Runner or CLI to verify it works as expected. Proper naming of files and test cases ensures you can run specific tests efficiently.
Once you have multiple test files, running the entire suite every time becomes inefficient. If you are working only on the login feature, there is no reason to execute tests for payments, dashboards, or reports. Cypress allows you to run a single test file directly from the command line or through the Test Runner.
Here is how to do it properly.
Step 1: Identify the test file path
Go to your cypress/e2e/ folder and note the exact file name. For example:
cypress/e2e/login.spec.js
You need the correct relative path because Cypress uses it to determine which file to execute.
Step 2: Run the test using the CLI in headless mode
Use the following command:
npx cypress run --spec "cypress/e2e/login.spec.js"
The --spec flag tells Cypress to execute only the specified file instead of the entire suite. This is the most common and reliable way to run a specific test file, especially in CI pipelines.
Step 3: Run the file in interactive mode (optional)
If you prefer the visual Test Runner, use:
npx cypress open
Then manually click on login.spec.js in the UI. This runs only that file in interactive mode, which is useful for debugging.
Step 4: Use glob patterns for multiple specific files (advanced)
If you want to run more than one targeted file, you can use patterns:
npx cypress run --spec "cypress/e2e/auth/*.js"
This runs all test files inside the auth folder while skipping the rest of the suite.
Running a single test file gives you faster feedback, cleaner debugging, and better control over execution scope. It becomes especially powerful when combined with keyword filtering or conditional skipping, which we will cover next.
Running a single test locally is useful for quick feedback. However, local execution only reflects your machine’s browser and environment. If your users access the app from different browsers or operating systems, you need to validate your specific test there as well. That is where tools like BrowserStack become relevant.
Instead of running the entire suite on a cloud grid, you can run only the targeted test file you are working on. This keeps cloud execution focused and efficient.
Here’s how BrowserStack helps when running specific Cypress tests:
Single Page Applications behave differently from traditional multi-page apps. Routes change without full page reloads, content renders dynamically, and components update based on API responses. Because of this, running specific tests in SPAs requires careful targeting.
When working with SPAs, you typically want to run only the tests related to the route, feature, or component you modified.
Here’s what matters when targeting specific tests in SPAs:
The command line gives you precise control over which tests run. This is essential when you want to execute a specific file, folder, or pattern without opening the interactive runner.
The most important tool here is the --spec flag.
To run a single file:
npx cypress run --spec "cypress/e2e/login.spec.js"
To run multiple specific files:
npx cypress run --spec "cypress/e2e/login.spec.js,cypress/e2e/profile.spec.js"
To run an entire folder:
npx cypress run --spec "cypress/e2e/auth/*"
You can also use glob patterns for more flexible targeting:
npx cypress run --spec "cypress/e2e/**/*login*.js"
This allows pattern-based execution, which is extremely useful in large projects where tests are grouped by feature or naming convention.
Using CLI targeting is especially powerful in CI pipelines. Instead of triggering the full suite after every commit, you can configure your pipeline to run only the impacted test files based on file changes. This keeps feedback fast and reduces resource consumption.
Sometimes you do not just want to run a specific file. You want certain tests to run only under specific conditions. This is common when features are environment-based, behind flags, or dependent on external services.
Cypress allows you to control execution dynamically so you can skip tests based on environment variables, runtime values, or configuration settings.
One common approach is using environment variables.
For example, suppose a feature exists only in staging:
if (Cypress.env('ENV') !== 'staging') {
it.skip('should test staging-only feature', () => {
// test steps
})
}
You can pass environment variables through the CLI:
npx cypress run --env ENV=staging
This ensures that specific tests run only when the correct environment is active.
Another practical approach is conditional logic inside hooks:
before(function () {
if (!Cypress.env('featureFlag')) {
this.skip()
}
})
Using this.skip() inside a before hook skips all tests in that suite when the condition fails. This is useful when a feature flag controls whether functionality exists.
You can also combine conditional skipping with CI pipelines. For example, smoke tests can run on every commit, while heavier regression tests run only on scheduled builds. This keeps targeted execution aligned with development workflows.
However, conditional skipping should be used carefully. Overusing it can make test behavior unpredictable. Each test should clearly document why it is conditionally skipped, so other team members understand execution logic.
Conditional execution adds flexibility, but it works best when paired with structured test organization and clear naming conventions.
Running specific tests in Cypress is powerful, but without structure it can create confusion, hidden dependencies, and inconsistent CI behavior. Targeted execution should improve speed and clarity, not introduce unpredictability. The following best practices ensure that running specific tests remains reliable and scalable.
Running specific tests in Cypress gives you better control over your testing workflow. Instead of executing the entire suite every time, you can target individual files, filter by keywords, skip irrelevant scenarios, and isolate failures quickly. This improves debugging speed, reduces unnecessary execution time, and keeps development aligned with the features you are actively building.
However, running specific tests locally only validates behavior in your own environment. With BrowserStack, you can execute those same targeted Cypress tests across real browsers and operating systems without increasing execution overhead. This ensures that focused test runs remain efficient while still delivering broad cross-browser confidence and makes your targeted testing strategy both fast and reliable.
Get visual proof, steps to reproduce and technical logs with one click
Try Bird on your next bug - you’ll love it
“Game changer”
Julie, Head of QA
Try Bird later, from your desktop