下面列出了org.openqa.selenium.firefox.FirefoxBinary#setEnvironmentProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public FirefoxDriver makeObject() throws Exception {
FirefoxBinary ffBinary = new FirefoxBinary();
if (System.getProperty(DISPLAY_PROPERTY_KEY) != null) {
Logger.getLogger(this.getClass()).info("Setting Xvfb display with value " + System.getProperty(DISPLAY_PROPERTY_KEY));
ffBinary.setEnvironmentProperty("DISPLAY", System.getProperty(DISPLAY_PROPERTY_KEY));
}
FirefoxDriver fd = new FirefoxDriver(ffBinary, ProfileFactory.getInstance().getScenarioProfile());
if (this.implicitelyWaitDriverTimeout != null) {
fd.manage().timeouts().implicitlyWait(this.implicitelyWaitDriverTimeout.longValue(), TimeUnit.SECONDS);
}
if (this.pageLoadDriverTimeout != null) {
fd.manage().timeouts().pageLoadTimeout(this.pageLoadDriverTimeout.longValue(), TimeUnit.SECONDS);
}
return fd;
}
/**
*
* @param config
* @return A FirefoxDriver.
*/
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
FirefoxBinary ffBinary = new FirefoxBinary();
if (System.getProperty(DISPLAY_PROPERTY) != null) {
ffBinary.setEnvironmentProperty(
DISPLAY_PROPERTY.toUpperCase(),
System.getProperty(DISPLAY_PROPERTY));
} else if (System.getenv(DISPLAY_PROPERTY.toUpperCase()) != null) {
ffBinary.setEnvironmentProperty(
DISPLAY_PROPERTY.toUpperCase(),
System.getenv(DISPLAY_PROPERTY.toUpperCase()));
}
RemoteWebDriver remoteWebDriver = new FirefoxDriver(ffBinary, firefoxProfile);
if (screenHeight != -1 && screenWidth!= -1) {
remoteWebDriver.manage().window().setSize(new Dimension(screenWidth, screenHeight));
}
return remoteWebDriver;
}
@Override
public WebDriver createWebDriver(String webDriverPath) {
FirefoxBinary ffox = new FirefoxBinary();
if ("true".equals(System.getenv("TRAVIS"))) {
// xvfb is supposed to run with DISPLAY 99
ffox.setEnvironmentProperty("DISPLAY", ":99");
}
ffox.addCommandLineOptions("--headless");
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir",
FileUtils.getTempDirectory().toString() + "/firefox/");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("app.update.auto", false);
profile.setPreference("app.update.enabled", false);
profile.setPreference("dom.max_script_run_time", 0);
profile.setPreference("dom.max_chrome_script_run_time", 0);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
profile.setPreference("network.proxy.type", 0);
System.setProperty(
GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, webDriverPath);
System.setProperty(
FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(ffox);
firefoxOptions.setProfile(profile);
firefoxOptions.setLogLevel(FirefoxDriverLogLevel.TRACE);
return new FirefoxDriver(firefoxOptions);
}
private FirefoxDriver createFirefoxDriver(String display, String binaryPath,
DesiredCapabilities desiredCapabilities)
{
FirefoxProfile profile = createDefaultFirefoxProfile();
FirefoxBinary binary = !StringUtils.isBlank(binaryPath) ? new FirefoxBinary(new File(binaryPath))
: new FirefoxBinary();
LOG.info("Binding to {} display", display);
availableDisplays.compute(display, (d, value) -> value == null ? 1 : value + 1);
binary.setEnvironmentProperty(DISPLAY, display);
LOG.info("Firefox path is: {}", binaryPath);
return openFirefoxDriver(desiredCapabilities, profile, binary);
}