Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't start webdriver-manager after upgrading of jdk, node & webdriver

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>
like image 932
Idan E Avatar asked Dec 25 '15 11:12

Idan E


3 Answers

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

  • How to set java_home on Windows 7?

Also see:

  • 'Java' is not recognized as an internal or external command
like image 103
alecxe Avatar answered Oct 31 '22 15:10

alecxe


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.

like image 39
David C Avatar answered Oct 31 '22 14:10

David C


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.

like image 1
VivekDev Avatar answered Oct 31 '22 15:10

VivekDev