Please take a look at an example here:
https://github.com/TheBrainFamily/cypress-cucumber-example
Important steps:
Install this plugin:
npm install --save-dev cypress-cucumber-preprocessor
Put your step definitions in cypress/support/step_definitions
Examples: cypress/support/step_definitions/google.js
/* global given */
// you can have external state, and also require things!
const url = 'https://google.com'
given('I open Google page', () => {
cy.visit(url)
})
cypress/support/step_definitions/shared.js
/* global then */
then(`I see {string} in the title`, (title) => {
cy.title().should('include', title)
})
Since given/when/then are on global scope please use
/* global then, when, given */
to make IDE/linter happy
We had a pattern to import those explicitly, but for some reason it was messing up the watch mode on Linux :-( (#10)
Your feature file in cypress/integration:
Example: cypress/integration/Facebook.feature
Feature: The Facebook
I want to open a social network page
Scenario: Opening a social network page
Given I open Facebook page
Then I see "Facebook" in the title
Add it to your plugins:
cypress/plugins/index.js
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
}
Step definition files are by default in: cypress/support/step_definitions. If you want to put them somewhere please use cosmiconfig format. For example, add to your package.json :
"cypress-cucumber-preprocessor": {
"step_definitions": "cypress/support/step_definitions/"
}
Run your cypress the way you would normally do :) click on a .feature file on the list of specs, and see the magic happening!
We use https://docs.cucumber.io/cucumber-expressions/ to parse your .feature file, please use that document as your reference
Install all dependencies:
npm install
Link the package:
npm link
npm link cypress-cucumber-preprocessor
Run tests:
npm test
Please let me know if you find any issues or have suggestions for improvements.
You can use this package with TypeScript!
module.exports = on => {
on('file:preprocessor', cypressTypeScriptPreprocessor)
on('file:preprocessor', cucumber())
}
(Maybe?) Option to customize mocha template ( #3 )
Based/inspired on great work on https://github.com/sitegeist/gherkin-testcafe , although, with this package we don't have to run cypress programmatically - with an external runner, we can use cypress as we are used to :)
Thanks to the Cypress team for the fantastic work and very exciting tool! :-)
Thanks to @fcurella for fantastic work with making the preprocessor reactive to file changes. :-)