I am working on a Web-test automation framework, and would like to few functionalities present in describe()
block in one cypress ..spec.js file, by methods present in another in another cypress ..spec.js file?
Kindly read about Shared Behaviour facility provided in Mocha: https://github.com/mochajs/mocha/wiki/Shared-Behaviours
I tried that but its not working. 1. Is it possible to achieve something similar to Mocha Shared steps (as descibed above)? 2. Or is there something similar to Cucumber-ruby/Pico-container's WORLD object?
Kindly advise.
You can use custom commands to re-use steps over several files. This can be done by the following steps.
cypress/support/commands.js
with the steps which you want to use in several files. You can use this syntax:Cypress.Commands.add('customCommand', function() {
cy.get('object')
.clear()
.type('something')
// do other steps
})
describe('Description of the test', function () {
it('first scenario of the test', function () {
cy.customCommand()
})
})
Concluding: to share steps over several testfiles, you need to place the shared steps in the commands.js instead of in a testfile.