Cypress CLI lets you run your tests from the command line. This helps you test your app automatically without opening the browser UI.
0
0
Cypress CLI execution
Introduction
You want to run tests on a server or in a continuous integration system.
You want to run all tests quickly without manual clicks.
You want to see test results in the terminal or save reports.
You want to run tests in different browsers or headless mode.
You want to automate testing as part of your development workflow.
Syntax
Cypress
npx cypress run [options]
npx cypress run runs all tests in headless mode by default.
You can add options like --browser chrome or --spec 'cypress/e2e/test.cy.js' to customize the run.
Examples
Runs all tests in the default browser (usually Electron) in headless mode.
Cypress
npx cypress run
Runs all tests in Google Chrome browser in headless mode.
Cypress
npx cypress run --browser chrome
Runs only the test file named
login.cy.js.Cypress
npx cypress run --spec 'cypress/e2e/login.cy.js'Runs tests in Firefox browser with the browser window visible (not headless).
Cypress
npx cypress run --headed --browser firefox
Sample Program
This command runs the sample_test.cy.js test file using Chrome browser in headless mode. You will see test results in the terminal.
Cypress
npx cypress run --spec 'cypress/e2e/sample_test.cy.js' --browser chromeOutputSuccess
Important Notes
Use npx to run Cypress without installing it globally.
Headless mode means tests run without opening the browser window.
You can save test videos and screenshots automatically with Cypress CLI.
Summary
Cypress CLI runs tests from the command line without the UI.
You can choose browser, test files, and headless or headed mode with options.
Test results show in the terminal, useful for automation and continuous integration.