if you try in locally, then
1, If you want to skip a specific test group or test case, one approach is to add .skip at the end of context or it blocks. For example, context.skip() or it.skip().
context.skip('Test group', () => {
// This whole test group will be skipped
it('Test case 1', () => {
// This test case will not run because test group is skipped
});
});
context('Test group', () => {
it.skip('test case1', () => {
// Test case one will be skipped
});
it('test case2', () => {
// Detail for test case two
// This will execute
});
});
- Run Specific/modified Tests Only
you can add .only at the end of context or it block, such as context.only() or it.only().
// Only 1st test group will run
context.only('test group1', () => {
it('test case', () => {
// Test case one will run
});
it('test case2', () => {
// Test case two will run
});
});
// The 2nd test group will not run
context('test group2', () => {
it('test case3', () => {
// Test case three will be skipped
});
it('test cas4', () => {
// Test case three will be skipped
});
});
context('test group', () => {
it.only('test case1', () => {
// Test case one will run
});
it('test case2', () => {
// Test case two will be skipped
});
});
- Run Tests Conditionally by Using cypress.json
run tests conditionally is to use cypress.json file, if you want to run a specific test file.
If you only want to run tests in test.spec.js file, you can just add file path to test files in the cypress.json.
{
"testFiles": "**/test.spec.js"
}
run multiple test files
{
"testFiles": ["**/test-1.spec.js", "**/test-2.spec.js"]
}
ignore specific tests from your test runs
{
"ignoreTestFiles": "**/*.ignore.js"
}
Run Tests Conditionally by Using command line
npx cypress run --spec "cypress/integration/test.spec.js"
To run all the tests in a specific folder with file name end with .spec.js
npx cypress run --spec "cypress/integration/testgroup-directory-name/*.spec.js"
If you are using CI/CD then this will help you and you can get an idea.
Faster test execution with cypress-grep