【问题标题】:inject is not defined - CodeceptJs and CucumberJs未定义注入 - CodeceptJs 和 CucumberJs
【发布时间】:2021-01-25 22:54:57
【问题描述】:

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

当我在终端上运行 npx codeceptjs gherkin:steps 或 sn-ps 时,我收到这条消息说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 上进行了尝试,但在所有这些上都得到了相同的结果。

基本功能

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 Ultimate 2020.2

这里是我的Github repo

非常感谢。

【问题讨论】:

    标签: intellij-idea cucumber cucumberjs codeceptjs


    【解决方案1】:

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

    能够将步骤保存在 step_definitions/steps 文件夹下(不是 features 文件夹中的那个)。要修复未实现的问题,必须安装 wdio 依赖项。为了通过运行 npm install 使其正常生效,node_modules 和 package-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'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 2017-08-14
      • 1970-01-01
      相关资源
      最近更新 更多