cucumber-js: cucumber-js doesn't find step definitions

Hi, I’m a newbie who’s been trying for hours to get cucumber-js to find my step definitions. I’ve come up with this simple example.

In features/foo.feature:

Feature: Foo
  Scenario: Bar
    Given FooBar

In features/step_definitions/step_defs.js:

var {defineSupportCode} = require('cucumber');

defineSupportCode(function({Given}) {
    Given('FooBar', function () {
      return 'pending';
    });    
});

I get this result:

Feature: Foo

  Scenario: Bar
  ? Given FooBar

Warnings:

1) Scenario: Bar - features\foo.feature:2
   Step: Given FooBar - features\foo.feature:3
   Message:
     Undefined. Implement with the following snippet:

       Given('FooBar', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

1 scenario (1 undefined)
1 step (1 undefined)
0m00.000s

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 49 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Alright. I believe I figured this out.

When using a global install of cucumber to run the feature tests, you are still defining support code by requiring the local install of cucumber. The fact that these are two different instances results in no step definitions being loaded.

Is there any reason you can’t use the local install for running the command? I do this on mac by adding “./node_modules/.bin” to my path.

I don’t like the idea of trying to making this work by having the global install try to require the local install in order to get the step definitions. I also dislike the global install since it makes you have to specify things like compile modules by their absolute path.

If this is possible on windows, I’d prefer to just update the documentation to mention that this cannot be used as a global install.

@vvedachalam

It works for me.

The only thing I did was move step_definitions to under the features directory

also i did a npm install cucumber@1.3.3 --save-dev

then ran node_modules/cucumber/bin/cucumber.js features/

I had to downgrade to 1.3.1 to make it work. It does not even work in centos.

On 25 Jan 2017 21:32, “Mrityunjeyan S” notifications@github.com wrote:

I am facing the same issue all of a sudden, the cucumber was fine executing the scripts until today morning. I have no idea what is wrong with it.

I run the feature by rightclick on ruby mine and from command line using the command cucumber -r features/chatstep.feature I get the same result.

Can anyone please help

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cucumber/cucumber-js/issues/718#issuecomment-275224435, or mute the thread https://github.com/notifications/unsubscribe-auth/ALjDKMNdggk1Gh-x_q3KRuvlpN5f_0cOks5rV7E9gaJpZM4LhJZO .

The simple solution for this error is npm install cucumber@1.3.3 --save-dev then run your test …npm test

@GeeChao Ok, again its my silly mistake. Looping variable was not set properly (forgot to compare the length). Thanks again for your support

@GeeChao All worked fine. I made a For loop inside the Then statement which created the issue. Is it possible to use For loop inside step definition? I dont want to use Example as I have to run the Then step based on a Text file data (data driven test) I know this Question is not related to this topic but just thought whether I can get some help.

i get the same issues on windows using command prompt through cygwin maybe thats the issue? i even copied the code directly from the example.

Feature: Simple maths In order to do maths As a developer I want to increment variables

Scenario: easy maths Given a variable set to 1 When I increment the variable by 1 Then the variable should contain 2

Scenario Outline: much more complex stuff Given a variable set to <var> When I increment the variable by <increment> Then the variable should contain <result>

Examples:
  | var | increment | result |
  | 100 |         5 |    105 |
  |  99 |      1234 |   1333 |
  |  12 |         5 |     18 |

Cucumber.defineSupportCode(function(context) { var setWorldConstructor = context.setWorldConstructor; var Given = context.Given var When = context.When var Then = context.Then

///// Your World ///// // // Call ‘setWorldConstructor’ with to your custom world (optional) //

var CustomWorld = function() {};

CustomWorld.prototype.variable = 0;

CustomWorld.prototype.setTo = function(number) { this.variable = parseInt(number); };

CustomWorld.prototype.incrementBy = function(number) { this.variable += parseInt(number); };

setWorldConstructor(CustomWorld);

///// Your step definitions ///// // // use ‘Given’, ‘When’ and ‘Then’ to declare step definitions //

Given(/^a variable set to (\d+)$/, function(number) { this.setTo(number); });

When(/^I increment the variable by (\d+)$/, function(number) { this.incrementBy(number); });

Then(/^the variable should contain (\d+)$/, function(number) { if (this.variable != parseInt(number)) throw new Error('Variable should contain ’ + number + ’ but it contains ’ + this.variable + ‘.’); }); })

i get this error “ReferenceError: Given is not defined” i run cucumber.js and ~/node_modules/.bin/cucumber.js with the specific file name and it always throws an error. I can run cucumber with ruby no problems but i can’t get cucumberjs to work

@charlierudolph I have similar problem. I exactly follow https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md and issue still occur.

My setup is

  • NODE 7.4.0
  • OS: Windows 10
  • Cucumber 2.0.0 -rc.6

@dunlop-ben please see the changelog about the difference between 1.0 and the 2.0 release candidates. The way of defining steps changed, and your example appears to be using the 1.0 syntax.

@jeffmath nothing looks wrong to me. We have feature tests that verify something like your simple example works. Reproducing on a mac, it works as expected for me. What version of node are you running? And from the paths it appears you are on windows machine, is that correct?