0

I am trying a POC on selenium grid with Cucumber. I am receiving this error: Error forwarding the new session Empty pool of VM for setup Capabilities

Here is my sample Code:

public static void configureServer() {

    GridHubConfiguration gridHubConfig = new GridHubConfiguration();
    //gridHubConfig.role = "hub";
    gridHubConfig.host = "127.0.0.1";
    gridHubConfig.port = 4444;
    gridHubConfig.newSessionWaitTimeout = 150000;
    Hub myHub = new Hub(gridHubConfig);
    myHub.start();

    GridNodeConfiguration gridNodeConfig = new GridNodeConfiguration();
    gridNodeConfig.hub = "http://127.0.0.1:4444/grid/register";
    gridNodeConfig.host = "xxxx"; //my ip address
    gridNodeConfig.port = 5566;
    gridNodeConfig.role = "webdriver";
    RegistrationRequest req = RegistrationRequest.build(gridNodeConfig);
    req.getConfiguration();
    req.validate();
    RegistrationRequest.build(gridNodeConfig);

    SelfRegisteringRemote remote = new SelfRegisteringRemote(req);
    remote.setRemoteServer(new SeleniumServer(gridNodeConfig));
    remote.startRemoteServer();
    remote.startRegistrationProcess();

    System.out.println("Node Registered to Hub..............");
}

Capabilities:

        capabilities.setBrowserName("chrome");
        capabilities.setPlatform(Platform.MOJAVE);
        capabilities.setVersion("91.0.4472.114");
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

Driver Initialization:

            HubNodeConfiguration.configureServer();
            System.setProperty("webdriver.chrome.driver","xxx/chromedriver");
            threadLocalDriver.set(new RemoteWebDriver(new URL("http://localhost:9090 
            /wd/hub"),capabilities));
             

Have tried and followed the answer provided here (Selenium Grid +Error forwarding the new session Empty pool of VM for setup Capabilities) but with no luck

For detailed code please refer to my Git Repo : https://github.com/rkhanna1401/cucumber_selenium_grid

1 Answer 1

0

There are multiple problems with your code. In a nutshell, you are hardcoding a lot of the OS platform information only in your Desired Capabilities object that you are using to create the WebDriver but the Grid Hub is not having those changes.

I also noticed that your code base is trying to talk to a hub running in a different port but your hub is running in a different port.

I also noticed that your test code is not waiting for the Node to be registered to the hub. I have as a quick hack added a sleep to facilitate that, but you can employ sophisticated mechanisms such as polling the hub to see if the node is registered or not etc.,

You need to create a patch file with the below git diff contents and then you can apply it to your codebase.

Here's a git diff that you can apply to your project to fix the problem

From 7d718cea160e7feac2fab8526f8578553d697426 Mon Sep 17 00:00:00 2001
From: Krishnan Mahadevan <Krishnan.Mahadevan>
Date: Sat, 26 Jun 2021 19:46:33 +0530
Subject: [PATCH] Changes needed

---
 .../java/WebdriverBase/GridDriverManager.java     | 15 +++++----------
 .../java/WebdriverBase/HubNodeConfiguration.java  | 12 +++++++++---
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/main/java/WebdriverBase/GridDriverManager.java b/src/main/java/WebdriverBase/GridDriverManager.java
index 58a8052..4102ac3 100644
--- a/src/main/java/WebdriverBase/GridDriverManager.java
+++ b/src/main/java/WebdriverBase/GridDriverManager.java
@@ -96,7 +96,7 @@ public class GridDriverManager {
        }
        if (browserType.equalsIgnoreCase("Chrome")) {
            try {
-               System.setProperty("webdriver.chrome.driver","/Users/rishikhanna/Documents/cucumber/shopping/Driver/chromedriver");
+//             System.setProperty("webdriver.chrome.driver","/Users/rishikhanna/Documents/cucumber/shopping/Driver/chromedriver");
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -112,9 +112,8 @@ public class GridDriverManager {
 //            chromePrefs.put("profile.default_content_settings.popups", 0);
 //            ChromeOptions options = new ChromeOptions();
 //            options.setExperimentalOption("prefs", chromePrefs);
-            capabilities.setBrowserName("chrome");
-            capabilities.setPlatform(Platform.MOJAVE);
-            capabilities.setVersion("91.0.4472.114");
+
+            capabilities.merge(DesiredCapabilities.chrome());
             capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
           //  capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        }
@@ -130,9 +129,6 @@ public class GridDriverManager {
        if (platformType.equalsIgnoreCase("WINDOWS")) {
            capabilities.setPlatform(Platform.WINDOWS);
        }
-       if (platformType.equalsIgnoreCase("MAC")) {
-           capabilities.setPlatform(Platform.MOJAVE);
-       }
 
        //capabilities.setVersion(getValFromJson(jsonObject,"version"));
        return capabilities;
@@ -149,7 +145,7 @@ public class GridDriverManager {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
-       setDriver("chrome", "WINDOWS");
+       setDriver("chrome", "MAC");
        return threadLocalDriver.get();
    }
 
@@ -159,8 +155,7 @@ public class GridDriverManager {
        {
            try {
                HubNodeConfiguration.configureServer();
-               System.setProperty("webdriver.chrome.driver","/Users/rishikhanna/Documents/cucumber/shopping/Driver/chromedriver");
-               threadLocalDriver.set(new RemoteWebDriver(new URL("http://localhost:9090/wd/hub"),capabilities));
+               threadLocalDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capabilities));
                threadLocalDriver.get().manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
            } catch (MalformedURLException e) {
                e.printStackTrace();
diff --git a/src/main/java/WebdriverBase/HubNodeConfiguration.java b/src/main/java/WebdriverBase/HubNodeConfiguration.java
index 174b216..2725bba 100644
--- a/src/main/java/WebdriverBase/HubNodeConfiguration.java
+++ b/src/main/java/WebdriverBase/HubNodeConfiguration.java
@@ -4,6 +4,7 @@ import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 
+import java.util.concurrent.TimeUnit;
 import org.openqa.grid.common.GridRole;
 import org.openqa.grid.common.RegistrationRequest;
 import org.openqa.grid.internal.utils.SelfRegisteringRemote;
@@ -30,10 +31,10 @@ public class HubNodeConfiguration {
        myHub.start();
 
        GridNodeConfiguration gridNodeConfig = new GridNodeConfiguration();
-       gridNodeConfig.hub = "http://127.0.0.1:4444/grid/register";
-       gridNodeConfig.host = "xxxx"; //my ip address
+       gridNodeConfig.hub = "http://localhost:4444";
+       gridNodeConfig.host = "localhost"; //my ip address
        gridNodeConfig.port = 5566;
-       gridNodeConfig.role = "webdriver";
+       gridNodeConfig.role = "node";
        RegistrationRequest req = RegistrationRequest.build(gridNodeConfig);
        req.getConfiguration();
        req.validate();
@@ -44,6 +45,11 @@ public class HubNodeConfiguration {
        remote.startRemoteServer();
        remote.startRegistrationProcess();
 
+       try {
+           TimeUnit.SECONDS.sleep(10);
+       } catch (InterruptedException e) {
+           e.printStackTrace();
+       }
        System.out.println("Node Registered to Hub..............");
    }
 }
-- 
2.24.3 (Apple Git-128)+GitX
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! Yes even I figured out the same issues and have updated the code base accordingly... if you wish you can re-visit my repo and have a look again and suggest if any....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.