5

我已将 Node、Protractor、JDK 和 webdriver 升级到最新版本。现在我不能再通过 CMD 和 Node 命令行启动 webdriver-manager 了。

任何想法?

错误: 您的环境已设置为使用 Node.js 0.12.2 (x64) 和 npm。

C:\Users\idan>cd c:\automation\tests\node_modules\protractor\bin

c:\automation\tests\node_modules\protractor\bin>webdriver-manager start
selenium.pid: 6484
'java' is not recognized as an internal or external command,
operable program or batch file.
Selenium Standalone has exited with code 1

c:\automation\tests\node_modules\protractor\bin>
4

3 回答 3

2

您需要jdk安装并JAVA_HOME设置环境变量:

另见:

于 2015-12-25T14:50:26.013 回答
2

是的,无论谁制作了 webdriver-manager,都做了太多的假设......:S

在我的机器上找到 webdriver-manager\built\lib\cmds\start.js

C:\Users\XYZ\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\built\lib\cmds\start.js

找到以开头的行

var seleniumProcess = spawnCommand

将该行和前一行替换为

logger.info(process.env.JAVA_HOME+'\\bin\\java.exe' + argsToString);
var seleniumProcess = spawnCommand(process.env.JAVA_HOME+'\\bin\\java.exe', args);

设置你的 JAVA_HOME 就可以了。

如果您不知道如何设置 JAVA_HOME,请执行以下操作:

以管理员权限运行命令提示符 (cmd.exe),然后运行

dir c:\java.exe /s/a/b

一段时间后,您将获得至少一行文本,例如

C:\Dev\Java\JDK\jre\bin\java.exe

如果没有文本行,则 C 驱动器上没有 java。:( 重复其他字母或安装 Java JRE。

选择任何这些文本行。您的 java_home 是除 bin\java.exe之外的那一行文本。要设置它,就我而言,我会这样做:

setx /m JAVA_HOME C:\Dev\Java\JDK\jre\

setx 将在机器范围内永久设置 JAVA_HOME。如果要为当前用户永久设置 JAVA_HOME,请删除 /m 参数。如果您想临时设置 JAVA_HOME,请仅针对打开的“命令提示符”窗口执行以下操作:

set JAVA_HOME=C:\Dev\Java\JDK\jre\

祝你好运。

于 2016-09-22T15:36:42.363 回答
1

I ran the command

webdriver-manager start

and got the above error messages.

Then followed David C instructions for this question and it finally worked. But before that, I had to install the JDK as well. Here are the complete steps.

  1. I searched for install java jdk windows 10 64 bit and ended up on this Java JDK Installation.

  2. Scrolled a bit and clicked on JDK Installation Instructions for Windows

  3. As per the instructions there, again went hunting for Java SE Development Kit 10 Downloads and ended up on Java SE Development Kit 13 Downloads page. That seems to be the latest as of now

  4. Downloaded the Windows x64 Installer. The file name looked like this jdk-13.0.2_windows-x64_bin.exe. 13 seems to be the latest.

  5. On my machine, took a look at C:\Program Files\Java. This JAVA folder is not yet present.

  6. Run the exe downloaded with admin privliages.

  7. Ensure that java is installed by peeking at C:\Program Files\Java. I have got a folder inside that as C:\Program Files\Java\jdk-13.0.2.

  8. Now followed David C's instructions. Opened up a command prompt and ran

    dir c:\java.exe /s/a/b 
    

    Confirmed that my path is c:\Program Files\Java\jdk-13.0.2\bin\java.exe

  9. Now I run, in the same admin command prompt,

    setx /m JAVA_HOME "c:\Program Files\Java\jdk-13.0.2"
    
    setx JAVA_HOME "c:\Program Files\Java\jdk-13.0.2"
    
  10. Finally caught hold of start.js. Mine is located at C:\Users\XYX\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\built\lib\cmds

  11. Commented the following lines

    //logger.info('java' + argsToString);
    //let seleniumProcess = utils_1.spawn('java', args, stdio);`
    

    and replaced them with

    logger.info(process.env.JAVA_HOME+'\\bin\\java.exe' + argsToString);
    let seleniumProcess = utils_1.spawn(process.env.JAVA_HOME+'\\bin\\java.exe', args, stdio); 
    
  12. Now ran the command

    webdriver-manager start
    

    Finally got it. - Selenium Server is up and running on port 4444

Such a pain going through all of these steps.

于 2020-03-14T02:55:31.657 回答