似乎将 browsermob-core 添加到我的依赖项会导致我的 selenium webdriver 停止工作
Seems adding browsermob-core to my dependencies causes my selenium webdriver to stop working
这是代码。这只是一个示例测试,没有 browermob-core。有了核心,我得到了 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 {
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'
}
和错误。当我删除 browermob-core 时一切正常
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)
搜索了一段时间,从这个中找到了答案
似乎我有一些 cross-path 问题或 missing/dated netty dependent
将此添加到我的 Gradle 构建中
implementation group: 'io.netty', name: 'netty-all', version: '4.1.75.Final'
这是代码。这只是一个示例测试,没有 browermob-core。有了核心,我得到了 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 {
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'
}
和错误。当我删除 browermob-core 时一切正常
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)
搜索了一段时间,从这个
将此添加到我的 Gradle 构建中
implementation group: 'io.netty', name: 'netty-all', version: '4.1.75.Final'