英文:
"Error: not found: java" when running webdriver.io test
问题
我正试图通过VS Code调试器运行一个webdriver.io测试套件,但它在错误消息中失败了:
ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: not found: java
at getNotFoundError (/Users/andrew/projects/rod-licensing-tests/packages/frontend-acceptance-tests/node_modules/selenium-standalone/node_modules/which/which.js:10:17)
我该如何解决这个问题?从在网上找到的类似问题来看,我尝试了以下方法,但结果都一样:
npm install
- 使用
npm install java
安装 Java - 使用
./node_modules/.bin/selenium-standalone install
安装 selenium-standalone - 在我的
launch.json
配置中添加一个环境变量:"JAVA_HOME": "/usr/libexec/java_home"
- 通过系统偏好设置将我的 Mac 更新到 Java 8 更新 271
虽然使用 Docker 可以成功运行测试,但我更希望能够从 IDE 中运行并快速启动和调试测试。此外,我的同事可以在 IntelliJ IDE Ultimate 中使用配置运行相同的测试,但我觉得在 VS Code 中也应该是可能的。
以下是我 launch.json
文件的当前内容:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch via NPM",
"type": "pwa-node",
"args": [
"conf/local.conf.js",
"--logLevel trace"
],
"cwd": "${workspaceFolder}/packages/frontend-acceptance-tests",
"env": {
"JAVA_HOME": "/usr/libexec/java_home",
"SERVICE_URL": "[redacted]",
"OAUTH_AUTHORITY_HOST_URL": "[redacted]",
"OAUTH_TENANT": "[redacted]",
"OAUTH_CLIENT_ID": "[redacted]",
"OAUTH_CLIENT_SECRET": "[redacted]",
"OAUTH_SCOPE": "[redacted]",
"DYNAMICS_API_PATH": "[redacted]",
"DYNAMICS_API_VERSION": "9.1"
},
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/packages/frontend-acceptance-tests/node_modules/.bin/wdio",
"runtimeVersion": "14.13.0"
}
]
}
我对 Node.JS 还不太熟悉,仍在学习如何将其组合在一起。欢迎提供建议!
英文:
I'm trying to run a webdriver.io test suite from the VS Code debugger but it is failing with the error message:
ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: not found: java
at getNotFoundError (/Users/andrew/projects/rod-licensing-tests/packages/frontend-acceptance-tests/node_modules/selenium-standalone/node_modules/which/which.js:10:17)
How do I get round this? From looking at similar issues on the web, I've tried the following with the same results:
npm install
- installing Java using
npm install java
- installing selenium-standalone with
./node_modules/.bin/selenium-standalone install
- adding an environment variable to my
launch.json
config:"JAVA_HOME": "/usr/libexec/java_home"
- updating Java on my Mac to Java 8 update 271 via System Preferences
The tests do run successfully using Docker, but I'd ideally want to run this from the IDE too so that I can quickly start and debug them. Also, my colleague can run the same tests using config in IntelliJ IDE Ultimate but I feel this should be possible in VS Code too.
This is the current content of my launch.json
file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch via NPM",
"type": "pwa-node",
"args": [
"conf/local.conf.js",
"--logLevel trace"
],
"cwd": "${workspaceFolder}/packages/frontend-acceptance-tests",
"env": {
"JAVA_HOME": "/usr/libexec/java_home",
"SERVICE_URL": "[redacted]",
"OAUTH_AUTHORITY_HOST_URL": "[redacted]",
"OAUTH_TENANT": "[redacted]",
"OAUTH_CLIENT_ID": "[redacted]",
"OAUTH_CLIENT_SECRET": "[redacted]",
"OAUTH_SCOPE": "[redacted]",
"DYNAMICS_API_PATH": "[redacted]",
"DYNAMICS_API_VERSION": "9.1"
},
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/packages/frontend-acceptance-tests/node_modules/.bin/wdio",
"runtimeVersion": "14.13.0"
}
]
}
I'm pretty new to Node.JS so still learning how it fits together. Any suggestions appreciated!
答案1
得分: 2
在使用selenium-standalone-service运行测试时,需要安装JAVA-JDK。另外,以下依赖项应该在package.json中可用:
{
"devDependencies": {
"@wdio/selenium-standalone-service": "^6.6.1"
}
}
或者
npm install @wdio/selenium-standalone-service --save-dev
**用于VScode调试**
根据[文档][1],我们需要启用[JavaScript调试器(Nightly)][2]。
示例.vscode/launch.json应如下所示
{
"name": "run select spec",
"type": "node",
"request": "launch",
"args": ["wdio.conf.js", "--spec", "${file}"],
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"program": "${workspaceRoot}/node_modules/@wdio/cli/bin/wdio.js",
"console": "integratedTerminal"
},
示例:[launch.json][3]
[1]: https://webdriver.io/docs/debugging.html
[2]: https://marketplace.visualstudio.com/items?itemName=ms-vscode.js-debug-nightly
[3]: https://github.com/mgrybyk/webdriverio-devtools/blob/master/.vscode/launch.json
英文:
In case we are using selenium-standalone-service for running the test then JAVA-JDK need to be installed. Also below dependency should be available in the package.json
{
"devDependencies": {
"@wdio/selenium-standalone-service": "^6.6.1"
}
}
or
>npm install @wdio/selenium-standalone-service --save-dev
For VScode debugging
As per documentation we will need JavaScript Debugger (Nightly) enabled.
Sample .vscode/launch.json should looks like
{
"name": "run select spec",
"type": "node",
"request": "launch",
"args": ["wdio.conf.js", "--spec", "${file}"],
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"program": "${workspaceRoot}/node_modules/@wdio/cli/bin/wdio.js",
"console": "integratedTerminal"
},
Example : launch.json
答案2
得分: 1
你通常需要使用Java 1.8版本来配置项目的SDK,可以从此链接安装:
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
但我看到你已经尝试过了。也许你需要将Selenium的JAR文件添加到项目的依赖中。
英文:
You usually need to configure your project sdk with Java version 1.8 which can be installed from this link:
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
But I see you already tried that. Perhaps you need to add the selenium jar files to your project's dependencies.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论