Selenium Node doesnt parse hub configurations properly when you have custom capability matcher
Meta -
OS: Linux
Selenium Version:
3.0.1
Browser:
Chrome
Browser Version:
55.0.2883.87
Expected Behavior -
Selenium Node Should be able to parse the hub config irrespective of capabilities
Actual Behavior -
Timeout from hub not honored as parsing the hub config emits below warning
00:03:36.450 WARN - error getting the parameters from the hub. The node may end up with wrong timeouts.Error with the JSON of the config : String io .sterodium.extensions.capability.CustomCapabilityMatcher could not be coerced to class: java.lang.Class
Steps to reproduce -
hub json
{
"success": true,
"capabilityMatcher": "io.sterodium.extensions.capability.CustomCapabilityMatcher",
"newSessionWaitTimeout": -1,
"throwOnCapabilityNotPresent": true,
"cleanUpCycle": 5000,
"custom": {},
"host": "10.0.9.2",
"maxSession": 50,
"servlets": ["io.sterodium.extensions.hub.proxy.HubRequestsProxyingServlet", "com.ariba.es.ai.hub.proxy.servlets.SeleniumApiProxyServlet"],
"browserTimeout": 0,
"debug": false,
"jettyMaxThreads": -1,
"log": "log/hub_7777.log",
"port": 7777,
"role": "hub",
"timeout": 300000,
"newSessionRequestCount": 0,
"slotCounts": {
"free": 1,
"total": 1
}
}
Node JSON
{
"capabilities": [
{
"seleniumProtocol": "WebDriver",
"extension.sikuliCapability": true,
"browserName": "firefox",
"maxInstances": 1,
"version": "50.0",
"platform": "MAC"
},
{
"seleniumProtocol": "WebDriver",
"extension.sikuliCapability": true,
"browserName": "chrome",
"maxInstances": 1,
"version": "55.0.2883.87",
"platform": "MAC"
}
],
"loadedFromFile": "node_5555.json",
"proxy": "com.groupon.seleniumgridextras.grid.proxies.SetupTeardownProxy",
"maxSession": 1,
"port": 5555,
"register": true,
"unregisterIfStillDownAfter": 10000,
"hubPort": 7777,
"hubHost": "MyHubIPHere",
"host": "MyNodeIPHere",
"nodeStatusCheckTimeout": 10000,
"downPollingLimit": 0
}
When i debugged the code I found that it fails in this method
public static GridHubConfiguration loadFromJSON(JsonObject json) {
try {
GsonBuilder builder = new GsonBuilder();
GridHubConfiguration.staticAddJsonTypeAdapter(builder);
return builder.excludeFieldsWithoutExposeAnnotation().create()
.fromJson(json, GridHubConfiguration.class);
} catch (Throwable e) {
throw new GridConfigurationException("Error with the JSON of the config : " + e.getMessage(),
e);
}
}
Its because I have used a custom capability matcher class that helps us to execute SIKULI UI tests in grid. Workaround for me was to copy the jar containing " io .sterodium.extensions.capability.CustomCapabilityMatcher" and add it to class path of node. Why selenium grid imposes us to copy a jar file to node where its not at all used. Just to parse the json we need to copy the jar file and add it to class path. Please fix it
Confirming that this is an issue.
To fix this such that the custom capability matcher class does not have to be present on the nodes (I agree, it should not be required), we would have to strip out troublesome JSON key/value pairs from the response in this call https://github.com/SeleniumHQ/selenium/blob/705be71ce9ec7e3825cb1633d3da40ab75a8819f/java/server/src/org/openqa/grid/internal/utils/SelfRegisteringRemote.java#L327-L341 -- which seems a bit hacky to me.
We will pursue a proper fix and update this issue when something is in place.
In the interim, if it is important to you that the nodes acquire their timeout value from the hub, please take the work-around and ensure the nodes have the class in their CLASSPATH.
Hi, I am also facing the same problem in my infrastructure when I customised the capability matcher. I am using Selenium 3.7.1, hub is running on linux, mobile physical device on a Mac Mini appium node and Browsers on a windows node.
Hub config: { "port": 4444, "newSessionWaitTimeout": -1, "servlets" : [], "withoutServlets": [], "custom": {}, "capabilityMatcher": "org.openqa.grid.internal.utils.customDefaultCapabilityMatcher", ...
Command to start hub with custom capability: su - selenium -c "nohup java -cp /usr/share/selenium-hub/customDefaultCapabilityMatcher.jar:/usr/share/selenium-hub/selenium-server-standalone-3.7.1.jar org.openqa.grid.selenium.GridLauncherV3 -role hub -hubConfig /usr/share/selenium-hub/conf/hubconfig.json 2>&1 & echo $! > /usr/share/selenium-hub/selenium-hub.pid" >> /applications/logs/selenium-hub/selenium-hub.log
Error from log: 15:34:59.986 INFO - Selenium Grid hub is up and running 09:21:00.957 INFO - Registered a node http://127.0.0.1:5555 Exception in thread "main" org.openqa.grid.common.exception.GridConfigurationException: Error with the JSON of the config : String org.openqa.grid.internal.utils.customDefaultCapabilityMatcher could not be coerced to class: java.lang.Class at org.openqa.grid.internal.utils.configuration.GridHubConfiguration.loadFromJSON(GridHubConfiguration.java:172) at org.openqa.grid.internal.utils.configuration.GridHubConfiguration.loadFromJSON(GridHubConfiguration.java:159)
As for the above workaround to the selenium issue, does it matter where I store the custom jar file on the appium and windows node and can someone provide steps on how to set the CLASSPATH on both nodes (iOS and Windows)? Thanks inadvance.
@WilliamCKTang Do you have a class named customDefaultCapabilityMatcher? Or is it a typo, a missing dot?
@shankarkc @mach6 can you please give some more explanation on how you added the jar containing the class to the class path of the nodes?
I.E.:
- Do you mean the class path as in environment variables of the node?
- Do you add it in the node config .json?
- In what folder on the node do you keep the jar relative to the folder containing the nodeconfig.json and the other selenium jars?
Thanks in advance!
@MaikelBruin Hello,
I'm facing same issue you have, in order to workaround it I'm doing the following:
- Have selenium-server-standalone.jar and your custom-grid-capability-matcher.jar in same folder
- Run node like this
java -cp "custom-grid-capability-matcher.jar:selenium-server-standalone.jar:lib/*" org.openqa.grid.selenium.GridLauncherV3 -role node -nodeConfig ./nodes/node1.json
In addition, I'm running server in same way as node:java -cp "custom-grid-capability-matcher.jar:selenium-server-standalone.jar:lib/*" org.openqa.grid.selenium.GridLauncherV3 -role hub -hubConfig ./config/hubconfig.json
@xlenz Thanks for replying!
I am going to try it out soon for the node. However the hub is started by a jenkins plugin (using JenkinsCapabilityMatcher) and I cannot yet figure out how to change the hub startup command...
Wil give an update as soon as I tried out starting the node as you said.
@xlenz When I try to run your command I get the Error message: Could not find or load main class org.openqa.grid.selenium.GridLauncherV3
I checked the standalone jar with a decompiler and it sais that the main class is actually there, also specified as main class in the manifest.mf.
Perhaps any idea on why it is giving this message? what does your nodeConfig.json look like?
Thanks again in advance!
@MaikelBruin looks like there is no selenium server standalone in the folder you are starting hub. Just to be more clear, I've downloaded server from https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar to the folder with my matcher:
-rw-r--r-- 1 4.6K Jan 3 15:12 grid-capability-matcher-3.141.5.jar
-rw-r--r--@ 1 10M Jan 4 19:26 selenium-server-standalone-3.141.59.jar
and then starting hub like this
java -cp "selenium-server-standalone-3.141.59.jar:grid-capability-matcher-3.141.5.jar*" org.openqa.grid.selenium.GridLauncherV3 -role hub -hubConfig ./config/hubconfig.json
Note: jar order does matter! Selenium server should always be first!
P.S.
java version "1.8.0_192"
@xlenz thanks for replying. The jars were in the same folder so that was not the problem. The problem was that the hub was started differently than the nodes (via jenkins selenium plugin). I now eliminated the jenkins selenium plugin out of the equation and so far it seems to be working correctly.
Thanks for your help anyway!
Closing this since there is a workaround, which is to have the customized jar present in the nodes too, not ideal though. Additionally, Grid 3.x is not under active development anymore.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.