0

尝试使用 TestNG 和 WebDriverManager 执行测试时出现此错误。我使用的依赖是https://github.com/bonigarcia/webdrivermanager-examples中提到的 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)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

SKIPPED CONFIGURATION: @AfterTest teardown
SKIPPED: test
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)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at 
org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

有任何想法吗?

谢谢!

4

2 回答 2

0

检查您的配置,该示例使用 JUnit,并且您已切换到 TestNG。您还从 github 配置 6.13 更新了 TestNG 版本。我检查了您的 TestNG 版本,这似乎不是问题。

package io.github.bonigarcia.wdm.test;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

//import org.junit.After;
//import org.junit.Before;
//import org.junit.BeforeClass;
//import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

/**
 * Test with Chrome.
 *
 * @author Boni Garcia (boni.gg@gmail.com)
 * @since 1.0.0
 */
public class ChromeTestNG {

    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. For example:
//        WebDriverWait wait = new WebDriverWait(driver, 30);
//        driver.get("https://en.wikipedia.org/wiki/Main_Page");
//        By searchInput = By.id("searchInput");
//        wait.until(presenceOfElementLocated(searchInput));
//        driver.findElement(searchInput).sendKeys("Software");
//        By searchButton = By.id("searchButton");
//        wait.until(elementToBeClickable(searchButton));
//        driver.findElement(searchButton).click();
//
//        wait.until(textToBePresentInElementLocated(By.tagName("body"),
//                "Computer software"));
    }

}

我做了以下事情:

git clone https://github.com/bonigarcia/webdrivermanager-examples.git
git clone https://github.com/bonigarcia/webdrivermanager.git
download and install chromedriver 2.40
update Chrome version to 66
NOTE: I'm running on Ubuntu

注意:您也可以取消注释测试代码,它也对我有用

于 2018-07-18T05:18:01.310 回答
0

在挖掘了一点之后,我可以找到我的问题的原因。我在 Maven 中缺少一些依赖项。

<dependency> 
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.6</version>
    </dependency>

    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer</artifactId>
        <version>5.5.1</version>
        <exclusions>
            <exclusion>
                <artifactId>jcl-over-slf4j</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
            <exclusion>
                <artifactId>slf4j-api</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>



    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.2</version>
    </dependency>
于 2018-08-06T20:03:36.387 回答