To run only one test with Cypress and JavaScript, we can set the --space option or use the it. only method. to run the tests in path/to/file. spec.
cypress run --no-exit To prevent the Cypress App from exiting after running tests in a spec file, use --no-exit .
Run multiple tests using --spec options in your Cypress command line. Organize Cypress Tests in a folder as a Test Suite. Cypress support/index. js and Environment Variable create Test Suite Dynamically.
cypress run --spec path/to/file.spec.js
or using glob patterns:
cypress run --spec 'path/to/files/*.spec.js'
Note: you need to wrap your glob patterns in single quotes to avoid shell expansion!
You can use a .only
as described in the Cypress docs
it.only('only run this one', () => {
// similarly use it.skip(...) to skip a test
})
it('not this one', () => {
})
Also, you can do the same with describe
and context
blocks
there's also a nice VSCode
extension to make adding/removing .only
's easier with keyboard shortcuts. It's called Test Utils (install with ext install chrisbreiding.test-utils
). It works with js, coffee, and typescript:
There are multiple ways of achieving this.
.only
to it
or describe
see @bkucera answernpx cypress run --record --spec "cypress/integration/my-spec.js" npm run cypress -- --record --spec "cypress/integration/my-spec.js"
You can mute not needed test suites and particular cases by prepending x
to testrunner methods call (describe
, it
, etc.)
So it would look like:
// this whole testsuite will be muted
xdescribe('Visit google', () => {
it('should visit google', () => { cy.visit('https://google.com/'); });
});
// this testsuite will run
describe('Visit youtube', () => {
it('should visit youtube', () => { cy.visit('https://youtube.com/'); });
// this testcase will be muted
xit('is not necessary', () => { ... });
});
You can run the test like this.
cypress run --spec **/file.js
There is one way I have found to skip tests which I don't need to run (in the current test), and that is to use: this.skip();
it('test page', function () {
// skip this test for now
this.skip();
cy.visit('http://example.com/')
cy.contains('test page').click()
cy.url()
.should('include', '/test-page/')
})
1. it is important to use regular function as second argument of it, this will not be available in arrow function
2. Whole of the test will be skipped no matter where we write this.skip()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With