0

Below is my code which I am using to pass browser, node and hub port to launch browser and execute the tests but i get exception although I am able to set up selenium server. I paste error below of the code too. I use mac book, Selenium 3.4, Firefox 55 and Gecko 0.18.0

public synchronized WebDriver setUp(String browser, String 
nodePort, String hubPort) throws MalformedURLException{

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.MAC);
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(ForSeleniumServer.PROXYING_EVERYTHING, 
true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, 
true);

if(browser.equals("firefox"))
    System.setProperty("webdriver.gecko.driver", 
System.getProperty("user.dir")+"//geckoDriver//geckodriver");
else if(browser.equals("chrome"))
    System.setProperty("webdriver.chrome.driver", 
System.getProperty("user.dir")+"//chromeDriver//chromeDriver");
driver = new RemoteWebDriver(new 
URL("http://localhost:"+nodePort+"/wd/hub"), capabilities);
driver.get("https://www.bookbaby.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
System.out.println(driver.toString());
return driver;

Error is

org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases Command duration or timeout: 1.41 seconds Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'Refaques-MacBook-Pro.local', ip: '192.168.108.206', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144' Driver info: driver.version: Driver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167) at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53) at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91) at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$22(ProtocolHandshake.java:365) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:137) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:174) at com.bookbaby.driver.Driver.setUp(Driver.java:55) at com.bookbaby.executor.RunCukesByFeatureForFirefox.setUpClass(RunCukesByFeatureForFirefox.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) at org.testng.TestRunner.privateRun(TestRunner.java:782) at org.testng.TestRunner.run(TestRunner.java:632) at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) at org.testng.SuiteRunner.access$000(SuiteRunner.java:39) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:400) at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:137) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:81) at org.openqa.selenium.remote.server.FirefoxDriverProvider.newInstance(FirefoxDriverProvider.java:63) at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60) at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222) at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:209) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176) ... 3 more

Below is my log from command prompt

13:25:14.249 INFO - Selenium build 
info: version: '3.4.0', revision: 'unknown'
13:25:14.249 INFO - Launching a Selenium Grid node
2017-09-12 13:25:14.814:INFO::main: Logging initialized @833ms to 
org.seleniumhq.jetty9.util.log.StdErrLog
13:25:14.864 INFO - Driver provider 
org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{ensureCleanSession=true, 
browserName=internet explorer, version=, platform=WINDOWS}] does not 
match the current platform MAC
13:25:14.864 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver 
registration is skipped:
registration capabilities Capabilities [{browserName=MicrosoftEdge, 
version=, platform=WINDOWS}] does not match the current platform MAC
13:25:14.864 INFO - Driver class not found: 
com.opera.core.systems.OperaDriver
13:25:14.864 INFO - Driver provider com.opera.core.systems.OperaDriver 
registration is skipped:
 Unable to create new instances on this machine.
13:25:14.865 INFO - Driver class not found: 
com.opera.core.systems.OperaDriver
13:25:14.865 INFO - Driver provider com.opera.core.systems.OperaDriver 
is not registered
2017-09-12 13:25:14.899:INFO:osjs.Server:main: jetty-9.4.3.v20170317
2017-09-12 13:25:14.938:INFO:osjsh.ContextHandler:main: Started 
o.s.j.s.ServletContextHandler@e056f20{/,null,AVAILABLE}
2017-09-12 13:25:14.963:INFO:osjs.AbstractConnector:main: Started 
ServerConnector@39529185{HTTP/1.1,[http/1.1]}{0.0.0.0:5556}
2017-09-12 13:25:14.963:INFO:osjs.Server:main: Started @982ms
13:25:14.963 INFO - Selenium Grid node is up and ready to register to 
the hub
13:25:14.983 INFO - Starting auto registration thread. Will try to 
register every 5000 ms.
13:25:14.983 INFO - Registering the node to the hub: 
http://localhost:4445/grid/register
13:25:15.044 INFO - The node is registered to the hub and ready to use
13:25:20.205 INFO - SessionCleaner initialized with 
 insideBrowserTimeout 0 and clientGoneTimeout 1800000 polling every 
180000
13:26:11.724 INFO - Executing: [new session: Capabilities 
[{proxyEverything=true, acceptSslCerts=true, marionette=true, 
acceptInsecureCerts=true, browserName=firefox, javascriptEnabled=true, 
handlesAlerts=true, version=, platform=MAC}]])
13:26:11.738 INFO - Creating a new session for Capabilities 
[{proxyEverything=true, acceptSslCerts=true, marionette=true, 
acceptInsecureCerts=true, browserName=firefox, javascriptEnabled=true, 
handlesAlerts=true, version=, platform=MAC}]
13:26:11.770 WARN - Exception thrown
java.util.concurrent.ExecutionException: 
org.openqa.selenium.WebDriverException: 
java.lang.reflect.InvocationTargetException
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'XXXXXX-MacBook-Pro.local', ip: '192.168.108.206', 
os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', 
java.version: '1.8.0_144'
Driver info: driver.version: unknown

13:26:11.777 WARN - Exception: The path to the driver executable must 
be set by the webdriver.gecko.driver system property; for more 
information, see https://github.com/mozilla/geckodriver. The latest 
version can be downloaded from 
https://github.com/mozilla/geckodriver/releases
slavoo
  • 5,798
  • 64
  • 37
  • 39
Ref
  • 27
  • 1
  • 8

2 Answers2

0

please set environment variable webdriver.gecko.driver in your machine and its value.

or you can pass the parameter webdriver.gecko.driver while starting your hub or registering your node. like

java -Dwebdriver.gecko.driver="path to the gecko driver" {jar} -role node/hub
Murthi
  • 5,299
  • 1
  • 10
  • 15
  • the way i set up wont work?System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"//geckoDriver//geckodriver"); – Ref Sep 12 '17 at 13:48
  • it will not work if you are executing on selenium grid. it will work without grid. – Murthi Sep 12 '17 at 13:50
0

Firstly say the issue in your code, if you want to use the selenium server/grid please specify the webdriver path in command line when start selenium server,rather than specify by code.
so below code is unnecessary, they are only necessary when you choose run test not using selenium server/grid, we call it 'directConnect' (your script communicate directly with webdriver.exe)

if(browser.equals("firefox"))
        System.setProperty("webdriver.gecko.driver", 
    System.getProperty("user.dir")+"//geckoDriver//geckodriver");
    else if(browser.equals("chrome"))
        System.setProperty("webdriver.chrome.driver", 
    System.getProperty("user.dir")+"//chromeDriver//chromeDriver");

register node to hub argument example to specify webdriver.exe path:

java
-Dwebdriver.chrome.driver=C:\selenium\chromedriver_2.32.exe 
-Dwebdriver.gecko.driver=C:\selenium\geckodriver-v0.18.0.exe 
-jar C:\selenium\selenium-server-standalone-3.4.0.jar 
-role node
-port 4446

Reminder: please check the standalone.jar, specified webdriver.exe and browser on node are compatible with each other, otherwise the node will fail to launch browser in testing.

yong
  • 13,357
  • 1
  • 16
  • 27
  • Thanks for your help. Now I run this command and works for firefox but not for chrome,any idea . java -Dwebdriver.chrome.driver=Users/username/chromeDriver/chromedriver -Dwebdriver.gecko.driver=/Users/username/gecko_driver/geckodriver -jar /Users/username/selenium-server/selenium-server-standalone-3.5.3.jar -role node -port "+nodePort+" -hub http://localhost:"+hubPort+"/grid/register – Ref Sep 12 '17 at 16:02
  • please check the chromedriver compatibel with your chrome browser, my chrome version is 60 and chromedriver is 2.30 – yong Sep 12 '17 at 16:06