首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义inject - CodeceptJs和CucumberJs

未定义inject - CodeceptJs和CucumberJs
EN

Stack Overflow用户
提问于 2020-10-11 12:37:54
回答 1查看 1.3K关注 0票数 0

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

当我在终端上运行:步骤或代码片段时,我会收到这样的消息: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终极版、网络风暴版和VSCode版,但它们都是一样的。

basic.feature

代码语言:javascript
复制
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

代码语言:javascript
复制
const {Given} = require('cucumber');
const {I} = inject();

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

codecept.conf.js

代码语言:javascript
复制
  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

代码语言:javascript
复制
 {
  "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回购

非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-12 12:54:19

它现在起作用了,如果对其他人有用的话,我回来这里更新它。

能够将步骤保存在step_/文件夹(而不是特性文件夹中的步骤)下。要解决未实现的问题,必须安装wdio依赖项。为了使它通过运行npm install正确地发挥作用,node_modulespackage-lock.json都必须被删除,才能重新生成。

更新的package.json

代码语言:javascript
复制
  {
  "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

代码语言:javascript
复制
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'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64304096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档