错误:“from”参数必须是字符串类型。收到未定义

问题描述 投票:0回答:3

我正在使用 webdriverIO v7(最新稳定版本)和 cucumber。
我收到这个错误:

Error: The "from" argument must be of type string. Received undefined

这是堆栈跟踪:

2021-04-08T18:29:37.403Z ERROR @wdio/runner: TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined
    at validateString (internal/validators.js:120:11)
    at Object.relative (path.js:437:5)
    at getDefinitionLineAndUri (C:\my-project\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:184:27)
    at buildStepDefinitionConfig (C:\my-project\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:124:7)
    at SupportCodeLibraryBuilder.defineStep (C:\my-project\node_modules\cucumber\lib\support_code_library_builder\index.js:51:79)
    at Object.<anonymous> (C:\my-project\src\step_definitions\/accountSummary_steps.js:6:1)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Module._compile (C:\my-project\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Object.newLoader [as .js] (C:\my-project\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.hookedLoader [as _load] (C:\my-project\node_modules\mockery\mockery.js:111:12)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at C:\my-project\node_modules\@wdio\cucumber-framework\build\index.js:204:13   

在我的帐户Summary_steps.js第6行只有这样:

    import loggedInHeaderModule from "../pages/modules/loggedInHeaderModule"
    import accountSummaryPage from "../pages/accountSummaryPage"

import {Then, When} from 'cucumber';
    When(/^I click on My account details link$/, function () { // This is line 6
        loggedInHeaderModule.openAccountSummary();
    });  

这是我的 package.json 依赖项:

"dependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/plugin-proposal-export-default-from": "^7.5.2",
    "@babel/preset-env": "^7.4.2",
    "@babel/register": "^7.4.0",
    "@types/cucumber": "^7.0.0",
    "@wdio/cli": "^7.3.1",
    "@wdio/config": "^7.3.1",
    "@wdio/cucumber-framework": "^7.3.1",
    "@wdio/local-runner": "^7.3.1",
    "@wdio/selenium-standalone-service": "^7.3.1",
    "@wdio/spec-reporter": "^7.3.1",
    "@wdio/sync": "^7.3.1",
    "chai": "^4.3.4",
    "cucumber": "^6.0.5",
    "eslint-plugin-wdio": "^7.0.0",
    "file-system": "^2.2.2",
    "mjpeg-consumer": "^2.0.0",
    "node-fetch": "^2.6.1",
    "webdriverio": "^7.3.1",
    "yarn": "^1.22.10"
  },
  "devDependencies": {
    "@babel/core": "^7.4.0",
    "@wdio/allure-reporter": "^7.3.1",
    "@wdio/browserstack-service": "^7.3.1",
    "@wdio/junit-reporter": "^7.3.1",
    "babel-eslint": "^10.1.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.23.0",
    "eslint-plugin-import": "^2.22.1",
    "forever": "^3.0.4",
    "jest": "^26.6.3",
    "npm-run-all": "^4.1.5"
  }  

有人知道哪里出了问题吗?
谢谢!

cucumber webdriver-io
3个回答
10
投票

我设法通过删除

"cucumber": "^6.0.5"
依赖项并在
"@cucumber/cucumber": "^7.1.0"
文件中使用
package.json
来解决它。
在我的步骤文件中,我导入了如下语句:

import {Then, When} from '@cucumber/cucumber';    

而不是这个:

import {Then, When} from 'cucumber';  

这似乎是 webdriverIO v7 与 Cucumber 集成的新方式。 (如文档中所述)


0
投票

我对黄瓜有疑问,我也遇到了同样的错误。经过无休止的摆弄之后,我发现包锁定文件看起来有所不同 - 它以 node_modules 开头所有依赖项。我用的黄瓜无法处理这个问题。这与 npm 有关,我将 npm 降级为 < 7. Then I found

npm i --package-lock-only

用以前的格式更新了包锁定文件。

那时我可以运行 npm i 来重新加载 Cucumber。之后就工作了。


0
投票

我仍然面临这个问题。尝试了所有可能的方法来解决错误,例如:通过使用 import-cwd 解决此问题,以便您的支持代码始终需要当前工作目录(即主机项目)中的 cucumber-js :

const importCwd = require('import-cwd') const { 给定,何时,然后 } = importCwd('@cucumber/cucumber').

没有什么对我有用。请帮助我找到正确的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.