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" ] |
On running npm test, you can see on the test runner UI that all the tests are listed from 1 to 13 in sequence.
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' |
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 |
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.
Do check out 🙂
Github:Â https://github.com/alapanme/Cypress-Automation
All Cypress Articles: https://testersdock.com/cypress-tutorial/
Hi Arpan,
If we have created a separate folder for the page and separate folder for the test class then it is feasible or not?
There is no one way to do this. So. if this works for your project then you can go with this approach.
Hello I have this code,
“testFiles” : [
“login.js”,
“cartasResguardo.js”,
“persona.js”,
“beneficiarios.js”,
“visorConvenio.js”,
“convenio.js”
]
but when pressing Running integration tests, Just show me beneficiario and convenio. something is missing
This only takes the spec file in order. What about in a particular spec file I have created one suite which is having 20+ test cases and I want to run them in order?
How to perform the same actions with Cypress version 8
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:
//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’