[🐛 Bug]: HasAuthentication is not working for Chromium browsers when they are executed in Selenium Grid
See original GitHub issueWhat happened?
I am able to use register method from HasAuthentication interface using chromium drivers running on local machine. But when i try to use chromium browser (edge/chrome) which is part of selenium grid I am getting the following error when I try to use HasAuthentication interface.
Code where the test fails:
((HasAuthentication) webDriver).register(() -> new UsernameAndPassword("admin", "admin"));
Error:
java.lang.ClassCastException: class org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$gPlLDnEY cannot be cast to class org.openqa.selenium.HasAuthentication (org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$gPlLDnEY is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @77681ce4; org.openqa.selenium.HasAuthentication is in unnamed module of loader 'app')
How can we reproduce the issue?
How to reproduce the problem:
* Run a selenium grid (standalone / hub&node mode - does not matter)
`java -jar selenium-server.jar standalone --detect-drivers true`
* Execute the code below using selenium-java 4
Code Example
`WebDriver webDriver = RemoteWebDriver
.builder()
.augmentUsing(new Augmenter())
.oneOf(new ChromeOptions())
.address(new URL("http://localhost:4444"))
.build();
((HasAuthentication) webDriver).register(() -> new UsernameAndPassword("admin", "admin"));
webDriver.get("https://the-internet.herokuapp.com/basic_auth");`
Relevant log output
java.lang.ClassCastException: class org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$E2NldVid cannot be cast to class org.openqa.selenium.HasAuthentication (org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$E2NldVid is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @2d38edfd; org.openqa.selenium.HasAuthentication is in unnamed module of loader 'app')
at com.isobar.commerce.selenium.tests.FeaturesTests.test(FeaturesTests.java:175)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Operating System
Windows 10 / MacOS BigSur 11.3.1
Selenium version
4.0.0
What are the browser(s) and version(s) where you see this issue?
Chrome 94
What are the browser driver(s) and version(s) where you see this issue?
chromedriver 94.0.4606.61
Are you using Selenium Grid?
Yes - 4.0.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:19 (8 by maintainers)
Top GitHub Comments
Thank you @pujagani I’m currently not able to try this out properly (for many reasons including tightened company restrictions and a dead computer 😦 ). However I appreciate your input and I’ll check out your suggestion when I’m in a position to look at it properly.
Augmentation is only needed for RemoteWebDriver instances because the applicable browser drivers themselves implement the interface. This doesn’t actually address making the second call easier, but with respect to getting an augmented driver in the first place, I wanted to point out that you can use
RemoteWebDriverBuilder
to automatically augment. Here’s an example:https://github.com/saucelabs-training/demo-java/blob/docs-1.2/selenium-examples/src/test/java/com/saucedemo/selenium/se4newfeatures/RemoteWebDriverBuilderTest.java
Just thought I’d mention it since there are so few resources out there right now discussing the Augmenter, and it’s super powerful.