Skip to main content

Cypress Run Only One Test

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.

Cypress Run Only One 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

Video Tutorial: Cypress Only Run One Test

Tags
Submitted by arilio666 on June 10, 2022

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.