这是我第一次使用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
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 stepsteps.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回购
非常感谢。
发布于 2020-10-12 12:54:19
它现在起作用了,如果对其他人有用的话,我回来这里更新它。
能够将步骤保存在step_/文件夹(而不是特性文件夹中的步骤)下。要解决未实现的问题,必须安装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'
}https://stackoverflow.com/questions/64304096
复制相似问题