Automation WebDriver管理器java.lang.NoSuchMethodError

Automation WebDriver管理器java.lang.NoSuchMethodError,automation,webdriver,webdrivermanager-java,Automation,Webdriver,Webdrivermanager Java,我使用Java+selenium+testng+maven。 我尝试使用WebDriver管理器而不是标准用法。 在按照API的指令进行声明之后,我遇到了一个问题。 编译时出现错误: java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.copyInputStreamToFile(Ljava/io/InputStream;Ljava/io/File;)V at io.github.bonigarcia.wdm.Download

我使用Java+selenium+testng+maven。 我尝试使用WebDriver管理器而不是标准用法。 在按照API的指令进行声明之后,我遇到了一个问题。 编译时出现错误:

java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.copyInputStreamToFile(Ljava/io/InputStream;Ljava/io/File;)V

at io.github.bonigarcia.wdm.Downloader.download(Downloader.java:128)
at io.github.bonigarcia.wdm.BrowserManager.manage(BrowserManager.java:277)
at io.github.bonigarcia.wdm.BrowserManager.setup(BrowserManager.java:108)
at io.github.bonigarcia.wdm.BrowserManager.setup(BrowserManager.java:87)
at Base.BaseDriver.startBrowser(BaseDriver.java:67)
at Base.BaseTest.beforeClass(BaseTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
...
这是我的代码框架:

public static WebDriver startBrowser() {

    String browser = Property.getProperties("browser");

    if (browser.equalsIgnoreCase("firefox")) {
        FirefoxDriverManager.getInstance().setup();
        sDriver = new FirefoxDriver();
    } else if (browser.equalsIgnoreCase("chrome")) {
        ChromeDriverManager.getInstance().setup();
        sDriver = new ChromeDriver();
    }

    sDriver.manage().window().maximize();
    sDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    return sDriver;
}
和驱动程序使用:

@BeforeClass
public void beforeClass() throws Exception {
    BaseDriver.startBrowser();
}

WebDriverManager 1.7.1内部使用2.5。看起来您在项目中使用的是该库的不同版本,结果是出现了该错误


最简单的解决方案可能是将commons io版本升级到2.5,这是撰写本文时最新的稳定版本。

谢谢。我更新了依赖关系。Chrome驱动程序工作正常。但在尝试使用firefox时,我遇到了一个问题:java.lang.RuntimeException:java.lang.RuntimeException:检测到响应错误。HTTP/1.1 401未经授权