5

I've upgraded Node, Protractor, JDK & webdriver to the latest versions. And now I can't start webdriver-manager anymore not by CMD and not by Node command line.

Any idea?

Error: Your environment has been set up for using Node.js 0.12.2 (x64) and 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>
cnishina
  • 5,016
  • 1
  • 23
  • 40
Idan E
  • 1,299
  • 4
  • 17
  • 42
  • What are your selenium-webdriver, protractor, and node versions? Can you update that in your question? Also your java is not available from the command line. Probably setting the global environment path might help. Thanks – giri-sh Dec 25 '15 at 12:30

3 Answers3

2

You need to have jdk installed and JAVA_HOME environment variable set:

Also see:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
2

Yeah whoever made webdriver-manager, made too many assumptions... :S

Find webdriver-manager\built\lib\cmds\start.js On my machine it's

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

Find the line that starts with

var seleniumProcess = spawnCommand

replace that line and the preceding line with

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

Set your JAVA_HOME and you're set.

If you don't know how to set your JAVA_HOME, do this:

Run Command Prompt (cmd.exe) with admin privileges and then run

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

After a while, you will get at least one line of text such as

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

If you get no text lines you don't have java on C drive. :( Repeat for other letters or install a Java JRE.

Pick any of those lines of text. Your java_home is that line of text except bin\java.exe. To set it, in my case I would do:

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

setx will set JAVA_HOME permanently machine-wide. If you want to set JAVA_HOME permanently for the current user remove the /m parameter. If you want to set JAVA_HOME temporarily, only for that opened "Command Prompt" window do this:

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

Good luck.

David C
  • 21
  • 3
  • Thank you, David, to point out where webdriver-manager pick up the java and start the selenium server. Based on it, I modified my start.js under "%appdata%\npm\node_modules\webdriver-manager\built\lib\cmds\" with the following change: var myJava = 'C:\\java\\jdk1.8.0_111\\bin\\java.exe'; var seleniumProcess = spawnCommand(myJava, args); so that I can avoid to switch the value of JAVA_HOME environment since there are other java project using JDK that is not JDK 8 (Selenium need jdk 8) – TianCaiBenBen Dec 16 '16 at 23:44
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.

VivekDev
  • 20,868
  • 27
  • 132
  • 202