To run a specified suite or test, append .only to the describe or it. Using only is recommended for writing a test because while working on a test, you would only run that test or its suite.
Table of Content
- Cypress Run Single Test
- Cypress Describe Only
- Cypress Run Certain Tests
- Only While Running Command Line
- Video Tutorial
Cypress Run Single Test
Below code will execute Test 2 of Suite 1.
describe('suite 1', () => {
it('suite 1 - test 1', () => {
// test 1
})
it.only('suite 1 - test 2', () => {
//test 2
})
it('suite 1 - test 3', () => {
//test 3
})
})
describe('suite 2', () => {
it('suite 2 - test 1', () => {
// test 1
})
it('suite 2 - test 2', () => {
//test 2
})
})
Output
Cypress Describe Only
Below code will execute Test Suite 1 only.
describe.only('suite 1', () => {
it('suite 1 - test 1', () => {
// test 1
})
it('suite 1 - test 2', () => {
//test 2
})
it('suite 1 - test 3', () => {
//test 3
})
})
describe('suite 2', () => {
it('suite 2 - test 1', () => {
// test 1
})
it('suite 2 - test 2', () => {
//test 2
})
})
Output
Cypress Only Run Certain Tests
Below code will execute Test 1 of Suite 1 and Test 2 of Suite 2.
describe('suite 1', () => {
it.only('suite 1 - test 1', () => {
// test 1
})
it('suite 1 - test 2', () => {
//test 2
})
it('suite 1 - test 3', () => {
//test 3
})
})
describe('suite 2', () => {
it('suite 2 - test 1', () => {
// test 1
})
it.only('suite 2 - test 2', () => {
//test 2
})
})
Output
Only While Running Command Line
If you are executing command line, you must specify the spec file in which you are using only otherwise all spec file will run.
$ npx cypress run --spec cypress/integration/sample.spec.js
- Log in to post comments