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