List of usage examples for org.openqa.selenium.chrome ChromeOptions CAPABILITY
String CAPABILITY
To view the source code for org.openqa.selenium.chrome ChromeOptions CAPABILITY.
Click Source Link
From source file:org.aludratest.service.gui.web.selenium.selenium2.Selenium2Driver.java
License:Apache License
/** @param url the URL for which to create a WebDriver instance. * @param arguments Additional arguments to include for the WebDriver instance, or an empty array. * @return a freshly created instance of the related WebDriver class */ public WebDriver newRemoteDriver(URL url, String[] arguments) { AludraSeleniumHttpCommandExecutor executor = new AludraSeleniumHttpCommandExecutor(url); DesiredCapabilities caps = capabilities; if (arguments != null && arguments.length > 0) { caps = new DesiredCapabilities(capabilities); // this looks strange, but is the only way to avoid having all Threads sharing the same ChromeOptions object ChromeOptions opts = (ChromeOptions) createChromeCaps().getCapability(ChromeOptions.CAPABILITY); if (opts != null) { opts.addArguments(arguments); caps.setCapability(ChromeOptions.CAPABILITY, opts); }//w w w . jav a 2s . c o m } try { RemoteWebDriver driver = new RemoteWebDriver(executor, caps); driver.setFileDetector(new LocalFileDetector()); return driver; } catch (WebDriverException e) { LoggerFactory.getLogger(Selenium2Driver.class).error( "Could not create remote web driver. Last remote HTTP response: " + executor.getLastResponse()); throw e; } }
From source file:org.aludratest.service.gui.web.selenium.selenium2.Selenium2Driver.java
License:Apache License
private static DesiredCapabilities createChromeCaps() { DesiredCapabilities caps = DesiredCapabilities.chrome(); ChromeOptions opts = new ChromeOptions(); opts.addArguments("--disable-extensions"); caps.setCapability(ChromeOptions.CAPABILITY, opts); return caps;/*w w w . j a v a2s .co m*/ }
From source file:org.apache.archiva.web.test.tools.WebdriverUtility.java
License:Apache License
public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort, boolean seleniumRemote) { log.info("WebDriver {}, {}, {}, {}", seleniumBrowser, seleniumHost, seleniumPort, seleniumRemote); if (seleniumRemote && StringUtils.isEmpty(seleniumHost)) { throw new IllegalArgumentException("seleniumHost must be set, when seleniumRemote=true"); }// w w w . j a v a 2s . c o m try { if (StringUtils.contains(seleniumBrowser, "chrome")) { ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); if (seleniumRemote) { DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities); } else { return new ChromeDriver(options); } } if (StringUtils.contains(seleniumBrowser, "safari")) { if (seleniumRemote) { return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.safari()); } else { return new SafariDriver(); } } if (StringUtils.contains(seleniumBrowser, "iexplore")) { if (seleniumRemote) { return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.internetExplorer()); } else { new InternetExplorerDriver(); } } if (StringUtils.contains(seleniumBrowser, "firefox")) { if (seleniumRemote) { return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.firefox()); } else { return new FirefoxDriver(); } } DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit(); capabilities.setJavascriptEnabled(true); capabilities.setVersion("firefox-52"); WebDriver driver; if (seleniumRemote) { driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities); } else { driver = new HtmlUnitDriver(capabilities) { @Override protected WebClient modifyWebClient(WebClient client) { client.getOptions().setThrowExceptionOnFailingStatusCode(false); client.getOptions().setThrowExceptionOnScriptError(false); client.getOptions().setCssEnabled(true); return client; } }; } return driver; } catch (MalformedURLException e) { throw new RuntimeException("Initializion of remote driver failed"); } }
From source file:org.apache.atlas.objectwrapper.WebDriverWrapper.java
License:Apache License
private static WebDriver appConfig(XmlTest config) { // AtlasConstants.UI_URL = config.getParameter("app_url"); String serverIP = config.getParameter("server_ip"); String serverPort = config.getParameter("server_port"); String browserName = config.getParameter("browserName"); int browserHeight = Integer.parseInt(config.getParameter("browser_window_height")); int browserWidth = Integer.parseInt(config.getParameter("browser_window_width")); DesiredCapabilities capabilities = null; if (browserName.contains("firefox")) { capabilities = DesiredCapabilities.firefox(); capabilities.setPlatform(Platform.ANY); webDriver = new FirefoxDriver(capabilities); } else if (browserName.contains("chrome") || browserName.equalsIgnoreCase("chrome")) { LOGGER.info("Configuring settings for Chrome"); // Google Chrome Driver ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-web-security"); options.addArguments("--start-maximized"); // For use with RemoteWebDriver: capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); webDriver = new ChromeDriver(capabilities); }/*from www. j a v a 2 s . c o m*/ AtlasConstants.UI_URL = "http://" + serverIP + ":" + serverPort; webDriver.manage().window().setPosition(new Point(0, 0)); Dimension dimenssion = new Dimension(browserHeight, browserWidth); webDriver.manage().window().setSize(dimenssion); return webDriver; }
From source file:org.arquillian.drone.appium.extension.webdriver.AppiumDriverFactoryTest.java
License:Apache License
@Test public void testCapabilities() throws IOException { DesiredCapabilities originalCapabilities = new DesiredCapabilities(); originalCapabilities.setCapability(PLATFORM_NAME, "android"); originalCapabilities.setCapability(BROWSER_NAME, "chrome"); originalCapabilities.setCapability("chromeArguments", CHROME_OPTIONS_VALUE); AppiumDriverFactory factory = new AppiumDriverFactory(); Capabilities newCapabilities = factory.getCapabilities(getMockedConfiguration(originalCapabilities)); assertEquals(originalCapabilities.getCapability(PLATFORM_NAME), newCapabilities.getCapability(PLATFORM_NAME)); assertEquals(originalCapabilities.getCapability(BROWSER_NAME), newCapabilities.getCapability(BROWSER_NAME)); Object chromeOptions = newCapabilities.getCapability(ChromeOptions.CAPABILITY); assertTrue(new Gson().toJson(chromeOptions).contains(CHROME_OPTIONS_VALUE)); }
From source file:org.auraframework.integration.test.util.WebDriverTestCase.java
License:Apache License
/** * Adds capabilities that request WebDriver performance logs<br/> * See https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log *//*from w w w . ja va 2 s .c om*/ private void addPerfCapabilities(DesiredCapabilities capabilities) { if (PerfUtil.hasPerfCmpTestAnnotation(this)) { // Do not reuse browser capabilities.setCapability(WebDriverProvider.REUSE_BROWSER_PROPERTY, false); LoggingPreferences performance_prefs = new LoggingPreferences(); performance_prefs.enable(LogType.PERFORMANCE, Level.ALL); capabilities.setCapability(CapabilityType.LOGGING_PREFS, performance_prefs); Map<String, Object> prefs = new HashMap<>(); prefs.put("traceCategories", "disabled-by-default-devtools.timeline"); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("perfLoggingPrefs", prefs); capabilities.setCapability(ChromeOptions.CAPABILITY, options); } }
From source file:org.auraframework.test.util.WebDriverTestCase.java
License:Apache License
/** * Adds capabilities that request WebDriver performance logs<br/> * See https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log *//* w ww . ja v a 2s .c om*/ private void addPerfCapabilities(DesiredCapabilities capabilities) { if (PerfUtil.hasPerfCmpTestAnnotation(this)) { LoggingPreferences performance_prefs = new LoggingPreferences(); performance_prefs.enable(LogType.PERFORMANCE, Level.ALL); capabilities.setCapability(CapabilityType.LOGGING_PREFS, performance_prefs); Map<String, Object> prefs = new HashMap<>(); prefs.put("traceCategories", "disabled-by-default-devtools.timeline"); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("perfLoggingPrefs", prefs); capabilities.setCapability(ChromeOptions.CAPABILITY, options); } }
From source file:org.auraframework.test.util.WebDriverUtil.java
License:Apache License
public static synchronized ChromeOptions addChromeOptions(DesiredCapabilities capabilities, Dimension windowSize) {/*from w w w.j a va 2s.c o m*/ ChromeOptions options = new ChromeOptions(); List<String> arguments = Lists.newArrayList(); arguments.add("--ignore-gpu-blacklist"); if (windowSize != null) { arguments.add("window-size=" + windowSize.width + ',' + windowSize.height); } options.addArguments(arguments); // To remove message "You are using an unsupported command-line flag: --ignore-certificate-errors. // Stability and security will suffer." // Add an argument 'test-type' options.addArguments("test-type"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return options; }
From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java
License:Open Source License
/** * Set DesiredCapabilities//from w ww . j a v a 2 s .c o m * @param tCExecution * @return * @throws CerberusException */ private DesiredCapabilities setCapabilities(TestCaseExecution tCExecution) throws CerberusException { /** * Instanciate DesiredCapabilities */ DesiredCapabilities caps = new DesiredCapabilities(); if (!StringUtil.isNullOrEmpty(tCExecution.getBrowser())) { caps = this.setCapabilityBrowser(caps, tCExecution.getBrowser(), tCExecution); } /** * Feed DesiredCapabilities with values get from Robot */ if (!StringUtil.isNullOrEmpty(tCExecution.getPlatform())) { caps.setCapability("platform", tCExecution.getPlatform()); } if (!StringUtil.isNullOrEmpty(tCExecution.getVersion())) { caps.setCapability("version", tCExecution.getVersion()); } /** * Loop on RobotCapabilities to feed DesiredCapabilities */ List<RobotCapability> additionalCapabilities = tCExecution.getCapabilities(); if (additionalCapabilities != null) { for (RobotCapability additionalCapability : additionalCapabilities) { caps.setCapability(additionalCapability.getCapability(), additionalCapability.getValue()); } } /** * if application is a mobile one, then set the "app" capability to the * application binary path */ if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("APK") || tCExecution.getApplicationObj().getType().equalsIgnoreCase("IPA")) { // Set the app capability with the application path if (tCExecution.isManualURL()) { caps.setCapability("app", tCExecution.getMyHost()); } else { caps.setCapability("app", tCExecution.getCountryEnvironmentParameters().getIp()); } } /** * Add custom capabilities */ // Maximize windows for chrome browser if ("chrome".equals(caps.getBrowserName())) { ChromeOptions options = new ChromeOptions(); options.addArguments("--kiosk"); caps.setCapability(ChromeOptions.CAPABILITY, options); } return caps; }
From source file:org.eclipse.che.selenium.core.SeleniumWebDriver.java
License:Open Source License
private RemoteWebDriver doCreateDriver(URL webDriverUrl) { DesiredCapabilities capability;/*from ww w .ja v a 2s . co m*/ switch (browser) { case GOOGLE_CHROME: LoggingPreferences loggingPreferences = new LoggingPreferences(); loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL); loggingPreferences.enable(LogType.BROWSER, Level.ALL); ChromeOptions options = new ChromeOptions(); options.addArguments("--no-sandbox"); options.addArguments("--dns-prefetch-disable"); options.addArguments("--ignore-certificate-errors"); // set parameters required for automatic download capability Map<String, Object> chromePrefs = new HashMap<>(); chromePrefs.put("download.default_directory", downloadDir); chromePrefs.put("download.prompt_for_download", false); chromePrefs.put("download.directory_upgrade", true); chromePrefs.put("safebrowsing.enabled", true); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("plugins.plugins_disabled", "['Chrome PDF Viewer']"); options.setExperimentalOption("prefs", chromePrefs); capability = DesiredCapabilities.chrome(); capability.setCapability(ChromeOptions.CAPABILITY, options); capability.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences); capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); break; default: capability = DesiredCapabilities.firefox(); capability.setCapability("dom.max_script_run_time", 240); capability.setCapability("dom.max_chrome_script_run_time", 240); } RemoteWebDriver driver = new RemoteWebDriver(webDriverUrl, capability); if (driver.getErrorHandler().isIncludeServerErrors() && driver.getCapabilities().getCapability("message") != null) { String errorMessage = format("Web driver creation error occurred: %s", driver.getCapabilities().getCapability("message")); LOG.error(errorMessage); throw new RuntimeException(errorMessage); } driver.manage().window().setSize(new Dimension(1920, 1080)); return driver; }