use of org.openqa.selenium.chrome.ChromeOptions in project selenified by Coveros.
the class TestSetup method setupDriver.
/**
* this creates the webdriver object, which will be used to interact with
* for all browser web tests
*
* @param browser - what browser is being tested on
* @param capabilities - what capabilities are being tested with
* @return WebDriver: the driver to interact with for the test
* @throws InvalidBrowserException If a browser that is not one specified in the
* Selenium.Browser class is used, this exception will be thrown
*/
public static WebDriver setupDriver(Browser browser, DesiredCapabilities capabilities) throws InvalidBrowserException {
WebDriver driver;
// check the browser
switch(browser) {
case HTMLUNIT:
capabilities.setBrowserName("htmlunit");
capabilities.setJavascriptEnabled(true);
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http").setLevel(Level.OFF);
driver = new HtmlUnitDriver(capabilities);
break;
case FIREFOX:
FirefoxDriverManager.getInstance().forceCache().setup();
FirefoxOptions firefoxOptions = new FirefoxOptions(capabilities);
if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
firefoxOptions.setHeadless(true);
}
driver = new FirefoxDriver(firefoxOptions);
break;
case CHROME:
ChromeDriverManager.getInstance().forceCache().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions = chromeOptions.merge(capabilities);
if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
chromeOptions.setHeadless(true);
}
driver = new ChromeDriver(chromeOptions);
break;
case INTERNETEXPLORER:
InternetExplorerDriverManager.getInstance().forceCache().setup();
InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions(capabilities);
driver = new InternetExplorerDriver(internetExplorerOptions);
break;
case EDGE:
EdgeDriverManager.getInstance().forceCache().setup();
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions = edgeOptions.merge(capabilities);
driver = new EdgeDriver(edgeOptions);
break;
case SAFARI:
SafariOptions safariOptions = new SafariOptions(capabilities);
driver = new SafariDriver(safariOptions);
break;
case OPERA:
OperaDriverManager.getInstance().forceCache().setup();
driver = new OperaDriver(capabilities);
break;
case PHANTOMJS:
PhantomJsDriverManager.getInstance().forceCache().setup();
driver = new PhantomJSDriver(capabilities);
break;
// if the browser is not listed, throw an error
default:
throw new InvalidBrowserException("The selected browser " + browser + " is not an applicable choice");
}
return driver;
}
use of org.openqa.selenium.chrome.ChromeOptions in project cerberus-source by cerberustesting.
the class SeleniumServerService method setCapabilityBrowser.
/**
* Instanciate DesiredCapabilities regarding the browser
*
* @param capabilities
* @param browser
* @param tCExecution
* @return
* @throws CerberusException
*/
private DesiredCapabilities setCapabilityBrowser(DesiredCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException {
try {
if (browser.equalsIgnoreCase("firefox")) {
capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("app.update.enabled", false);
try {
Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));
if (invariant.getGp2() == null) {
LOG.warn("Country selected (" + tCExecution.getCountry() + ") has no value of GP2 in Invariant table, default language set to English (en)");
profile.setPreference("intl.accept_languages", "en");
} else {
profile.setPreference("intl.accept_languages", invariant.getGp2());
}
} catch (CerberusException ex) {
LOG.warn("Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English (en)");
profile.setPreference("intl.accept_languages", "en");
}
// Set UserAgent if testCaseUserAgent or robotUserAgent is defined
String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());
if (!StringUtil.isNullOrEmpty(usedUserAgent)) {
profile.setPreference("general.useragent.override", usedUserAgent);
}
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
} else if (browser.equalsIgnoreCase("IE")) {
capabilities = DesiredCapabilities.internetExplorer();
} else if (browser.equalsIgnoreCase("chrome")) {
capabilities = DesiredCapabilities.chrome();
/**
* Add custom capabilities
*/
ChromeOptions options = new ChromeOptions();
// Maximize windows for chrome browser
options.addArguments("--start-fullscreen");
// Set UserAgent if necessary
String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());
if (!StringUtil.isNullOrEmpty(usedUserAgent)) {
options.addArguments("--user-agent=" + usedUserAgent);
}
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
} else if (browser.contains("android")) {
capabilities = DesiredCapabilities.android();
} else if (browser.contains("ipad")) {
capabilities = DesiredCapabilities.ipad();
} else if (browser.contains("iphone")) {
capabilities = DesiredCapabilities.iphone();
} else if (browser.contains("safari")) {
capabilities = DesiredCapabilities.safari();
} else {
LOG.warn("Not supported Browser : " + browser);
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
mes.setDescription(mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported"));
mes.setDescription("Not supported Browser : " + browser);
throw new CerberusException(mes);
}
} catch (CerberusException ex) {
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription()));
throw new CerberusException(mes);
}
return capabilities;
}
use of org.openqa.selenium.chrome.ChromeOptions in project opentest by mcdcorp.
the class SeleniumHelper method createDriver.
private static WebDriver createDriver() {
WebDriver webDriver = null;
DesiredCapabilities caps;
setSystemProperties();
if (config.hasProperty("selenium.seleniumServerUrl")) {
String seleniumServerUrl = config.getString("selenium.seleniumServerUrl");
Logger.info(String.format("Using remote Selenium server %s", seleniumServerUrl));
try {
caps = new DesiredCapabilities();
injectCapsFromConfig(caps);
webDriver = new RemoteWebDriver(new URL(seleniumServerUrl), caps);
} catch (Exception ex) {
throw new RuntimeException(String.format("Falied to connect to Selenium server %s", seleniumServerUrl), ex);
}
} else {
Logger.info("Using local Selenium server");
String browserName = config.getString("selenium.desiredCapabilities.browserName").toLowerCase();
switch(browserName) {
case "chrome":
setDriverExecutable(config.getString("selenium.chromeDriverExePath", null), "chrome");
caps = getCapsForBrowser("chrome");
injectCapsFromConfig(caps);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.merge(caps);
webDriver = new ChromeDriver(chromeOptions);
break;
case "edge":
setDriverExecutable(config.getString("selenium.edgeDriverExePath", null), "edge");
caps = getCapsForBrowser("edge");
injectCapsFromConfig(caps);
webDriver = new EdgeDriver(caps);
break;
case "firefox":
setDriverExecutable(config.getString("selenium.firefoxDriverExePath", null), "firefox");
caps = getCapsForBrowser("firefox");
injectCapsFromConfig(caps);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.merge(caps);
webDriver = new FirefoxDriver(firefoxOptions);
break;
case "internet explorer":
setDriverExecutable(config.getString("selenium.ieDriverExePath", null), "internet explorer");
caps = getCapsForBrowser("internet explorer");
// Avoid the browser zoom level error
caps.setCapability("ignoreZoomSetting", true);
injectCapsFromConfig(caps);
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.merge(caps);
webDriver = new InternetExplorerDriver(ieOptions);
break;
case "opera":
setDriverExecutable(config.getString("selenium.operaDriverExePath", null), "opera");
caps = getCapsForBrowser("opera");
injectCapsFromConfig(caps);
webDriver = new OperaDriver(caps);
break;
case "safari":
setDriverExecutable(config.getString("selenium.safariDriverExePath", null), "safari");
caps = getCapsForBrowser("safari");
injectCapsFromConfig(caps);
webDriver = new SafariDriver();
break;
default:
throw new RuntimeException(String.format("The \"selenium.browserName\" config property specifies a browser " + "that is invalid or not supported. The property value was \"%s\". " + "The valid values are: \"chrome\", \"edge\", \"firefox\", \"internet " + "explorer\" and \"safari\".", browserName));
}
}
webDriver.manage().timeouts().setScriptTimeout(config.getInteger("selenium.scriptTimeout", 20), TimeUnit.SECONDS);
webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
Boolean maximizeWindow = config.getBoolean("selenium.maximizeWindow", true);
if (maximizeWindow) {
try {
webDriver.manage().window().maximize();
} catch (Exception ex) {
Logger.warning(String.format("Failed to maximize browser window"), ex);
}
}
return webDriver;
}
use of org.openqa.selenium.chrome.ChromeOptions in project ifml2php by Dipiert.
the class Page_test method loadChromeDriver.
private static void loadChromeDriver() {
System.setProperty("webdriver.chrome.driver", "drivers/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
drivers.add(new ChromeDriver(chromeOptions));
}
use of org.openqa.selenium.chrome.ChromeOptions in project cia by Hack23.
the class AbstractRoleSystemTest method getWebDriver.
/**
* Gets the web driver.
*
* @return the web driver
*/
protected final synchronized WebDriver getWebDriver() {
WebDriver driver = null;
if ("firefox".equals(browser)) {
final DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
driver.manage().window().maximize();
} else if ("chrome".equals(browser)) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--allow-insecure-localhost", "--start-maximized");
driver = new ChromeDriver(chromeOptions);
} else if ("htmlunit-firefox".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else if ("htmlunit-ie11".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.INTERNET_EXPLORER);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else if ("htmlunit-edge".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.EDGE);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else if ("htmlunit-chrome".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.CHROME);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else {
fail("No valid browser parameter:" + browser);
}
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
webDriverMap.put(browser, driver);
return driver;
}
Aggregations