WebDriver Manager java.lang.NoSuchMethodError

2.9k Views Asked by At

I use Java+selenium+testng+maven. And I tried to use WebDriver Manager instead of standard usage. After declaration according to the instruction of API, I ran into a problem. When compiling the errors occurs:

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)
...

Here is my code frame:

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;
}

And driver usage:

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

There are 1 best solutions below

1
On BEST ANSWER

WebDriverManager 1.7.1 internally use Apache commons-io 2.5. It seems you are using a different version of that library in your project, and a result you get that error.

The easiest solution might be upgrading your commons-io version to 2.5, which is the latest stable version at the moment of this writing.