SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.75k stars 8.2k forks source link

[πŸ› Bug]: cannot pass node driver-configuration via cli argument #13531

Closed muhammetaltindal closed 9 months ago

muhammetaltindal commented 9 months ago

What happened?

Running the simple command from the selenium tutorial does not work.

Documentation page: https://www.selenium.dev/documentation/grid/configuration/cli_options/

Selenium server jar is not able to read the provided --driver-configuration argument.

Run the command

java -jar selenium-server-<version>.jar node --detect-drivers false --driver-configuration display-name="Chrome (custom capability true)" max-sessions=1 stereotype='{"browserName":"chrome","gsg:customcap":true}' --port 6161

Basically main issue is:

Caused by: org.openqa.selenium.grid.config.ConfigException: No driver configs were found!

Take a look at the method org.openqa.selenium.grid.config.Config#getArray: In the for-loop it checks if (Config.DELIMITER.equals(next)) { ..., however that never matches because that constant Config.DELIMITER is equal to String DELIMITER = DELIM_KEY + "=\"record-separator\"", so I basically would need to pass that somehow via CLI in order to make the program understand it and return a non-empty config list. Right now always an empty config list is returned.

How can we reproduce the issue?

java -jar selenium-server-4.17.0.jar hub &
java -jar selenium-server-4.17.0.jar node --detect-drivers false --driver-configuration display-name="Chrome (custom capability true)" max-sessions=1 stereotype='{"browserName":"chrome","gsg:customcap":true}' --port 6161

Relevant log output

10:09:34.580 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding
10:09:34.583 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing
10:09:34.585 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding
10:09:34.588 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing
10:09:34.634 INFO [BoundZmqEventBus.<init>] - XPUB binding to [binding to tcp://*:4442, advertising as tcp://[2a02:3035:6e0:61b4:82f4:b1fa:6892:4%en0]:4442], XSUB binding to [binding to tcp://*:4443, advertising as tcp://[2a02:3035:6e0:61b4:82f4:b1fa:6892:4%en0]:4443]
10:09:34.636 INFO [UnboundZmqEventBus.<init>] - Connecting to tcp://0.0.0.0:4442 and tcp://0.0.0.0:4443
10:09:34.654 INFO [UnboundZmqEventBus.<init>] - Sockets created
10:09:34.657 INFO [UnboundZmqEventBus.<init>] - Connecting to ...
10:09:34.668 INFO [UnboundZmqEventBus.<init>] - Sockets created
10:09:35.660 INFO [UnboundZmqEventBus.<init>] - Event bus ready
10:09:35.673 INFO [UnboundZmqEventBus.<init>] - Event bus ready
10:09:35.731 INFO [NodeServer.createHandlers] - Reporting self as: http://192.168.8.6:6262
10:09:35.742 INFO [NodeOptions.getSessionFactories] - Detected 10 available processors
10:09:35.746 ERROR [Bootstrap.runMain] - Error during execution
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.openqa.selenium.grid.Bootstrap.runMain(Bootstrap.java:77)
    at org.openqa.selenium.grid.Bootstrap.main(Bootstrap.java:70)
Caused by: org.openqa.selenium.grid.config.ConfigException: java.lang.reflect.InvocationTargetException
    at org.openqa.selenium.grid.config.MemoizedConfig.getClass(MemoizedConfig.java:119)
    at org.openqa.selenium.grid.node.config.NodeOptions.getNode(NodeOptions.java:181)
    at org.openqa.selenium.grid.node.httpd.NodeServer.createHandlers(NodeServer.java:126)
    at org.openqa.selenium.grid.node.httpd.NodeServer.asServer(NodeServer.java:185)
    at org.openqa.selenium.grid.node.httpd.NodeServer.execute(NodeServer.java:247)
    at org.openqa.selenium.grid.TemplateGridCommand.lambda$configure$4(TemplateGridCommand.java:122)
    at org.openqa.selenium.grid.Main.launch(Main.java:83)
    at org.openqa.selenium.grid.Main.go(Main.java:56)
    at org.openqa.selenium.grid.Main.main(Main.java:41)
    ... 6 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.openqa.selenium.grid.config.ClassCreation.callCreateMethod(ClassCreation.java:51)
    at org.openqa.selenium.grid.config.MemoizedConfig.lambda$getClass$4(MemoizedConfig.java:104)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1740)
    at org.openqa.selenium.grid.config.MemoizedConfig.getClass(MemoizedConfig.java:99)
    ... 14 more
Caused by: org.openqa.selenium.grid.config.ConfigException: No driver configs were found!
    at org.openqa.selenium.grid.node.config.NodeOptions.lambda$addDriverConfigs$11(NodeOptions.java:416)
    at java.base/java.util.Optional.ifPresent(Optional.java:178)
    at org.openqa.selenium.grid.node.config.NodeOptions.addDriverConfigs(NodeOptions.java:370)
    at org.openqa.selenium.grid.node.config.NodeOptions.getSessionFactories(NodeOptions.java:245)
    at org.openqa.selenium.grid.node.local.LocalNodeFactory.create(LocalNodeFactory.java:79)
    ... 22 more
Exception in thread "Thread-0" java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.grid.node.Node.getStatus()" because "this.node" is null
    at org.openqa.selenium.grid.node.httpd.NodeServer.lambda$new$0(NodeServer.java:78)
    at java.base/java.lang.Thread.run(Thread.java:833)
10:09:35.944 INFO [Hub.execute] - Started Selenium Hub 4.17.0 (revision e52b1be057*): http://192.168.8.6:4444

Operating System

macOS

Selenium version

4.17.0

What are the browser(s) and version(s) where you see this issue?

Chrome 121

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver: 121.0.6167.85

Are you using Selenium Grid?

4.17.0

github-actions[bot] commented 9 months ago

@muhammetaltindal, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 9 months ago

Yeah, https://github.com/SeleniumHQ/selenium/commit/ecfa9c40532679dd51c0f6691ea8da9564f8d603 broke that. I will have a look.

Jiurong-Yang commented 9 months ago

I'm also having this issue, I tested a few recent older version, the issue started in 4.12, which seems to be before the PR in question. Not sure if this helps. For me I'll just be rolling back to 4.11

diemol commented 9 months ago

I pushed a fix, but it will be available in the next release.

There is a change in how this argument needs to be passed, and now it is needed to use double quotation marks for this.

Then, using the example, it would become:

java -jar selenium-server-<version>.jar standalone --detect-drivers false --driver-configuration display-name="Chrome (custom capability true)" max-sessions=1 stereotype="{\"browserName\":\"chrome\", \"gsg:customcap\":true}" --port 6161

The docs were also fixed with this commit https://github.com/SeleniumHQ/seleniumhq.github.io/commit/333ff8ee4c92bb62f335f533272bc94ce66d0cc7

Jiurong-Yang commented 9 months ago

Does this cause a problem when running this parameter on windows powershell? I've tried both the old 4.11 and the nightly 4.18 selenium version with various different ways to try to escape the quotes but all fails. The example you give here throws this error for 4.18

