我遇到了使用 Selenium 的 Opera 浏览器的问题。要下载浏览器二进制文件,我正在使用 webdrivermanager 插件(https://github.com/bonigarcia/webdrivermanager)
这是一个实现不同类型浏览器的枚举:
public enum DriverType implements DriverSetup {
CHROME {
public WebDriver getWebDriverObject() {
WebDriverManager.chromedriver().setup();
return new ChromeDriver();
}
},
FIREFOX {
public WebDriver getWebDriverObject() {
WebDriverManager.firefoxdriver().setup();
return new FirefoxDriver();
}
},
OPERA {
public WebDriver getWebDriverObject() {
WebDriverManager.operadriver().setup();
return new OperaDriver();
}
}
}
有一个 getWebDriverObject 方法的调用:
public class DriverBase {
public WebDriver driver;
public WebDriver initializeBrowser() {
DriverType driverType = DriverType.CHROME;
try {
String browser = System.getProperty("browser").toUpperCase();
driver = DriverType.valueOf(browser).getWebDriverObject();
} catch (Exception e) {
System.out.println("No driver specified/Wrong driver specified, default tests running on Chrome");
driver = driverType.getWebDriverObject();
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
return driver;
}
}
在我运行测试之前,我将系统属性浏览器设置为“opera”。这是一个输出。默认情况下,测试在 chrome 中运行,并且 Opera 浏览器没有打开,所以它不起作用。我该如何解决?
ProjectName > Login STANDARD_ERROR
1160 [Test worker] WARN io.github.bonigarcia.wdm.WebDriverManager - The driver version for Opera No Instance(s) Available. is unknown .
.. trying with latest
1163 [Test worker] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/operasoftware/operachromiumdri
ver/releases to seek operadriver
1465 [Test worker] INFO io.github.bonigarcia.wdm.WebDriverManager - Latest version of operadriver is 2.41
1548 [Test worker] INFO io.github.bonigarcia.wdm.Downloader - Using binary driver previously downloaded
1550 [Test worker] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.opera.driver as C:\Users\me\.m2\re
pository\webdriver\operadriver\win64\2.41\operadriver.exe
Starting OperaDriver 2.41 on port 37865
Only local connections are allowed.
Socrates > Login STANDARD_OUT
No driver specified/Wrong driver specified, default tests running on Chrome