Bird
Raised Fist0
Cypresstesting~20 mins

Cypress CLI execution - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Cypress CLI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Cypress CLI command?
You run the command cypress run --spec cypress/e2e/login.cy.js in your terminal. What will Cypress do?
ARun all tests in the <code>login.cy.js</code> file and output results in the terminal.
BOpen the Cypress Test Runner GUI and allow manual test selection.
CRun all tests in the <code>cypress/e2e</code> folder except <code>login.cy.js</code>.
DRun tests only in the <code>cypress/support</code> folder.
Attempts:
2 left
💡 Hint
The --spec flag specifies which test file to run in headless mode.
❓ assertion
intermediate
2:00remaining
Which assertion verifies Cypress CLI ran tests successfully?
After running cypress run, you want to check if all tests passed by inspecting the exit code. Which assertion is correct in a Node.js script?
Cypress
const { exec } = require('child_process');
exec('cypress run', (error, stdout, stderr) => {
  // Which assertion below correctly checks success?
});
Aassert.strictEqual(error, null);
Bassert.strictEqual(error.code, 1);
Cassert.strictEqual(stderr.length, 0);
Dassert.strictEqual(stdout.includes('failing'), true);
Attempts:
2 left
💡 Hint
A null error means the command exited with code 0 (success).
🔧 Debug
advanced
2:00remaining
Why does cypress run --headless fail with 'No browser found' error?
You run cypress run --headless --browser chrome but get an error: No browser found named chrome. What is the most likely cause?
AYou must specify the full path to the Chrome executable.
BChrome browser is not installed or not detected on the system.
CThe <code>--headless</code> flag is incompatible with Chrome.
DCypress CLI requires <code>--browser chromium</code> instead of <code>chrome</code>.
Attempts:
2 left
💡 Hint
Cypress needs the browser installed to run tests in it.
🧠 Conceptual
advanced
2:00remaining
What does the --record flag do in Cypress CLI?
You run cypress run --record --key abc123. What is the purpose of the --record flag?
AIt records video of the test run locally on your machine.
BIt runs tests in parallel automatically on multiple machines.
CIt enables verbose logging of all test steps in the terminal.
DIt uploads test results to the Cypress Dashboard for detailed reporting.
Attempts:
2 left
💡 Hint
Think about Cypress Dashboard integration.
❓ framework
expert
2:00remaining
In a CI pipeline, which Cypress CLI command best runs tests with video recording and fails the build on test failures?
You want to run Cypress tests in a CI environment. You want to record videos, upload results to Dashboard, and ensure the pipeline fails if any test fails. Which command is best?
Acypress run --record --key $CYPRESS_RECORD_KEY --video --exit
Bcypress run --record --key $CYPRESS_RECORD_KEY --video --fail-fast
Ccypress run --record --key $CYPRESS_RECORD_KEY --video
Dcypress open --record --key $CYPRESS_RECORD_KEY --video
Attempts:
2 left
💡 Hint
Consider default Cypress CLI behavior on test failures.

Practice

(1/5)
1. What does running cypress run from the command line do?
easy
A. Runs all tests in headless mode without opening the Cypress UI
B. Opens the Cypress Test Runner UI for manual test selection
C. Starts a web server for the application under test
D. Generates a test report without executing tests

Solution

  1. Step 1: Understand the command cypress run

    This command runs Cypress tests from the command line without opening the UI.
  2. Step 2: Identify the mode of execution

    By default, cypress run runs tests in headless mode, meaning no browser window appears.
  3. Final Answer:

    Runs all tests in headless mode without opening the Cypress UI -> Option A
  4. Quick Check:

    cypress run = headless test run [OK]
Hint: Remember: 'run' means headless test execution [OK]
Common Mistakes:
  • Confusing 'cypress run' with 'cypress open'
  • Thinking it opens the UI
  • Assuming it starts a server
2. Which of the following is the correct syntax to run Cypress tests in Chrome browser using CLI?
easy
A. cypress run --browser chrome
B. cypress open --browser chrome
C. cypress run -b firefox
D. cypress start --browser chrome

Solution

  1. Step 1: Identify the correct command to run tests in CLI

    cypress run is used to run tests from CLI, not cypress open or cypress start.
  2. Step 2: Check the correct option for specifying browser

    The option to specify browser is --browser, so cypress run --browser chrome is correct syntax.
  3. Final Answer:

    cypress run --browser chrome -> Option A
  4. Quick Check:

    Use --browser with cypress run [OK]
Hint: Use 'cypress run --browser' to specify browser [OK]
Common Mistakes:
  • Using 'cypress open' instead of 'cypress run' for CLI execution
  • Using wrong option '-b' instead of '--browser'
  • Using non-existent command 'cypress start'
3. What will be the output when running cypress run --spec "cypress/e2e/login.cy.js"?
medium
A. Runs all tests except those in login.cy.js
B. Runs only the tests inside login.cy.js and shows results in terminal
C. Opens Cypress UI and highlights login.cy.js tests
D. Throws an error because --spec is invalid

Solution

  1. Step 1: Understand the --spec option

    The --spec option tells Cypress to run only the specified test file(s).
  2. Step 2: Analyze the command behavior

    The command runs tests only in cypress/e2e/login.cy.js and outputs results in the terminal because cypress run is headless.
  3. Final Answer:

    Runs only the tests inside login.cy.js and shows results in terminal -> Option B
  4. Quick Check:

    --spec runs specified test file only [OK]
Hint: Use --spec to run specific test files [OK]
Common Mistakes:
  • Thinking it runs all tests except specified file
  • Expecting Cypress UI to open with 'run' command
  • Assuming --spec is invalid option
4. You run cypress run --browser chrome --headed but tests still run headless. What is the likely cause?
medium
A. Cypress does not support headed mode with Chrome
B. The Chrome browser is not installed on the machine
C. The command must include --headless to run headed
D. The --headed flag is misspelled or missing

Solution

  1. Step 1: Understand the --headed flag

    The --headed flag runs tests with the browser UI visible, not headless.
  2. Step 2: Identify why tests run headless despite --headed

    The likely cause is that the --headed flag was misspelled (e.g., --headless) or missing from the actual command executed. cypress run defaults to headless mode without the correct flag.
  3. Final Answer:

    The --headed flag is misspelled or missing -> Option D
  4. Quick Check:

    Missing or misspelled --headed defaults to headless [OK]
Hint: Verify --headed flag spelling and presence when headed mode fails [OK]
Common Mistakes:
  • Confusing --headed with --headless
  • Assuming Cypress doesn't support headed Chrome
  • Ignoring browser installation status
5. You want to run tests only in Firefox, headlessly, and save the results to a JSON file named results.json. Which command achieves this?
hard
A. cypress open --browser firefox --headless --output results.json
B. cypress run --browser firefox --headed --reporter json --output results.json
C. cypress run --browser firefox --headless --reporter json --reporter-options output=results.json
D. cypress run --browser firefox --headless --output results.json

Solution

  1. Step 1: Choose correct command and browser

    Use cypress run to run tests headlessly and specify --browser firefox.
  2. Step 2: Specify headless mode and JSON reporter output

    Use --headless for no UI, --reporter json to format output, and --reporter-options output=results.json to save results.
  3. Final Answer:

    cypress run --browser firefox --headless --reporter json --reporter-options output=results.json -> Option C
  4. Quick Check:

    Use reporter options to save JSON results [OK]
Hint: Use --reporter and --reporter-options to save JSON output [OK]
Common Mistakes:
  • Using 'cypress open' instead of 'cypress run'
  • Missing --reporter or reporter-options flags
  • Confusing --headed with --headless
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard