我使用 Java+selenium+testng+maven。我尝试使用 WebDriver Manager 而不是标准用法。根据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();
}