未定义注入 - CodeceptJs 和 CucumberJs

inject is not defined - CodeceptJs and CucumberJs

这是我第一次使用 CodeceptJs,我正在努力 运行 我的功能文件,因为 IDE 要求我 implement steps for my scenario但这已经完成了,所以我觉得它可能在 codecept.conf.js 文件下指定的以外的地方搜索它们?

当我 运行 npx codeceptjs gherkin:steps 或终端上的代码片段时,我收到这条消息说 Could not include object Step Definition from ./step_definitions/steps.js from module '/Users/myUser/IdeaProjects/codeceptjs_webdriver/step_definitions/steps.js' The "from" argument must be of type string. Received undefined .

然后我将 step_definitions 文件夹移动到内部功能,因为我读到这将是这些功能的默认位置,现在得到一个 inject is not defined error,这可能是问题的实际原因我'我收到了,但不确定如何解决它。

我试过 IntelliJ Ultimate、Webstorm 和 VSCode,但在所有这些上都一样。

basic.feature

Feature: Business rules
  In order to achieve my goals
  As a persona
  I want to be able to interact with a system

  Scenario: do something
    Given I have a defined step

steps.js

const {Given} = require('cucumber');
const {I} = inject();

Given(/^I have a defined step$/, function () {
    I.amOnPage('/');
});

codecept.conf.js

  exports.config = {
  output: './output',
  helpers: {
    WebDriver: {
      url: 'https:www.google.com',
      browser: 'chrome'
    }
  },
  include: {
    I: './steps_file.js'
  },
  mocha: {},
  bootstrap: null,
  teardown: null,
  hooks: [],
  gherkin: {
    features: './features/*.feature',
    steps: ['./step_definitions/steps.js']
  },
  plugins: {
    screenshotOnFail: {
      enabled: true
    },
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true
    },
    tryTo: {
      enabled: true
    }
  },
  tests: './*_test.js',
  name: 'codeceptjs_webdriver'
}

package.json

 {
  "name": "codeceptjs_webdriver",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "codeceptjs": "^3.0.0",
    "cucumber": "^5.0.1"
  },
  "dependencies": {
    "@codeceptjs/configure": "^0.6.0"
  },
  "description": ""
}

IntelliJ 旗舰版 2020.2

这是我的 Github repo

非常感谢。

它现在正在运行,如果对其他人有用,我会回来更新它。

能够将步骤保留在 step_definitions/steps 文件夹下(而不是功能文件夹中的那个)。要解决未实现的问题,必须安装 wdio 依赖项。为了使其通过 运行 npm install 正常生效,node_modulespackage-lock.json 都必须 删除 才能重新生成。

已更新package.json

  {
  "name": "codeceptjs_webdriver",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "npx codeceptjs run"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "@wdio/selenium-standalone-service": "^6.6.2",
    "codeceptjs": "^2.6.8",
    "codeceptjs-assert": "0.0.4",
    "webdriverio": "6.3.6"
  },
  "description": ""
}

已更新codecept.conf.js

exports.config = {
output: './output',
  helpers: {
    WebDriver: {
      url: 'https://www.google.com',
      browser: 'chrome'
    }
  },
  include: {
    I: './steps_file.js'
  },
  mocha: {},
  bootstrap: null,
  teardown: null,
  hooks: [],
  gherkin: {
    features: './features/*.feature',
    steps: ['./step_definitions/steps.js']
  },
  plugins: {
    wdio: {
        enabled: true,
        services: ['selenium-standalone']
        // additional config for service can be passed here
    },
    screenshotOnFail: {
      enabled: true
    },
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true
    },
  },
  tests: './*_test.js',
  name: 'codeceptjs_webdriver'
}