为什么Gecko Driver(v0.17.0-x64bit)没有打开浏览器?
基页/方法:
public BasePage loadUrl(String url) throws Exception {
driver.get(url);
return new BasePage(driver);
}
黄瓜步骤
@Given("^User navigates to the \"([^\"]*)\" website$")
public void user_navigates_to_the_website(String url) throws Throwable {
BasePage basePage = new BasePage(driver);
basePage.loadUrl(url);
}
驱动程序工厂:
public WebDriver getDriver() {
try {
if(driver == null){
System.setProperty("webdriver.gecko.driver", Constant.GECKO_DRIVER_DIRECTORY);
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
basePage = PageFactory.initElements(driver, BasePage.class);
loginPage = PageFactory.initElements(driver, LoginPage.class);
}
} catch (Exception e) {
}
return driver;
}
新代码 - 驱动程序工厂:使用if语句指向每种浏览器类型的exe文件:
public WebDriver getDriver() {
try {
ReadConfigFile file = new ReadConfigFile();
if (driver == null) {
if("chrome".equalsIgnoreCase(file.getBrowser())){
System.setProperty("webdriver.chrome.driver", Constant.CHROME_DRIVER_DIRECTORY);
driver = new ChromeDriver();
}
if("firefox".equalsIgnoreCase(file.getBrowser())){
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
System.setProperty("webdriver.gecko.driver", Constant.GECKO_DRIVER_DIRECTORY);
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
}
if("ie".equalsIgnoreCase(file.getBrowser())){
System.setProperty("webdriver.ie.driver", Constant.IE_DRIVER_DIRECTORY);
driver = new InternetExplorerDriver();
}
}
}
答案 0 :(得分:0)
已修复升级至 Selenium版本:3.4.0