use of org.openqa.selenium.chrome.ChromeOptions in project acceptance-test-harness by jenkinsci.
the class FallbackConfig method createWebDriver.
private WebDriver createWebDriver(TestName testName) throws IOException {
String browser = System.getenv("BROWSER");
if (browser == null)
browser = "firefox";
browser = browser.toLowerCase(Locale.ENGLISH);
String display = getBrowserDisplay();
switch(browser) {
case "firefox":
FirefoxProfile profile = new FirefoxProfile();
profile.setAlwaysLoadNoFocusLib(true);
profile.setPreference(LANGUAGE_SELECTOR, "en");
// Config screen with many plugins can cause FF to complain JS takes too long to complete - set longer timeout
profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
FirefoxBinary binary = new FirefoxBinary();
if (display != null) {
binary.setEnvironmentProperty("DISPLAY", display);
}
return new FirefoxDriver(binary, profile);
case "ie":
case "iexplore":
case "iexplorer":
return new InternetExplorerDriver();
case "chrome":
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", Collections.singletonMap(LANGUAGE_SELECTOR, "en"));
ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
if (display != null) {
builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
}
return new ChromeDriver(builder.build(), options);
case "safari":
return new SafariDriver();
case "htmlunit":
return new HtmlUnitDriver(true);
case "saucelabs":
case "saucelabs-firefox":
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability("version", "29");
caps.setCapability("platform", "Windows 7");
caps.setCapability("name", testName.get());
// if running inside Jenkins, expose build ID
String tag = System.getenv("BUILD_TAG");
if (tag != null)
caps.setCapability("build", tag);
return new SauceLabsConnection().createWebDriver(caps);
case "phantomjs":
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability(LANGUAGE_SELECTOR, "en");
capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
return new PhantomJSDriver(capabilities);
case "remote-webdriver-firefox":
String u = System.getenv("REMOTE_WEBDRIVER_URL");
if (StringUtils.isBlank(u)) {
throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set");
}
return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
new URL(u), DesiredCapabilities.firefox());
default:
throw new Error("Unrecognized browser type: " + browser);
}
}
use of org.openqa.selenium.chrome.ChromeOptions in project selenium_java by sergueik.
the class CommonFunctions method getSeleniumDriver.
@SuppressWarnings("deprecation")
public static WebDriver getSeleniumDriver() throws IOException {
checkEnvironment();
if (isDestopTesting) {
// For desktop browser testing, run a Selenium node and Selenium hub on
// port 4444
// For Vagrant box browser testing have localhost port 4444 forwarded to
// the hub 4444
// Alternatively make the test class launch the browser
osName = System.getProperty("os.name");
if (browser.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", new File((chromeDriverPath == null) ? osName.toLowerCase().startsWith("windows") ? "C:\\java\\selenium\\chromedriver.exe" : "/tmp/chromedriver" : chromeDriverPath).getAbsolutePath());
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("profile.default_content_settings.popups", 0);
String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("enableNetwork", "true");
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("allow-running-insecure-content");
options.addArguments("allow-insecure-localhost");
options.addArguments("enable-local-file-accesses");
options.addArguments("disable-notifications");
// options.addArguments("start-maximized");
options.addArguments("browser.download.folderList=2");
options.addArguments("--browser.helperApps.neverAsk.saveToDisk=image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf");
options.addArguments("browser.download.dir=" + downloadFilepath);
// options.addArguments("user-data-dir=/path/to/your/custom/profile");
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
seleniumDriver = new ChromeDriver(capabilities);
} else if (browser.equals("firefox")) {
// alternatively one can add Geckodriver to system path
System.setProperty("webdriver.gecko.driver", "c:/java/selenium/geckodriver.exe");
// https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// use legacy FirefoxDriver
capabilities.setCapability("marionette", false);
// http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.firefox.FirefoxProfile
capabilities.setCapability("locationContextEnabled", false);
capabilities.setCapability("acceptSslCerts", true);
capabilities.setCapability("elementScrollBehavior", 1);
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
// no longer supported as of Selenium 3.8.x
// profile.setEnableNativeEvents(false);
System.out.println(System.getProperty("user.dir"));
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
try {
// java.lang.ClassCastException:
// org.openqa.selenium.remote.service.DriverCommandExecutor cannot be
// cast to
// org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor
seleniumDriver = new FirefoxDriver(capabilities);
} catch (WebDriverException e) {
e.printStackTrace();
throw new RuntimeException("Cannot initialize Firefox driver");
}
}
} else {
DesiredCapabilities capabilities = new DesiredCapabilities("phantomjs", "", Platform.ANY);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--web-security=false", "--ssl-protocol=any", "--ignore-ssl-errors=true", "--local-to-remote-url-access=true", // prevent local file test XMLHttpRequest Exception 101
"--webdriver-loglevel=INFO" // set to DEBUG for a really verbose console output
});
seleniumDriver = new PhantomJSDriver(capabilities);
}
return seleniumDriver;
}
use of org.openqa.selenium.chrome.ChromeOptions in project selenium_java by sergueik.
the class Settings method setUp.
public void setUp() {
File file = new File(DRIVER_FILE_PATH);
System.setProperty(DRIVER_NAME, file.getAbsolutePath());
HashMap<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("profile.default_content_settings.popups", 0);
chromeOptions.put("download.default_directory", downloadFolder);
chromeOptions.put("download.prompt_for_download", false);
chromeOptions.put("--no-startup-window", true);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromeOptions);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(cap);
builder = new Actions(driver);
LOG.info("Driver setUp complete.");
}
use of org.openqa.selenium.chrome.ChromeOptions in project selenium_java by sergueik.
the class BaseTest method beforeClass.
@SuppressWarnings("deprecation")
@BeforeClass
public void beforeClass() throws IOException {
/* TODO: TripadvisorTest: observed user agent problem with firefox - mobile version of
page is rendered, and the toast message displayed with the warning:
"We noticed that you're using an unsupported browser. The TripAdvisor
website may not display properly.We support the following browsers:
Windows: Internet Explorer, Mozilla Firefox, Google Chrome. Mac:
Safari".
*/
System.err.println("Launching " + browser);
if (browser.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath());
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions chromeOptions = new ChromeOptions();
Map<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("profile.default_content_settings.popups", 0);
String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
chromePrefs.put("download.prompt_for_download", "false");
chromePrefs.put("download.directory_upgrade", "true");
chromePrefs.put("plugins.always_open_pdf_externally", "true");
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("enableNetwork", "true");
chromeOptions.setExperimentalOption("prefs", chromePrefs);
for (String optionAgrument : (new String[] { "--user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20120101 Firefox/33.0", "--allow-running-insecure-content", "--allow-insecure-localhost", "--enable-local-file-accesses", "--disable-notifications", "--disable-save-password-bubble", /* "start-maximized" , */
"--browser.download.folderList=2", "--disable-web-security", "--no-proxy-server", "--browser.helperApps.neverAsk.saveToDisk=image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf", String.format("--browser.download.dir=%s", downloadFilepath) /* "--user-data-dir=/path/to/your/custom/profile" , */
})) {
chromeOptions.addArguments(optionAgrument);
}
// chromeOptions.addArguments("user-data-dir=/path/to/your/custom/profile");
// options for headless
/*
for (String optionAgrument : (new String[] { "headless",
"window-size=1200x600", })) {
options.addArguments(optionAgrument);
}
*/
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
capabilities.setCapability(org.openqa.selenium.chrome.ChromeOptions.CAPABILITY, chromeOptions);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
loadChromeExtensionsBase64Encoded(chromeOptions);
// see also:
// https://github.com/pulkitsinghal/selenium/blob/master/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java
// For use with RemoteWebDriver
/*
RemoteWebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"), capabilities);
*/
driver = new ChromeDriver(capabilities);
} else if (browser.equals("firefox")) {
// https://developer.mozilla.org/en-US/Firefox/Headless_mode
// 3.5.3 and later
System.setProperty("webdriver.gecko.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/geckodriver.exe").getAbsolutePath() : "/tmp/geckodriver");
System.setProperty("webdriver.firefox.bin", osName.toLowerCase().startsWith("windows") ? new File("c:/Program Files (x86)/Mozilla Firefox/firefox.exe").getAbsolutePath() : "/usr/bin/firefox");
// https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// use legacy FirefoxDriver
capabilities.setCapability("marionette", false);
// http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.firefox.FirefoxProfile
capabilities.setCapability("locationContextEnabled", false);
capabilities.setCapability("acceptSslCerts", true);
capabilities.setCapability("elementScrollBehavior", 1);
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
profile.setEnableNativeEvents(false);
// optional
/*
profile.setPreference("general.useragent.override",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20120101 Firefox/33.0");
*/
// System.out.println(System.getProperty("user.dir"));
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
try {
driver = new FirefoxDriver(capabilities);
} catch (WebDriverException e) {
e.printStackTrace();
throw new RuntimeException("Cannot initialize Firefox driver");
}
}
actions = new Actions(driver);
driver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);
// Declare a wait time
wait = new WebDriverWait(driver, flexibleWait);
wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
screenshot = ((TakesScreenshot) driver);
js = ((JavascriptExecutor) driver);
// driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(implicitWait, TimeUnit.SECONDS);
// Go to URL
driver.get(baseURL);
}
use of org.openqa.selenium.chrome.ChromeOptions in project irida by phac-nml.
the class IntegrationUITestListener method startWebDriver.
/**
* Start the web driver.
*/
public static void startWebDriver() {
ChromeOptions options = new ChromeOptions();
/*
* Run chrome in no sandbox mode. Only use this option for running tests
* in docker containers.
*/
String noSandbox = System.getProperty("irida.it.nosandbox");
if (noSandbox != null && noSandbox.equals("true")) {
logger.warn("Running Chrome in no sandbox mode");
options.addArguments("--no-sandbox");
}
// Run chrome in headless mode
String headless = System.getProperty("irida.it.headless");
if (headless != null && headless.equals("true")) {
logger.info("Running Chome in headless mode");
options.addArguments("headless");
} else {
logger.info("Running Chome in no headless (normal) mode");
}
options.addArguments("window-size=1400x900");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(DRIVER_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
}
Aggregations