Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cucumber-js: specify path for step-definitions file

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?

like image 982
r.w.20 Avatar asked Jun 27 '18 14:06

r.w.20


People also ask

Which Cucumber option can be used to give path for step definition files?

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.

Where does Cucumber look for step definitions?

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.

How do you define step definitions in cucumbers?

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.


1 Answers

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

like image 75
KyleFairns Avatar answered Sep 24 '22 00:09

KyleFairns