Headless mode runs tests without opening a browser window. It helps run tests faster and in the background.
Headless mode in Cypress
npx cypress run --headless
This command runs all tests in headless mode using the default browser.
You can specify a browser with --browser option, for example: npx cypress run --headless --browser chrome.
npx cypress run --headless
npx cypress run --headless --browser firefox
npx cypress run --spec "cypress/e2e/login.cy.js" --headlessThis test visits a page and checks if the title contains 'Kitchen Sink'. Run it with npx cypress run --headless to see the result without opening a browser window.
describe('Simple test', () => { it('checks page title', () => { cy.visit('https://example.cypress.io') cy.title().should('include', 'Kitchen Sink') }) })
Headless mode is great for automation but you cannot see the test running visually.
Use headless mode in CI pipelines to save resources and speed up tests.
If you want to debug, run tests in headed mode with npx cypress open.
Headless mode runs tests without showing the browser window.
It is faster and useful for automated test runs and CI pipelines.
Use npx cypress run --headless to run tests this way.
Practice
headless mode?Solution
Step 1: Understand headless mode purpose
Headless mode runs tests without opening the browser window, making execution faster.Step 2: Compare options with headless mode features
Options B and C describe interactive or visible tests, which are not headless. Tests only run on mobile devices is unrelated.Final Answer:
Tests run faster without opening the browser window -> Option AQuick Check:
Headless mode = faster tests without UI [OK]
- Thinking headless mode shows browser UI
- Confusing headless with manual testing
- Assuming headless only runs on specific devices
Solution
Step 1: Recall Cypress commands for running tests
The correct command to run tests in headless mode isnpx cypress run --headless.Step 2: Eliminate incorrect commands
openlaunches the interactive GUI,startandtestare not valid Cypress commands.Final Answer:
npx cypress run --headless -> Option AQuick Check:
Run + --headless = correct command [OK]
- Using 'open' instead of 'run' for headless
- Typing invalid commands like 'start' or 'test'
- Omitting the --headless flag
npx cypress run --headless in your terminal?Solution
Step 1: Understand the effect of --headless flag
The --headless flag runs tests without opening the browser window, so tests run in the background.Step 2: Match options with expected behavior
Cypress opens the browser window and runs tests interactively and D describe interactive modes, which do not happen with --headless. Tests fail because --headless is not a valid option is incorrect because --headless is valid.Final Answer:
Tests run in the background without showing the browser UI -> Option BQuick Check:
--headless = background test run [OK]
- Expecting browser window to open
- Thinking --headless is invalid
- Confusing headless with interactive mode
npx cypress run --headless but tests did not start. Which is the most likely cause?Solution
Step 1: Check the command used
Usingcypress open --headlessis invalid becauseopendoes not support --headless.Step 2: Evaluate other options
Installing Cypress globally is not required withnpx. Missing test files cause errors but not silent failure. Headless mode does not require GUI.Final Answer:
You usedcypress open --headlessinstead ofrun-> Option CQuick Check:
Use 'run' command with --headless [OK]
- Using 'open' command with --headless
- Assuming global install is mandatory
- Thinking headless needs GUI
Solution
Step 1: Understand CI pipeline needs
CI pipelines require automated, non-interactive test runs without UI.Step 2: Choose the command that fits automation
npx cypress run --headlessruns tests automatically without opening browser UI, ideal for CI.Step 3: Eliminate other options
Runnpx cypress openand manually start tests requires manual start, C limits tests to local GUI, D shows browser UI which slows CI.Final Answer:
Runnpx cypress run --headlessin the pipeline script -> Option DQuick Check:
CI automation = run with --headless [OK]
- Running tests manually in CI
- Expecting GUI in CI environment
- Omitting --headless in automated runs
Ready to prove it?
Pass the test and this pattern moves unknown
