我有一个愚蠢的小问题要问你们这些聪明的 QA 人员!事情是这样的...
如何正确安装黄瓜?
我不断收到错误消息
错误:
2024-03-14T15:23:08.851Z ERROR @wdio/runner: Error:
You're calling functions (e.g. "When") on an instance of Cucumber that isn't running.
This means you have an invalid installation, mostly likely due to:
- Cucumber being installed globally
- A project structure where your support code is depending on a different instance of Cucumber
Either way, you'll need to address this in order for Cucumber to work.
See https://github.com/cucumber/cucumber-js/blob/main/docs/installation.md#invalid-installations
我启用了日志,发现黄瓜崩溃了并且没有做它的事情。 appium 安装日志正在连接到设备并在每次测试运行后终止会话,但 wdio 显示 cucumber 正在崩溃...
wido日志:
2024-03-14T15:22:58.331Z INFO @wdio/local-runner: Run worker command: run
2024-03-14T15:22:58.568Z DEBUG @wdio/runner: init remote session
2024-03-14T15:22:58.571Z DEBUG @wdio/utils:initializeServices: initialize service "appium" as NPM package
2024-03-14T15:22:58.670Z INFO wdio-cucumberjs-json-reporter: The 'reportFilePerRetry' was not set, it has been set to the default 'true'
2024-03-14T15:22:59.112Z DEBUG @wdio/runner: init remote session
2024-03-14T15:22:59.113Z INFO webdriver: Initiate new session using the WebDriver protocol
2024-03-14T15:22:59.113Z INFO @wdio/utils: Connecting to existing driver at http://127.0.0.1:4723/
2024-03-14T15:22:59.122Z INFO webdriver: [POST] http://127.0.0.1:4723/session
2024-03-14T15:22:59.122Z INFO webdriver: DATA {
capabilities: {
alwaysMatch: {
platformName: 'Android',
'appium:sessionOverride': false,
'appium:debugLogSpacing': true,
'appium:connectionRetryTimeout': 30000,
'appium:maxInstances': 1,
'appium:maxInstancesPerCapability': 1,
'appium:connectionRetryCount': 5,
'appium:app': 'test.apk',
'appium:automationName': 'UiAutomator2',
'appium:nativeInstrumentsLib': true,
'appium:isolateSimDevice': true,
'appium:noReset': false,
'appium:relaxedSecurity': true,
'appium:get_server_logs': true,
'appium:autoGrantPermissions': true,
'appium:autoLaunch': true
},
firstMatch: [ {} ]
},
desiredCapabilities: {
platformName: 'Android',
'appium:sessionOverride': false,
'appium:debugLogSpacing': true,
'appium:connectionRetryTimeout': 30000,
'appium:maxInstances': 1,
'appium:maxInstancesPerCapability': 1,
'appium:connectionRetryCount': 5,
'appium:app': 'test.apk',
'appium:automationName': 'UiAutomator2',
'appium:nativeInstrumentsLib': true,
'appium:isolateSimDevice': true,
'appium:noReset': false,
'appium:relaxedSecurity': true,
'appium:get_server_logs': true,
'appium:autoGrantPermissions': true,
'appium:autoLaunch': true
}
}
2024-03-14T15:23:08.851Z DEBUG @wdio/utils:shim: Finished to run "after" hook in 0ms
2024-03-14T15:23:08.851Z ERROR @wdio/runner: Error:
You're calling functions (e.g. "When") on an instance of Cucumber that isn't running.
This means you have an invalid installation, mostly likely due to:
- Cucumber being installed globally
- A project structure where your support code is depending on a different instance of Cucumber
Either way, you'll need to address this in order for Cucumber to work.
See https://github.com/cucumber/cucumber-js/blob/main/docs/installation.md#invalid-installations
at checkInstall (C:\workspace\ui-test\node_modules\@cucumber\cucumber\src\support_code_library_builder\index.ts:127:15)
at C:\workspacei-test\node_modules\@cucumber\cucumber\src\support_code_library_builder\index.ts:145:11
at Object.<anonymous> (C:\workspace\ui-test\test\step-definitions\service-steps.js:6:1)
at Module._compile (node:internal/modules/cjs/loader:1196:14)
at Module.m._compile (C:\workspace\ui-test\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
at Object.require.extensions.<computed> [as .js] (C:\workspaceu\ui-test\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1074:32)
at Function.Module._load (node:internal/modules/cjs/loader:909:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
2024-03-14T15:23:08.871Z INFO webdriver: COMMAND deleteSession()
2024-03-14T15:23:08.871Z INFO webdriver: [DELETE] http://127.0.0.1:4723/session/a47d2b52-87f0-435b-96bf-6960c5da4172
2024-03-14T15:23:09.610Z INFO webdriver: RESULT null
Appium 做得很好,但黄瓜似乎让我感到悲伤。
我尝试删除一些黄瓜包并更新和降级版本,但我似乎无法让黄瓜工作。
package.json
{
"name": "ui-test",
"version": "1.0.0",
"description": "testing",
"main": "index.js",
"scripts": {
"test": "wdio lan.wdio.conf.js",
"wdio": "wdio run wdio.conf.js"
},
"author": "x",
"license": "ISC",
"devDependencies": {
"@wdio/allure-reporter": "8.29.2",
"@wdio/appium-service": "8.29.1",
"@wdio/cli": "8.29.1",
"@wdio/cucumber-framework": "8.29.1",
"@wdio/local-runner": "8.29.2",
"@wdio/selenium-standalone-service": "8.15.0",
"@wdio/sync": "7.27.0",
"allure-commandline": "2.26.0",
"appium": "2.5.1",
"chai": "4.4.1",
"chromedriver": "121.0.0",
"cucumber": "6.0.7",
"multiple-cucumber-html-reporter": "3.6.1",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"wdio-chromedriver-service": "8.1.1",
"wdio-cucumberjs-json-reporter": "5.1.8",
"webdriverio": "8.29.1",
"appium-uiautomator2-driver": "^2.29.5",
"@wdio/spec-reporter": "^8.16.3",
"debug": "^4.3.4"
},
"dependencies": {
"axios": "1.6.7",
"request-promise-native": "1.0.9",
"wdio-appium-service": "0.2.3"
}
}
根据 npm 为什么,(如果我正确地阅读了这篇文章,一切都很好......)
npm 为什么输出:
PS C:\Workspace\ui-test> npm why @cucumber/cucumber
npm WARN config optional Use `--omit=optional` to exclude optional dependencies, or
npm WARN config `--include=optional` to include them.
npm WARN config
npm WARN config Default value does install optional deps unless otherwise omitted.
npm WARN config optional Use `--omit=optional` to exclude optional dependencies, or
npm WARN config `--include=optional` to include them.
npm WARN config
npm WARN config Default value does install optional deps unless otherwise omitted.
@cucumber/[email protected] dev
node_modules/@cucumber/cucumber
@cucumber/cucumber@"9.5.1" from @wdio/[email protected]
node_modules/@wdio/cucumber-framework
dev @wdio/cucumber-framework@"8.29.1" from the root project
PS C:\Workspace\ui-test>
有一个简单的方法可以修复这个黄瓜错误吗?
他,
X
我设法解决了这个问题。
npm why @cucumber/cucumber
查找所有已安装的 Cucumber 安装,并从 package.json 中删除所有多余的安装npm why @cucumber/cucumber
@cucumber/[email protected] dev
node_modules/@cucumber/cucumber
@cucumber/cucumber@"9.5.1" from @wdio/[email protected]
node_modules/@wdio/cucumber-framework
dev @wdio/cucumber-framework@"8.29.1" from the root project
如果配置良好,如果您有多个根条目,则必须删除它们。
因此,如果您使用 wdio/cucumber-framework,则无需将 @cucumber/cucumber 添加到包 json 中,因为它已经加载了...
npm list --all
显示使用 npm 加载的包....+package1
+package2
+package3
+package4
+package5
-package6
-package7
如果您有任何开头带有“-”符号的软件包,请将其删除。在底部,npm 还会提醒您缺少的依赖项,以便您添加。
如果您在 jenkins 中运行它们,则 wdio 浏览器应该设置无头选项。不然会失败。