Problem with WebDriverListener in case of RemoteWebDriver

147 views
Skip to first unread message

Arsen Papoyan

unread,
Jan 11, 2022, 12:55:35 AM1/11/22
to Selenium Users
Hello.
Could you please help sort out this issue?
Project: Maven
Runner: TestNG
Remote: Selenium Grid (selenium server 4.1.0)
JavaSE 14: version 16.0.1
src/main/java folder:
public class Driver { public static void initDriver() { assertionMode = AssertionMode.SOFT; baseUrl = "https://www.google.com/"; pageLoadStrategy = "eager"; browser = "Chrome"; pollingInterval = 500; holdBrowserOpen = false; savePageSource = false; fastSetValue = true; screenshots = false; remote = "remoteMachineUrl"; driverManagerEnabled = true; headless = false; timeout = 10000; WebDriverRunner.addListener(new WebDriverEvent()); open(); } public final class Util { public static WebDriver driver = new Augmenter().augment(getWebDriver()); public static DevTools devTools = ((HasDevTools) driver).getDevTools(); } public class WebDriverEvent implements WebDriverListener { @Override public void beforeClick(WebElement element) { WebDriverListener.super.beforeClick(element); System.out.println("Before Click"); } }
src/test/java folder:
public class DevToolsTest { @Test public void devToolTest(){ Driver.initDriver(); open(baseUrl); Util.devTools.createSession(); Util.devTools.send(Network.clearBrowserCache()); } }

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> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.4.0</version> </dependency> <dependency> <groupId>com.codeborne</groupId> <artifactId>selenide</artifactId> <version>6.1.2</version> </dependency> <dependency> <groupId>org.selenide</groupId> <artifactId>selenide-testng</artifactId> <version>1.0.0</version> <scope>test</scope> </dependency> <dependency> <groupId>net.bytebuddy</groupId> <artifactId>byte-buddy</artifactId> <version>1.12.6</version> </dependency> </dependencies> </project>

After running I get this error:
java.lang.ExceptionInInitializerError
at DevToolsTest.devToolTest(DevToolsTest.java:13)
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)
Caused by: java.lang.IllegalArgumentException: Cannot subclass primitive, array or final types: class jdk.proxy2.$Proxy10
at net.bytebuddy.ByteBuddy.subclass(ByteBuddy.java:490)
at net.bytebuddy.ByteBuddy.subclass(ByteBuddy.java:463)
at net.bytebuddy.ByteBuddy.subclass(ByteBuddy.java:360)
at org.openqa.selenium.remote.Augmenter.augment(Augmenter.java:179)
at Util.<clinit>(Util.java:10)

The problem is connected with the WebDriverEvent class, when I remove this class everything is okay.
But the problem is only arising in the case of running the test on the remote machine, when I run the test with the WebDriverEvent class in the local machine, everything is okay.

⇜Krishnan Mahadevan⇝

unread,
Jan 11, 2022, 1:37:30 AM1/11/22
to Selenium Users
I can't seem to be able to reproduce the problem using Selenium 4

Here's what I have as dependencies (Am on Gradle)
implementation 'org.seleniumhq.selenium:selenium-java:4.1.1'
Here's what my test code looks like:
import static org.assertj.core.api.Assertions.assertThat;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.decorators.WebDriverDecorator;
import org.openqa.selenium.support.events.EventFiringDecorator;
import org.openqa.selenium.support.events.WebDriverListener;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class TestClassSample {

  private WebDriver driver;
  private WebDriverEvent listener;

  @BeforeClass
  public void beforeClass() throws MalformedURLException {
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), new ChromeOptions());
    listener = new WebDriverEvent();
    WebDriverDecorator decorator = new EventFiringDecorator(listener);
    driver = decorator.decorate(driver);
  }

  @Test
  public void testMethod() {
    driver.get("https://testpages.herokuapp.com/styled/index.html");
    driver.findElement(By.id("basicpagetest")).click();
    assertThat(listener.logs)
        .contains("https://testpages.herokuapp.com/styled/index.html", "Basic Web Page Example");
  }

  @AfterClass
  public void afterClass() {
    Optional.ofNullable(driver)
        .ifPresent(WebDriver::quit);
  }

  public static class WebDriverEvent implements WebDriverListener {

    private final List<String> logs = new ArrayList<>();

    @Override
    public void beforeGet(WebDriver driver, String url) {
      logs.add(url);
    }

    @Override
    public void beforeClick(WebElement element) {
      logs.add(element.getText());
    }
  }
}

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/83feec28-6c0d-4f8d-b1e2-266b5037c01fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages