Cypress Run Only One Test

Profile picture for user arilio666

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

  1. Cypress Run Single Test
  2. Cypress Describe Only
  3. Cypress Run Certain Tests
  4. Only While Running Command Line
  5. 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 Run Only One Test

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 Describe Only

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

Cypress Only Run Certain Tests

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