0
votes

I want to run my Selenium test using selenium grid. For that I have setup the hub on my local machine (Ubuntu) and node on the Centos VM. I have run the following commands:

  1. java -jar selenium-server-standalone-3.141.59.jar -role hub (on local machine )
  2. java -Dwebdriver.chrome.driver="/usr/bin/chromedriver" -jar selenium-server-standalone-3.141.59.jar -role node -hub http://hubipaddress:4444/grid/register

Both work fine and node also setup successfully and I can also be verified from console.

Code snipet

          DesiredCapabilities cap1=new DesiredCapabilities();
          String hubURL = "http://10.242.2.6:4444/wd/hub";
          cap1.setBrowserName(browser);
          ChromeOptions option=new ChromeOptions();
          option.addArguments("--headless","--no-sandbox");
          option.merge(cap1);
          driver=new RemoteWebDriver(new URL(hubURL),option);
          driver.get("http://practice.automationtesting.in/my-account/");
          driver.findElement(By.id("username")).sendKeys("pavanoltraining");
          driver.findElement(By.id("password")).sendKeys("Test@selenium123");
          driver.findElement(By.name("login")).click();

Now when I run my test script from local machine,after few seconds I got this error

11:43:08.894 INFO [RequestHandler.process] - Error forwarding the new session Error forwarding the request Failed to connect to /**nodeIpAddress**:22956
org.openqa.grid.internal.exception.NewSessionException: Error forwarding the request Failed to connect to /**nodeIpAddress**:22956
    at org.openqa.grid.web.servlet.handler.RequestHandler.forwardNewSessionRequestAndUpdateRegistry(RequestHandler.java:94)
    at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:114)
    at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:85)
    at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:69)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:865)
    at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
    at org.seleniumhq.jetty9.security.SecurityHandler.handle(SecurityHandler.java:548)
    at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
    at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
    at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
    at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
    at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
    at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
    at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
    at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.seleniumhq.jetty9.server.Server.handle(Server.java:503)
    at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:364)
    at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:260)
    at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
    at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:103)
    at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
    at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
    at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
    at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
    at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
    at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
    at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
    at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.ConnectException: Failed to connect to /172.17.0.1:22956
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
    at org.openqa.grid.internal.TestSession.sendRequestToNode(TestSession.java:422)
    at org.openqa.grid.internal.TestSession.forward(TestSession.java:229)
    at org.openqa.grid.web.servlet.handler.RequestHandler.forwardNewSessionRequestAndUpdateRegistry(RequestHandler.java:91)
    ... 35 more
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.base/java.net.Socket.connect(Socket.java:609)
    at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129)
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245)

I have tried all the possible solutions but was not able to figure out the problem.

1
"I have tried all the possible solutions"... we need to know what you tried and the result so we don't suggest something you've already tried. Edit your question and add those details. - JeffC

1 Answers

0
votes

Try this:

            private WebDriver driver;
            private ChromeOptions chromeOptions;
            private DesiredCapabilities caps;
            // Test on VM
            private final String URL = "http://10.242.2.6:4444/wd/hub";
            ChromeOptions options = new ChromeOptions();
            options.addArguments("--headless");
            options.setCapability(CapabilityType.BROWSER_NAME, "chrome");
            options.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);
            options.addArguments("Proxy", "null");
            options.setExperimentalOption("useAutomationExtension", false);
            options.addArguments("--disable-dev-shm-usage");
            options.addArguments("--no-sandbox");
            options.addArguments("window-size=1920,1080");
            options.addArguments("--disable-gpu");
            options.addArguments("start-maximized");
            options.addArguments("--allow-insecure-localhost");
            options.addArguments("--ignore-certificate-errors");
            System.out.println(options);
            driver = new RemoteWebDriver(new URL(URL), options);
            driver.manage().window().fullscreen();

I tested and this works for me. If you in fact have the node connected to the Hub and you see that in the console, then this should work.