03 Test Execution - biswajitsundara/Cypress GitHub Wiki
We have different ways to execute the script/spec files
- Run this command
node_modules\.bin\cypress opento 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.
-
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"
- By default the specs will run in alphabetical order.
- Let's say we have two spec files
practice.jsandgoogle.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.jsonfile 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
- 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
- Using the Cypress run command
"scripts": {
"test": "cypress run --browser chrome"
}
Then for executing the test, just enter the command npm run test
- Using the Cypress Test Runner
"scripts": {
"test": "cypress open"
}
Then for executing the test, just enter the command npm run test
https://docs.cypress.io/guides/guides/command-line.html
https://docs.cypress.io/guides/references/configuration.html