在 Cucumber Protractor 设置中获取未定义的步骤定义警告

Getting undefined step definition warning in Cucumber Protractor setup

我已经在本地安装了 npm 模块(在下面 package.json 中找到依赖项详细信息)并尝试执行下面的 cucumber 功能文件和 SD,但得到 Undefined。实施.. 消息.

我准备了我的特征文件如下:存储在:test/features/sample.feature

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

并实现如下SD:存储在:test/step_definitions/sample.steps.js

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

我的 specs & cucumberOpts 在 conf.js 如下:

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

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

已安装 package.json 依赖项详细信息:

 "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"
 }

但在执行中得到消息为:

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

谁能帮我出来...

您的问题似乎与步骤定义本身有关。

您似乎在为 2.x 框架使用旧的 CucumberJS 1.x 语法。

这是对使用 2.x 语法提供的步骤定义的更新:

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

defineSupportCode(({Given, When, Then}) => {

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

});