javaseleniumselenium-chromedriverwebdriverbrowsermob-proxy

Seems adding browsermob-core to my dependencies causes my selenium webdriver to stop working


Here is the code. It's just an example test stuff works without browermob-core. With core I get NoSuchMethodError

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;
import java.util.Objects;

public class ChromeScriptTest {
  public WebDriver driver;

  @Test
  public void eightComponents() {
    System.setProperty("webdriver.chrome.driver", Objects.requireNonNull(getClass().getClassLoader().getResource("drivers/chromedriver.exe")).getFile() );

    driver = new ChromeDriver();

    driver.get("https://google.com");

    Assertions.assertEquals("Google", driver.getTitle());

    driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));

    WebElement searchBox = driver.findElement(By.name("q"));
    WebElement searchButton = driver.findElement(By.name("btnK"));

    searchBox.sendKeys("Selenium");
    searchButton.click();

    searchBox = driver.findElement(By.name("q"));
    Assertions.assertEquals("Selenium", searchBox.getAttribute("value"));

    driver.quit();
  }
}

Gradle Dependencies - I've tried changing the order and stuff still has the same error.

dependencies {
    implementation 'junit:junit:4.13.2'
    implementation 'org.junit.jupiter:junit-jupiter:5.8.2'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'


    implementation group:  'net.lightbody.bmp', name:  'browsermob-core' , version: '2.1.5'
    implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.1.0'
    implementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.0.3'

}

And the error. when I remove the browermob-core everything works fine

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

'io.netty.bootstrap.AbstractBootstrap io.netty.bootstrap.Bootstrap.channelFactory(io.netty.channel.ChannelFactory)'
java.lang.NoSuchMethodError: 'io.netty.bootstrap.AbstractBootstrap io.netty.bootstrap.Bootstrap.channelFactory(io.netty.channel.ChannelFactory)'
    at org.asynchttpclient.netty.channel.ChannelManager.newBootstrap(ChannelManager.java:162)
    at org.asynchttpclient.netty.channel.ChannelManager.<init>(ChannelManager.java:149)
    at org.asynchttpclient.DefaultAsyncHttpClient.<init>(DefaultAsyncHttpClient.java:92)
    at org.asynchttpclient.Dsl.asyncHttpClient(Dsl.java:32)

Solution

  • Searched a while and found the answer from this How solve Error: java.lang.ClassNotFoundException: io.netty.util.concurrent.GenericFutureListener? Seems either I had some cross-path issue or missing/dated netty dependent

    added this to my Gradle build

     implementation group: 'io.netty', name: 'netty-all', version: '4.1.75.Final'