-1

I am learning Selenium Grid and beginner for it.I setup my hub by using command:- java -jar selenium-server-standalone-3.3.0.jar -role hub and node is setup by using command:- java -jar selenium-server-standalone-3.3.0.jar -role webdriver -hub IP_of_hub:4444/grid/register -port 1234

Than i created a java project and created a class and write the down the code

import junit.framework.Assert;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.xerces.util.URI.MalformedURIException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

    public class selGrid {

        WebDriver driver;
        String base_url,node_url;

        @BeforeTest
        public void setUp() throws MalformedURLException{
            System.setProperty("webdriver.gecko.driver","C://Users//Administrator//Downloads//geckodriver.exe");
            base_url="http://newtours.demoaut.com";
            node_url="http://localhost:1234/wd/hub";
            DesiredCapabilities capability=DesiredCapabilities.firefox();
            capability.setBrowserName("firefox");
            capability.setPlatform(Platform.WINDOWS);

            driver=new RemoteWebDriver(new URL(node_url),capability);
        }
        @AfterTest
        public void afterTest()
        {
            driver.quit();
        }
         public void simpleTest()
        {
            driver.get(base_url);
            Assert.assertEquals("Welcome", driver.getTitle());
        }


      }}

And run it is as TestNGand in the console below text is showing

FAILED CONFIGURATION: @BeforeTest setUp  org.openqa.selenium.SessionNotCreatedException: Unable to create new remote   session. desired capabilities = Capabilities [{marionette=true,    browserName=firefox, moz:firefoxOptions=  {binary=Optional[FirefoxBinary(C:\Program Files (x86)\Mozilla   Firefox\firefox.exe)], args=[], legacy=null, logLevel=null, prefs={},   profile=null}, version=, platform=WINDOWS}], required capabilities =   Capabilities [{}]
  Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
  System info: host: 'UNO-13-PC', ip: '192.168.0.4', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
  Driver info: driver.version: FirefoxDriver
 Command duration or timeout: 0 milliseconds
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:363)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:113)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
at selGrid.setUp(selGrid.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.TestRunner.beforeRun(TestRunner.java:626)
at org.testng.TestRunner.run(TestRunner.java:594)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create   new remote session. desired capabilities = Capabilities [{marionette=true,  browserName=firefox, moz:firefoxOptions= {binary=Optional[FirefoxBinary(C:\Program Files (x86)\Mozilla  Firefox\firefox.exe)], args=[], legacy=null, logLevel=null, prefs={},  profile=null}, version=, platform=WINDOWS}], required capabilities =  Capabilities [{}]
   Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
        System info: host: 'UNO-13-PC', ip: '192.168.0.4', os.name: 'Windows 7',   os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
    Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07   11:21:31 -0800'
System info: host: 'UNO-13-PC', ip: '192.168.0.4', os.name: 'Windows 7',   os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
          Driver info: driver.version: FirefoxDriver
       at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:243)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:164)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

 SKIPPED CONFIGURATION: @AfterTest afterTest

 ===============================================
 Default test
 Tests run: 0, Failures: 0, Skips: 0
 Configuration Failures: 1, Skips: 1
 ===============================================


 ===============================================
 Default suite
 Total tests run: 0, Failures: 0, Skips: 0
 Configuration Failures: 1, Skips: 1
 ===============================================
  • Did you set the path to the driver, like the stack trace suggests ? – Tim Apr 03 '17 at 10:44
  • Read this: http://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr – Tim Apr 03 '17 at 10:47
  • @Tim i set the path, now Firefox is opening but to next process it is not proceeding Thanks for help. – Priti Andhale Apr 03 '17 at 11:43
  • Well, you did not post your actual @Test code. Also, before using the grid right away, you should try to make your test work locally. Then only should you try to run it on the grid. – Tim Apr 03 '17 at 11:47
  • only this part of code is commented @Test public void simpleTest() { driver.get(base_url); Assert.assertEquals("Welcome", driver.getTitle()); } – Priti Andhale Apr 03 '17 at 11:53
  • You should edit your question with this code. Also, when / where do you set the actual URL ? What error message do you get ? – Tim Apr 03 '17 at 11:56
  • But i am facing issue FAILED CONFIGURATION: @BeforeTest setUp org.openqa.selenium.SessionNotCreatedException: Unable to create new remote sessoion. – Priti Andhale Apr 03 '17 at 11:57
  • You should update your question with the current stack trace. Did you register your node to the hub ? (Are those running on the same machine ?) I find your code a bit confusing: Shouldn't "node_url" be called "hub_url" ? Also, each node needs the driver. – Tim Apr 03 '17 at 12:04
  • @Tim I updated question. I register my node to hub.Both node and hub are on same machine( IP of machine is replaced by localhost). – Priti Andhale Apr 03 '17 at 12:22
  • Does your test work locally ? (without the Grid configuration) – Tim Apr 03 '17 at 12:36
  • @Tim I resolved issue it is firefox version issue. Thank you for suggesting me the path set – Priti Andhale Apr 03 '17 at 12:52
  • In that case, you should answer your own question and accept it, so others know. If you think your solution can prevent others from having to ask a new question, be as precise as you can :) – Tim Apr 03 '17 at 13:03

1 Answers1

1

Set the path of geckodriver and use the latest version of firefox(or one can check compatible firefox for standalone server). Now I used firefox ver 52.0.2 and standalone server is 3.3.0