03 Test Execution - biswajitsundara/Cypress GitHub Wiki

We have different ways to execute the script/spec files

Using Test Runner

  • Run this command node_modules\.bin\cypress open to launch the test runner
  • Then select the spec file you want to run
  • Top right corner we have the option to select the browser
  • We can run single spec file or all the spec files at once.

Using CLI

  • All specs in headless mode (electron) - node_modules\.bin\cypress run

  • All specs in chrome browser - node_modules\.bin\cypress run --browser chrome

  • Run a single spec file (headless):
    node_modules\.bin\cypress run --spec "cypress\integration\practice.js"

  • Run spec files from a folder
    node_modules\.bin\cypress run --spec "cypress\integration\demo\**\*"

  • Run a single spec file in chrome browser:
    node_modules\.bin\cypress run --browser chrome --spec "cypress\integration\practice.js"

Execute Specs in Order

  • By default the specs will run in alphabetical order.
  • Let's say we have two spec files practice.js and google.js
  • Then it will execute the google.js first and then practice.js
  • If we want to execute them in a specific order then update cypress.json file like below
{
    "testFiles": [
        "practice.js",
        "google.js"
    ]   
}

If we run using the command node_modules\.bin\cypress run --browser chrome then it will execute the practice.js file first and then google.js

Configuring npm test

  1. We can also mention the command in package.json this way
"scripts": {
    "test": "node_modules/.bin/cypress run --browser chrome"
  }

Then for executing the test, just enter the command npm run test

  1. Using the Cypress run command
"scripts": {
    "test": "cypress run --browser chrome"
  }

Then for executing the test, just enter the command npm run test

  1. Using the Cypress Test Runner
"scripts": {
    "test": "cypress open"
  }

Then for executing the test, just enter the command npm run test

Reference

https://docs.cypress.io/guides/guides/command-line.html
https://docs.cypress.io/guides/references/configuration.html

⚠️ **GitHub.com Fallback** ⚠️