System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-extensions"); driver = new ChromeDriver(options);
@Override WebDriver create(Config config, Proxy proxy) { ChromeOptions options = createChromeOptions(config, proxy); return new ChromeDriver(options); }
private void setUpWebDriver() { ChromeOptions options = new ChromeOptions(); options.addArguments("headless"); options.addArguments("no-sandbox"); options.addArguments("window-size=1200x600"); driver = new ChromeDriver(options); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(300, TimeUnit.SECONDS); }
@Bean(destroyMethod = "quit") public ChromeDriver webDriver() { System.setProperty("webdriver.chrome.logfile", "/tmp/chromedriver.log"); System.setProperty("webdriver.chrome.verboseLogging", "true"); ChromeOptions options = new ChromeOptions(); options.addArguments( "--verbose", "--headless", "--disable-web-security", "--ignore-certificate-errors", "--allow-running-insecure-content", "--allow-insecure-localhost", "--no-sandbox", "--disable-gpu" ); LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.PERFORMANCE, Level.ALL); options.setCapability(CapabilityType.LOGGING_PREFS, logs); options.setAcceptInsecureCerts(true); ChromeDriver driver = new ChromeDriver(options); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(15, TimeUnit.SECONDS); driver.manage().window().setSize(new Dimension(1024, 768)); return driver; }
ChromeOptions createChromeOptions(Config config, Proxy proxy) { ChromeOptions options = new ChromeOptions(); options.setHeadless(config.headless()); if (!config.browserBinary().isEmpty()) { log.info("Using browser binary: " + config.browserBinary()); options.setBinary(config.browserBinary()); } options.merge(createCommonCapabilities(config, proxy)); options = transferChromeOptionsFromSystemProperties(options); log.config("Chrome options:" + options.toString()); return options; }
public static DesiredCapabilities getBrowserCapabilities(String driverParameter, boolean headless) { DesiredCapabilities capabilities = null; if (driverParameter == null || driverParameter.equalsIgnoreCase(FIREFOX)) { capabilities = DesiredCapabilities.firefox(); FirefoxOptions options = new FirefoxOptions(); options.setHeadless(headless); capabilities.merge(options); } else if (driverParameter.equalsIgnoreCase(IE)) { capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true); } else if (driverParameter.equalsIgnoreCase(CHROME)) { capabilities = DesiredCapabilities.chrome(); ChromeOptions options = new ChromeOptions(); options.setHeadless(headless); options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation")); capabilities.merge(options); } return capabilities; }
ChromeDriver driver = new ChromeDriver(); driver.get("file://empty-page.html"); String innerHtml = "<head>...</head><body onload="...">...</body>"; driver.executeScript("document.innerHTML = " + innerHtml);
@Test public void testAdditionalStartupString() { try (BrowserWebDriverContainer chrome = new BrowserWebDriverContainer("selenium/standalone-chrome-debug:" + tag) .withCapabilities(new ChromeOptions())) { chrome.start(); } } }
Capabilities getBrowserBinaryCapabilities(Config config, Browser browser) { log.info("Using browser binary: " + config.browserBinary()); if (browser.isChrome()) { ChromeOptions options = new ChromeOptions(); options.setBinary(config.browserBinary()); return options; } else if (browser.isFirefox()) { FirefoxOptions options = new FirefoxOptions(); options.setBinary(config.browserBinary()); return options; } else { log.warning("Changing browser binary on remote server is only supported for Chrome/Firefox, setting will be ignored."); } return new DesiredCapabilities(); }
private Capabilities getHeadlessCapabilities(Config config, Browser browser) { log.info("Starting in headless mode"); if (browser.isChrome()) { ChromeOptions options = new ChromeOptions(); options.setHeadless(config.headless()); return options; } else if (browser.isFirefox()) { FirefoxOptions options = new FirefoxOptions(); options.setHeadless(config.headless()); return options; } else { log.warning("Headless mode on remote server is only supported for Chrome/Firefox, setting will be ignored."); } return new DesiredCapabilities(); }
String downloadFilepath = "/path/to/download"; HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", downloadFilepath); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", chromePrefs); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); cap.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(cap);
/** * This method only handles so-called "arguments" and "preferences" * for ChromeOptions (there is also "Extensions" etc.) * * @param currentChromeOptions * @return options updated with args & prefs parameters */ private ChromeOptions transferChromeOptionsFromSystemProperties(ChromeOptions currentChromeOptions) { if (System.getProperty("chromeoptions.args") != null) { Stream<String> params = Arrays.stream(parseCSVhandlingQuotes(System.getProperty("chromeoptions.args"))); List<String> args = params .map(s -> s.replace("\"", "")) .collect(Collectors.toList()); currentChromeOptions.addArguments(args); } if (System.getProperty("chromeoptions.prefs") != null) { Map<String, Object> prefs = parsePreferencesFromString(System.getProperty("chromeoptions.prefs")); currentChromeOptions.setExperimentalOption("prefs", prefs); } return currentChromeOptions; }
ChromeOptions options = new ChromeOptions(); options.addArguments("-incognito"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options);
public static WebDriver getDriver(String browserType, boolean headless){ if ( StringUtils.isEmpty(browserType) || FIREFOX.equals(browserType)) { return new FirefoxDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType, headless)); } else if (CHROME.equals(browserType)) { return new ChromeDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType, headless)); } else if (IE.equals(browserType)) { return new InternetExplorerDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType, false)); } else if (PHANTOMJS.equals(browserType)) { return new PhantomJSDriver(); } else if (SAFARI.equals(browserType)) { return new SafariDriver(); } else if (EDGE.equals(browserType)) { return new EdgeDriver(); } else { throw new RuntimeException(String.format("Unknown browser type: \"%s\"", browserType)); } }
} else { logger().info("No capabilities provided, falling back to ChromeOptions"); capabilities = new ChromeOptions();
System.setProperty("webdriver.chrome.driver","<<your chrome path>>"); // To remove message "You are using an unsupported command-line flag: --ignore-certificate-errors. // Stability and security will suffer." // Add an argument 'test-type' DesiredCapabilities capabilities = DesiredCapabilities.chrome(); ChromeOptions options = new ChromeOptions(); options.addArguments("test-type"); capabilities.setCapability("chrome.binary","<<your chrome path>>"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(capabilities);
mDriver = new FirefoxDriver(sCaps); } else if (driver.equals(DRIVER_CHROME)) { mDriver = new ChromeDriver(sCaps); } else if (driver.equals(DRIVER_PHANTOMJS)) { mDriver = new PhantomJSDriver(sCaps);
@Test @Ignore public void testCreationOfManyContainers() { for (int i = 0; i < 50; i++) { BrowserWebDriverContainer container = new BrowserWebDriverContainer() .withCapabilities(new ChromeOptions()) .withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.RECORD_FAILING, new File("build")); container.start(); RemoteWebDriver driver = container.getWebDriver(); driver.get("http://www.google.com"); container.stop(); } } }
System.setProperty("webdriver.chrome.driver", "<unzip location>/chromedriver"); driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"); driver = new ChromeDriver();