未定义注入-CodeceptJs和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,但在所有这些方面都得到了相同的结果。

enter image description here

enter image description here

enter image description here

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

enter image description here

这是我的Github repo

非常感谢您。

解决方法

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

能够保留step_definitions / steps 文件夹下的步骤(不是features文件夹内的步骤)。要解决未实现的问题,必须安装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'
}