selenium: [πŸ› Bug]: Using HasAuthentication with Augmenter throws ClassCastException

What happened?

Getting an error in case of RemoteWebDriver using HasAuthentication.

How can we reproduce the issue?

Project: Maven
Runner: TestNG

src/main/java folder:

public class DriverMobile {

    public static WebDriver webDriver;
    public static DevTools devTools;

    public static void initDriver() {
        Map<String, String> mobileEmulation = new HashMap<>();
        mobileEmulation.put("deviceName", "iPhone 12 Pro");
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("mobileEmulation", mobileEmulation);
        assertionMode = SOFT;
        driverManagerEnabled = true;
        screenshots = false;
        savePageSource = false;
        headless = false;
        remote = "remoteMachineUrl";
        browserCapabilities = options;
        open();
        webDriver = new Augmenter().augment(getWebDriver());
        devTools = ((HasDevTools) webDriver).getDevTools();
        ((HasAuthentication) webDriver).register(UsernameAndPassword.of("username", "password"));
    }
}

src/test/java folder:

public class HasAuthenticationTest {

    @Test
    public void test(){
        DriverMobile.initDriver();
        open("https://www.google.com/");
    }
}

pom XML:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>Draft</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <aspectj.version>1.9.6</aspectj.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>selenide-testng</artifactId>
            <version>6.6.5</version>
        </dependency>
        <dependency>
            <groupId>net.bytebuddy</groupId>
            <artifactId>byte-buddy</artifactId>
            <version>1.12.10</version>
        </dependency>
    </dependencies>

The problem is only arising in the case of running the test on the remote machine, when I run the test on the local machine, everything is okay.

Relevant log output

java.lang.ClassCastException: class org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$W9YhfBNu cannot be cast to class org.openqa.selenium.HasAuthentication (org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$W9YhfBNu is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @5fa9247b; org.openqa.selenium.HasAuthentication is in unnamed module of loader 'app')

	at SelenideDriver.DriverMobile.initDriver(DriverMobile.java:40)
	at HasAuthenticationTest.test(HasAuthenticationTest.java:10)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
	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:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:794)
	at org.testng.TestRunner.run(TestRunner.java:596)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
	at org.testng.SuiteRunner.run(SuiteRunner.java:276)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
	at org.testng.TestNG.runSuites(TestNG.java:1063)
	at org.testng.TestNG.run(TestNG.java:1031)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

Operating System

Local: macOS Monterey / Remote: Windows 10

Selenium version

JavaSE 14: version 16.0.2

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

Chrome 103

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

ChromeDriver 102

Are you using Selenium Grid?

Selenium Grid (selenium server 4.1.4)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 19 (12 by maintainers)

Most upvoted comments

@diemol I quickly looked into the issue: the problem is that Selenium doesn’t have HasAuthenticationAugmenterProvider (like AddHasCdp, AddHasExtensions, BiDiProvider, AddHasCasting etc.)