PS C:\Users\exec\Downloads> java -jar selenium-server-standalone.jar standalone --detect-drivers false --driver-confi guration display-name="Chrome (custom capability true)" max-sessions=1 stereotype="{\"browserName\":\"chrome\", \"gsg :customcap\":true}" --port 6161 17:56:37.937 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding 17:56:37.952 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing 17:56:39.436 INFO [NodeOptions.getSessionFactories] - Detected 6 available processors 17:56:39.452 ERROR [Bootstrap.runMain] - Error during execution java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.openqa.selenium.grid.Bootstrap.runMain(Bootstrap.java:77) at org.openqa.selenium.grid.Bootstrap.main(Bootstrap.java:70) Caused by: org.openqa.selenium.grid.config.ConfigException: java.lang.reflect.InvocationTargetException at org.openqa.selenium.grid.config.MemoizedConfig.getClass(MemoizedConfig.java:119) at org.openqa.selenium.grid.node.config.NodeOptions.getNode(NodeOptions.java:181) at org.openqa.selenium.grid.commands.Standalone.createNode(Standalone.java:257) at org.openqa.selenium.grid.commands.Standalone.createHandlers(Standalone.java:223) at org.openqa.selenium.grid.TemplateGridServerCommand.asServer(TemplateGridServerCommand.java:47) at org.openqa.selenium.grid.commands.Standalone.execute(Standalone.java:243) at org.openqa.selenium.grid.TemplateGridCommand.lambda$configure$4(TemplateGridCommand.java:122) at org.openqa.selenium.grid.Main.launch(Main.java:83) at org.openqa.selenium.grid.Main.go(Main.java:56) at org.openqa.selenium.grid.Main.main(Main.java:41) ... 6 more Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.openqa.selenium.grid.config.ClassCreation.callCreateMethod(ClassCreation.java:51) at org.openqa.selenium.grid.config.MemoizedConfig.lambda$getClass$4(MemoizedConfig.java:104) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1737) at org.openqa.selenium.grid.config.MemoizedConfig.getClass(MemoizedConfig.java:99) ... 15 more Caused by: org.openqa.selenium.json.JsonException: Unable to parse: {\browserName\:\chrome\, \gsg:customcap\:true}
at org.openqa.selenium.json.Json.toType(Json.java:169) at org.openqa.selenium.json.Json.toType(Json.java:152) at org.openqa.selenium.grid.node.config.NodeOptions.lambda$addDriverConfigs$10(NodeOptions.java:434) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.openqa.selenium.grid.node.config.NodeOptions.lambda$addDriverConfigs$11(NodeOptions.java:430) at java.base/java.util.Optional.ifPresent(Optional.java:183) at org.openqa.selenium.grid.node.config.NodeOptions.addDriverConfigs(NodeOptions.java:370) at org.openqa.selenium.grid.node.config.NodeOptions.getSessionFactories(NodeOptions.java:245) at org.openqa.selenium.grid.node.local.LocalNodeFactory.create(LocalNodeFactory.java:79) ... 23 more Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: . Last 2 characters read: {\, next 44 characters to read: browserName\:\chrome\, \gsg:customcap\:true} Build info: version: '4.18.0-SNAPSHOT', revision: '290cfff' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.10' Driver info: driver.version: unknown at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:166) at org.openqa.selenium.json.JsonInput.hasNext(JsonInput.java:296) at org.openqa.selenium.json.JsonInputIterator.hasNext(JsonInputIterator.java:40) at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132) at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at org.openqa.selenium.json.MapCoercer.lambda$apply$1(MapCoercer.java:75) at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$6(JsonTypeCoercer.java:171) at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:146) at org.openqa.selenium.json.Json.toType(Json.java:206) at org.openqa.selenium.json.Json.toType(Json.java:167)

Jiurong-Yang commented 9 months ago

Yeah I don't think it's working for linux either. With this command:

java -jar /work/ams_config/cache/selenium-server-standalone.jar node --hub http://hostname:4444 --port 11001 --detect-drivers false --driver-configuration display-name="chrome" max-sessions=5 stereotype="{\"browserName\": \"chrome\", \"platformName\":\"linux\", \"browserVersion\": \"ANY\"}" --driver-configuration display-name="firefox" max-sessions=5 stereotype="{\"browserName\": \"firefox\", \"platformName\":\"linux\", \"browserVersion\": \"ANY\"}" --driver-configuration display-name="msedge" max-sessions=2 stereotype="{\"browserName\": \"msedge\", \"platformName\":\"linux\", \"browserVersion\": \"ANY\"}"

It only added the last browser, edge.

17:27:02.915 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding 17:27:02.921 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing 17:27:03.026 INFO [UnboundZmqEventBus.] - Connecting to tcp://intsrv1u.sdg.rd.hpicorp.net:4442 and tcp://intsrv1u.sdg.rd.hpicorp.net:4443 17:27:03.079 INFO [UnboundZmqEventBus.] - Sockets created 17:27:04.082 INFO [UnboundZmqEventBus.] - Event bus ready 17:27:04.243 INFO [NodeServer.createHandlers] - Reporting self as: http://15.1.194.68:11001 17:27:04.274 INFO [NodeOptions.getSessionFactories] - Detected 12 available processors 17:27:04.322 INFO [NodeOptions.report] - Adding msedge for {"browserName": "msedge","browserVersion": "ANY","platformName": "linux"} 2 times 17:27:04.345 INFO [Node.] - Binding additional locator mechanisms: relative 17:27:04.527 INFO [NodeServer$1.start] - Starting registration process for Node http://15.1.194.68:11001 17:27:04.528 INFO [NodeServer.execute] - Started Selenium node 4.18.0-SNAPSHOT (revision f38718b): http://15.1.194.68:11001 17:27:04.547 INFO [NodeServer$1.lambda$start$1] - Sending registration event... 17:27:04.710 INFO [NodeServer.lambda$createHandlers$2] - Node has been added

@diemol Should I create a new ticket or should we just reopen this one?

diemol commented 9 months ago

When using the CLI, --driver-configuration only accepts one configuration.

What we recommend is to always use a toml configuration file.

github-actions[bot] commented 8 months ago

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.