Q6 of 48 · Cypress
How do you run a single Cypress test from the command line?
Short answer
Short answer: Use `npx cypress run --spec 'cypress/e2e/path/to/file.cy.ts'`. To run a specific test inside a spec, use `it.only(...)` in the code, or `--grep` with `@cypress/grep`. Browser and headed mode are flags: `--browser chrome --headed`.
Detail
Cypress's CLI distinguishes file selection from test selection.
Selecting one spec file uses --spec with a path or glob:
npx cypress run --spec "cypress/e2e/auth/login.cy.ts"
npx cypress run --spec "cypress/e2e/auth/**"
Selecting one test inside a spec is harder out of the box. The two common ways:
.only— annotate the test withit.only('...', () => { ... }). Cypress runs only the annotated test in that spec. Don't commit.onlyto main; many teams add an ESLint rule to block it.@cypress/grep— a plugin that adds tag-based filtering. After installing,--env grep="login"runs tests whose names match. Combine with tags like{tags: '@smoke'}for tagged subsets.
Other useful flags: --browser chrome (or firefox, edge), --headed to see the browser, --config-file cypress.staging.config.ts for environment-specific configs. --record sends results to Cypress Cloud if configured.
For local debugging, npx cypress open launches the interactive runner — pick the spec, watch it run, and time-travel through commands.
// EXAMPLE
# Run all specs
npx cypress run
# Run one spec file
npx cypress run --spec "cypress/e2e/auth/login.cy.ts"
# Run all specs under a folder
npx cypress run --spec "cypress/e2e/checkout/**"
# Headed in Chrome (useful in CI debug)
npx cypress run --browser chrome --headed --spec "cypress/e2e/auth/login.cy.ts"
# With @cypress/grep — only tests tagged @smoke
npx cypress run --env grepTags=@smoke
# Open the interactive runner for local debugging
npx cypress open