Using the cypress configuration we can execute cypress tests in a sequence we desire. Simply write test file names under the testFiles property in your cypress.json file, like below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    "testFiles": [
    "TC01.spec.js",
    "TC02_fixtures.spec.js",
    "TC03_writeReadFile.spec.js",
    "TC04_each.spec.js",
    "TC05_conditionalTesting.spec.js",
    "TC06_fileUpload.spec.js",
    "TC07_fileDownload.spec.js",
    "TC08_apiTesting.spec.js",
    "TC09_apiChaining.spec.js",
    "TC_10_apiMocking.spec.js",
    "TC_11_jsAlertConfirmPrompt.spec.js",
    "TC_12_usingskip.spec.js",
    "TC_13_usingOnly.spec.js"
    ]

cypress testfiles configuration

On running npm test, you can see on the test runner UI that all the tests are listed from 1 to 13 in sequence.

Test files in an alphabetical order

Update 16 Jul 2022: Unfortunately with cypress 10 testFiles will no longer work, but thankfully there is a simple workaround for this.

Go to cypress/e2e and create a file sequenced-tests.cy.js and inside it import the tests in the order you want them to execute as shown below:

1
2
3
4
5
6
//Run tests in the intended order

import './TC05_conditionalTesting.cy.js'
import './TC01.cy.js'
import './TC03_writeReadFile.cy.js'
import './TC02_fixtures.cy.js'

import tests in order

To run the tests in CLI we will just execute the sequenced-tests.cy.js file.

1
npx cypress run --spec=cypress/e2e/sequenced-tests.cy.js

Test execution result for ordered tests

As you can see, in CLI mode the final test execution summary report will only have the name of the spec file sequenced-tests.cy.js along with the test case count from all the different test suites.

To run the tests in Test Runner, just click on sequenced-tests.cy.js, and cypress will do the rest.

test execution in order in test runner

Do check out 🙂

Github: https://github.com/alapanme/Cypress-Automation
All Cypress Articles: https://testersdock.com/cypress-tutorial/