I have multiple projects and I would like to implement cucumber-js E2E testing for all of them. I have a step definitions file which can be used for testing all of these projects, however I want to have multiple feature files with each project folder containing the feature files specific to the project. This is the layout:
step definitions: projects/E2E/step_definitions/chat.js
feature files: projects/project_1/features/feature_1.js
Right now, since the step definitions is outside of the features folder, I'm getting unimplemented steps error. Is there a way to specify the path to the step definitions when running cucumber-js?
An annotation followed by the pattern is used to link the Step Definition to all the matching Steps, and the code is what Cucumber will execute when it sees a Gherkin Step. Cucumber finds the Step Definition file with the help of the Glue code in Cucumber Options.
inside the directory in which Cucumber is run is treated as a step definition. In the same directory, Cucumber will search for a Feature corresponding to that step definition. This is either the default case or the location specified with the relevant relevant relevant -r relevant option.
A Step Definition is a Java method Kotlin function Scala function JavaScript function Ruby block with an expression that links it to one or more Gherkin steps. When Cucumber executes a Gherkin step in a scenario, it will look for a matching step definition to execute.
I believe that the step definitions will be classed as a support file, which should mean you can include them like this:
npm run cucumberjs -- --require "../E2E/step_definitions/*.js"
Note
This assumes that your package.json is inside your project_1
directory and includes:
"scripts": {
"cucumberjs": "./node_modules/.bin/cucumber-js"
},
Reference
CucumberJS Official Documents for Requiring Support Files
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