Search code examples
npmprotractorcucumberbddcucumberjs

Getting undefined step definition warning in Cucumber Protractor setup


I have installed the npm modules locally (find the dependencies details in below package.json) and try to execute the below cucumber feature file and SD but getting Undefined. Implement.. message.

I have prepared my feature file as below: Stored in: test/features/sample.feature

 Feature: Running Cucumber with Protractor
 @test
 Scenario: To verify the Search result
  Given I am on home page

And implemented the SD as below: Stored in: test/step_definitions/sample.steps.js

 module.exports = function() {
  this.Given(/^I am on home page$/, function () {
    return browser.get("http://www.google.com");
   });
 }

And my specs & cucumberOpts in conf.js as below:

 specs: [
 './../features/*.feature'
 ],

 cucumberOpts: {
  require: ['./step_definitions/*.steps.js'],
  tags: '@test',
  strict: true,
  format: 'pretty'
 }

Installed package.json dependencies details:

 "dependencies": {
  "chai": "^4.0.1",
  "chai-as-promised": "^6.0.0",
  "cucumber": "^2.3.0",
  "protractor": "^5.1.2",
  "protractor-cucumber-framework": "^3.1.1"
 }

But in execution getting the message as :

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

can anyone help me to come out...


Solution

  • Your problem seems to be with the step definitions themselves.

    You seem to be using the old CucumberJS 1.x syntax for the 2.x framework.

    Here's the update to the step definition provided using 2.x syntax:

    var {defineSupportCode} = require('cucumber');
    
    defineSupportCode(({Given, When, Then}) => {
    
      Given(/^I am on home page$/, function () {
        return browser.get("http://www.google.com");
      });
    
    });