WebDriverException: let's add some info about the Grid node
🚀 Feature Proposal
WebDriverException's should include the IP of the Grid node which is actually executing the commands, along with the info about the host running the test (which is being printed already).
Motivation
I've just bumped into an exception (pasted below) which is due to an issue between the Grid and the SUT, and I've realised that there is no way for me to figure out, just by looking at the exception, which node(s) of the Grid are affected (only one or two, or all?): the exception mentions the host executing the tests (which I don't really care about), but it doesn't say anything about the specific grid node running the browser (which I do care about).
org.openqa.selenium.WebDriverException: Unable to parse remote response: <html>
[..]
</html>
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:115)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
at RemoteDriverFactory.createDriver(RemoteDriverFactory.java:21)
[..]
Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: <. Last 1 characters read: <
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'xxxxx', ip: 'xxx', os.name: 'Linux', os.arch: 'amd64', os.version: 'xxx', java.version: 'xxx'
Driver info: driver.version: LazyWebDriver
at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:122)
at org.openqa.selenium.json.JsonTypeCoercer.lambda$null$6(JsonTypeCoercer.java:140)
at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:126)
at org.openqa.selenium.json.Json.toType(Json.java:69)
at org.openqa.selenium.json.Json.toType(Json.java:55)
at org.openqa.selenium.json.Json.toType(Json.java:50)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:112)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
[..]
PS: it seems to me that this is unrelated to this particular exception I got. I mean, no WebDriverException ever prints any info about the Grid node.
Example
I would expect any WebDriverException raised by a RemoteWebDriver (i.e. Grid mode), to look ideally like this (see in particular the last line, starting with "Grid info"):
org.openqa.selenium.json.WebDriverException: Some message
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'xxxxx', ip: 'xxx', os.name: 'Linux', os.arch: 'amd64', os.version: 'xxx', java.version: 'xxx'
Driver info: driver.version: RemoteWebDriver
Grid info: hub: x.x.x.x, node: 'y.y.y.y'
We are happy to review any PRs that can contribute to this. Probably should be something that gets enabled through a flag.
Hi @diemol , is this still open for the Grab and also where do you want it to be exposed ?
@dratler sorry for the late response. Yes, of course! However, I had a quick look and I am not sure where is the best place to add it. We need to follow the request flow and find that spot.
@asolntsev this issue showed me that we are not using the host and IP information from the Node to render it in the WebDriverException on the client side. We should remove that logic from that method, now I agree with you :)
@diemol Wow, it took only 6 six years. Apparently I need to improve my soft skills. :)
Should I prepare a pull request? [rubbing his hands...]
@asolntsev, yes please!
@alb-i986 Actually, this does seem to be working. When a WebDriverException happens in Grid, the error response will contain the IP of the machine where the exception happens. Could you share a scenario where this is not case?
@asolntsev maybe we need to hold on that PR :)
@alb-i986 Actually, this does seem to be working. When a
WebDriverExceptionhappens in Grid, the error response will contain the IP of the machine where the exception happens. Could you share a scenario where this is not case?
What version are you talking about?
I was talking about:
Build info: version: '3.141.59', revision: 'e82be7d358'
What version are you talking about?
Grid 4, latest is 4.1.2. The old Grid is not being updated or released anymore.
Just tried with both Grid 3.141.59 and 4.1.2: in most cases, they print out only the IP of test machine, not grid.
Case 1
When I execute code like $("#radioButtonz").click(),
- The error message returned by Grid (no IP!)
no such element: Unable to locate element: {"method":"css selector","selector":"#radioButtonz"}
(Session info: headless chrome=98.0.4758.80)
- The error generated on client side (test execution machine) - has IP:
org.openqa.selenium.NoSuchElementException: Unable to locate element: #radioButtonz
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'IP-CLIENT', ip: 'fe80:0:0:0:1820:2c9e:903:f0da%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_322'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 97.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20220202182137, moz:geckodriverVersion: 0.30.0, moz:headless: false, moz:processID: 22143, moz:profile: /var/folders/dn/94xhn6fx705..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: MAC, platformName: MAC, platformVersion: 21.3.0, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 9b16c85e-f90c-46d9-bcd4-d78...}
Session ID: 9b16c85e-f90c-46d9-bcd4-d78383b10378
*** Element info: {Using=css selector, value=#radioButtonz}
Case 2
But in case of SessionNotCreatedException, they print out BOTH IPs (of grid server and test execution machine):
org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'IP-GRID', ip: 'fe80:0:0:0:1820:2c9e:903:f0da%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_322'
...
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'IP-GRID', ip: 'fe80:0:0:0:1820:2c9e:903:f0da%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_322'
Driver info: driver.version: unknown
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'IP-CLIENT', ip: 'fe80:0:0:0:1820:2c9e:903:f0da%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_322'
Driver info: driver.version: unknown
The error message contains both IPs - and multiple times :)
And all this info is just a mud puddle, if you ask me. I would remove all these IPs, hostnames etc.
The case 2 is where this makes sense because there might be a misconfigured Node and you want to know the IP of it so you can fix it.
I agree with Case 1, there is no need for IP information there. And Case 2 should look much nicer, agreed.
I have made minor changes to resolve this issue. It won't be exactly what we discussed in the comments above, and there is a reason for that.
First of all, I removed the host name and IP from all exceptions but SessionNotCreatedException. So in most cases the user will see the exception as it is, and when something goes wrong while creating the session (Grid and locally), the host information will be shown. Please note that the host information will be the one from the host where the exception happened, could be the Hub or the Node.
Example:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Could not start a new session. No nodes support the capabilities in the request
Host info: host: 'SL-1966', ip: 'fe80:0:0:0:109e:7809:644:4af6%en0'
Build info: version: '4.4.0-9792-6', revision: 'Unknown'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '12.5', java.version: '11.0.12'
Driver info: driver.version: unknown
Build info: version: '4.4.0-9792-6', revision: '9f4f47ef6e5*'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.5', java.version: '11.0.14.1'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
It is not ideal, to have everything perfect in the exception would have required a major rework. However, what this issue is asking for, already exists. Grid 4 comes with Observability, so you could use that to get the information you are looking for.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.