尝试使用 TestNG 和 WebDriverManager 运行测试时出错

尝试使用 TestNG 和 WebDriverManager 执行测试时出现此错误。我使用的依赖是https://github.com/bonigarcia/webdrivermanager-examples for Maven 中提到的依赖,TestNG 的版本是 6.14.3。


我的代码很简单:


private WebDriver driver;


@BeforeClass

public void setupClass() {

    WebDriverManager.chromedriver().setup();

    driver = new ChromeDriver();

}


@AfterTest

public void teardown() {

    if (driver != null) {

        driver.quit();

    }

}


@Test

public void test() {

    // Your test code here

}

我得到这个错误:


[RemoteTestNG] detected TestNG version 6.14.3

FAILED CONFIGURATION: @BeforeClass setupClass

java.lang.NoSuchMethodError: org.apache.http.impl.client.HttpClientBuilder.setConnectionManagerShared(Z)Lorg/apache/http/impl/client/HttpClientBuilder;

at io.github.bonigarcia.wdm.HttpClient.<init>(HttpClient.java:97)

at io.github.bonigarcia.wdm.HttpClient.<init>(HttpClient.java:91)

at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:407)

at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:215)

at com.cuballama.automation.framework.Prueba.setupClass(Prueba.java:45)

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:564)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)

at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)

at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)

at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)


有任何想法吗?


回首忆惘然
浏览 171回答 2
2回答

眼眸繁星

多挖一点后,我可以找到问题的原因。我在 Maven 中缺少一些依赖项。<dependency>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.slf4j</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>slf4j-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.6.6</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.slf4j</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>slf4j-simple</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.6.6</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>net.sf.dozer</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>dozer</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>5.5.1</version>&nbsp; &nbsp; &nbsp; &nbsp; <exclusions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jcl-over-slf4j</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.slf4j</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>slf4j-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.slf4j</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; </exclusions>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.httpcomponents</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>httpclient</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>4.5.2</version>&nbsp; &nbsp; </dependency>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java