27

I'm trying to run selenium server, and get errors:

rond-macpro:selenium eladb$  java -Dwebdriver.chrome.driver=./chromedriver -r selenium-server-standalone-2.44.0.jar
Unrecognized option: -r
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

and without -r (what is it anyway?)

rond-macpro:selenium eladb$  java -Dwebdriver.chrome.driver=./chromedriver  selenium-server-standalone-2.44.0.jar
Error: Could not find or load main class selenium-server-standalone-2.44.0.jar

how should I start the server?

how do I set a non-default port to listen to?

These two posts: 1 2 - contradicts regarding the syntax. I think.

Community
  • 1
  • 1
Elad Benda
  • 35,076
  • 87
  • 265
  • 471

6 Answers6

36
java -jar seleniumjar.jar -Dwebdriver.chrome.driver=./chromedriver 

If you want to specifiy the port do

java -jar seleniumjar.version.jar -Dwebdriver.chrome.driver=./chromedriver -port 4545

As of 3.8.1, specifying the driver is no longer necessary:

java -jar seleniumjar.jar
Cory Klein
  • 51,188
  • 43
  • 183
  • 243
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • how come your cmd doesn't include main class path? – Elad Benda Mar 04 '15 at 12:15
  • @EladBenda I am sorry. Please clarify more – Saifur Mar 04 '15 at 12:16
  • for java in general, if the jar includes only one main class, we don't have to write its name in the `java -jar cmd`? – Elad Benda Mar 04 '15 at 12:19
  • 1
    Ooh gotcha. This is how `seleniumHQ` actually suggest to run this. Never wanted to dig into how it works internally – Saifur Mar 04 '15 at 12:21
  • Just FYI if order of args in answer crashes, try to switch the order: driver first, then jar. Such order solved it for me as suggested by https://stackoverflow.com/questions/42032960/unknown-option-dwebdriver-chrome-driver-when-running-selenium-server-standalon – Peter M. - stands for Monica May 26 '17 at 21:40
  • Does not work for standalone driver 3.4, the option "webdriver.chrome.driver" is not known. – rocksportrocker Jun 01 '17 at 14:23
  • @rocksportrocker I need to test that. That should not break though – Saifur Jun 01 '17 at 22:00
  • how can i use GhostDriver (PhantomJS) instead of ChromeDriver? – Dee Aug 31 '17 at 09:30
  • 1
    @johnlowvale you would need to register the node after the server is up. But please note ghost driver and PhantomJs is no longer being maintained at this time. *** phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444 *** – GetBackerZ Mar 23 '18 at 16:34
15

Running Standalone Selenium Server:

Form Jar Source Main-Class is org.openqa.grid.selenium.GridLauncher

As per GridRole class - Selenium server can run in one of the following roles:

  1. NOT_GRID [If -role option is omitted the server runs standalone not being a part of a grid]>
  2. HUB [as a hub of a Selenium grid]
  3. NODE [as a node of a Selenium grid]
D:\> java -jar selenium-server-standalone-*.jar -host 127.0.0.1 -port 4444

NOT GRID

Selenium Remote Control (RC) requires server to be started before executing the test scripts. RC server injects Selenium core (JavaScript) into the browser. The core (daemon process) receives commands from the server by your test scripts and executes them in a browser then results to your program. But cannot handle moving mouse cursors & mobile execution.

Java Client Driver: Client-Configures your browser to use the Selenium Server as an HTTP proxy and passes browser commands to server through "/selenium-server/RemoteRunner.html?sessionId=1234", clients may send Driver Command requests to selenium server over HTTP as follows:

Code & Requests: RC Server continuously runs. we create a daemon and from that communicate with the browser.

Selenium daemon = new DefaultSelenium("172.16.20.156", 4464, "*firefox", "https://www.google.co.in/");
daemon.start(); -- daemon.stop(); (OR)
setUp("http://www.google.com/", "*firefox", 4454); selenium.windowMaximize();

GET:http://localhost:4454/selenium-server/driver/?cmd=open&1=https://www.google.co.in/&sessionId=9b1a232d9478497892e09cfc93cf665a
  • RC(WebDriverinterface)- IP:Port/wd/hub/static/resource/hub.html:

RWD Code & Requests:

WebDriver nativeDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4454/wd/hub"), DesiredCapabilities.firefox());

Requests:
http://127.0.0.1:4454/wd/hub/session
    /123...[SESSIONID]
        /url
        { "url" : "http://demo.opencart.com/index.php?route=account/login" }


        /execute
        { "script" : "document.querySelectorAll( arguments[0] )[0].click();", "args" : ['input.btn'] }

Grid: [ - IP:Port/grid/console]

HUB Grid HUB Running as a standalone server: Hub is a central point which distributing tests on several node-machines, which are registered to it for parallel execution.

java -jar selenium-server-standalone-2.53.0.jar -host 127.0.0.1 -port 4454 -role hub -log "D:\\HUB_Log.txt"

NODE [RC] has to post a request to HUB in order to register with it, by this URL - IP:Port//grid/register.

java -jar selenium-server-standalone-2.53.0.jar -host 127.0.0.1 -port 4458 -role node 
-hub http://127.0.0.1:4454/grid/register -hubHost 127.0.0.1 -hubPort 4454 
-browser browserName=firefox,version=24.0, maxinstance=1,platform=WINDOWS7 
-browser  browserName=chrome,version=53.0,platform=WINDOWS 
-Dwebdriver.chrome.driver=D:\\Drivers\\chromedrivers\\2.24\\chromedriver.exe

Running as a grid node: browser Instance INFO: browserName=chrome, version=53.0, maxinstance=1, platform=WINDOWS Command Line parameters with System Property values -Dproperty=value -Dchrome=driverAddress (If value is a string that contains spaces, you must enclose the string in double quotes)

Node registration with a JSON configuration file registerNode.json.

D:\SeleniumJar_Source>java -jar selenium-server-standalone-2.53.0.jar -role node 
-hub http://127.0.0.1:4454/grid/register 
-nodeConfig registerNode.json 
-Dwebdriver.chrome.driver="D:\\Drivers\\chromedrivers\\2.24\\chromedriver.exe" 
-Dwebdriver.ie.driver="D:\\Drivers\\IEDrivers\\iedriver64\\IEDriverServer.exe" 
-Dwebdriver.firefox.logfile="D:\\FirefoxInstance.txt" 
-Dwebdriver.chrome.logfile="D:\\ChromeInstance.txt" 
-Dwebdriver.ie.logfile="D:\\IEInstance.txt"

WebDriver doesn't require any server start before start execution. You can see that WebDriver acts just as a normal Java library does: it's entirely self-contained, and you don't need to remember to start any additional processes or run any installers before using it.

WebDriver driver = new FirefoxDriver();

Selenium Server

@see

Yash
  • 9,250
  • 2
  • 69
  • 74
6
java -jar selenium-server-standalone-2.44.0.jar -port port_no
eebbesen
  • 5,070
  • 8
  • 48
  • 70
Giri
  • 411
  • 2
  • 18
3

I would like to add more webdrivers to @Saifur answer. https://stackoverflow.com/a/28854250/4587961

java   -Dwebdriver.ie.driver=./IEDriverServer32.exe -Dwebdriver.chrome.driver=./chromedriver.exe -jar selenium.jar -port 4545

Note, for IE you run 32 bit version of the driver. And it works. I created a bat file and put it inside of the selenium folder where I also put drivers.

Yan Khonski
  • 12,225
  • 15
  • 76
  • 114
1

If you are using Selenium >= 4.6 use

java -jar selenium-server-<version>.jar standalone

See this page for further instructions

https://www.selenium.dev/documentation/grid/getting_started/

Wolfgang Blessen
  • 900
  • 10
  • 29
0

One should first specify the driver part then the selenium jar :

java -Dwebdriver.chrome.driver=./chromedriver -jar selenium-server-standalone-3.141.59.jar

This worked for Ubuntu 18.04