org.openqa.selenium.chrome.ChromeOptions Java Examples
The following examples show how to use
org.openqa.selenium.chrome.ChromeOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebDriverFactory.java From vividus with Apache License 2.0 | 7 votes |
@Override public WebDriver getRemoteWebDriver(DesiredCapabilities desiredCapabilities) { DesiredCapabilities mergedDesiredCapabilities = getWebDriverCapabilities(false, desiredCapabilities); WebDriverType webDriverType = WebDriverManager.detectType(mergedDesiredCapabilities); Capabilities capabilities = mergedDesiredCapabilities; if (webDriverType != null) { webDriverType.prepareCapabilities(mergedDesiredCapabilities); if (webDriverType == WebDriverType.CHROME) { WebDriverConfiguration configuration = getWebDriverConfiguration(webDriverType, false); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments(configuration.getCommandLineArguments()); configuration.getExperimentalOptions().forEach(chromeOptions::setExperimentalOption); capabilities = chromeOptions.merge(mergedDesiredCapabilities); } } return createWebDriver(remoteWebDriverFactory.getRemoteWebDriver(remoteDriverUrl, capabilities)); }
Example #2
Source File: DriverFactory.java From qa-automation-samples with MIT License | 6 votes |
public static WebDriver createDriver(String mvnParameter){ if (mvnParameter == null){ System.setProperty(Browsers.CHROME_MAC.getBrowserType(), OperationSystems.MAC_OS_X.getDriversPath().concat(Browsers.CHROME_MAC.getExecutable())); ChromeOptions options = new ChromeOptions(); options.addArguments("--start-fullscreen", "--disable-gpu"); return new ChromeDriver(options); } try { String soName = getSoName(); String browserType = getBrowserTypeFromParameter(mvnParameter); System.setProperty(browserType, getDriversPath(soName).concat(getFullExecutableNameFromParameter(mvnParameter))); }catch (Exception e){ System.out.println("ERROR: Please select one of the valid browsers for the test."); Browsers.showAvaliableBrowsersOptions(); System.exit(1); } return Browsers.valueOf(mvnParameter).createDriverInstance(); }
Example #3
Source File: ChromeDriverClient.java From AndroidRobot with Apache License 2.0 | 6 votes |
public void createDriver(String pkg_name, String sn) { if(this.driver == null) { ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setExperimentalOption("androidPackage", pkg_name); // chromeOptions.setExperimentalOption("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin"); // chromeOptions.setExperimentalOption("debuggerAddress", "127.0.0.1:9222"); chromeOptions.setExperimentalOption("androidUseRunningApp", true); chromeOptions.setExperimentalOption("androidDeviceSerial", sn); // Map<String, Object> chromeOptions = new HashMap<String, Object>(); // chromeOptions.put("androidPackage", "com.eg.android.AlipayGphoneRC"); // chromeOptions.put("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.PERFORMANCE, Level.ALL); capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); // capabilities.setCapability(CapabilityType., value); if(ChromeService.getService() != null) driver = new RobotRemoteWebDriver(ChromeService.getService().getUrl(), capabilities); } }
Example #4
Source File: ChromeRecordingWebDriverContainerTest.java From testcontainers-java with MIT License | 6 votes |
@Test public void recordingTestThatShouldBeRecordedButNotPersisted() { try ( // withRecordingFileFactory { BrowserWebDriverContainer chrome = new BrowserWebDriverContainer() // } .withCapabilities(new ChromeOptions()) // withRecordingFileFactory { .withRecordingFileFactory(new CustomRecordingFileFactory()) // } ) { chrome.start(); doSimpleExplore(chrome); } }
Example #5
Source File: RemoteDesiredCapabilitiesFactory.java From jmeter-plugins-webdriver with Apache License 2.0 | 6 votes |
public static DesiredCapabilities build(RemoteCapability capability){ DesiredCapabilities desiredCapabilities; if(RemoteCapability.CHROME.equals(capability)){ ChromeOptions options = new ChromeOptions(); desiredCapabilities = DesiredCapabilities.chrome(); desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options); return desiredCapabilities; } else if (RemoteCapability.FIREFOX.equals(capability)){ FirefoxProfile profile = new FirefoxProfile(); desiredCapabilities = DesiredCapabilities.firefox(); desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile); return desiredCapabilities; } else if (RemoteCapability.INTERNET_EXPLORER.equals(capability)){ desiredCapabilities = DesiredCapabilities.internetExplorer(); return desiredCapabilities; } else if (RemoteCapability.PHANTOMJS.equals(capability)){ desiredCapabilities = DesiredCapabilities.phantomjs(); return desiredCapabilities; } throw new IllegalArgumentException("No such capability"); }
Example #6
Source File: AaarghFirefoxWhyDostThouMockMe.java From webDriverExperiments with MIT License | 6 votes |
@Test public void simpleUserInteractionInGoogleChrome(){ String currentDir = System.getProperty("user.dir"); // amend this for your location of chromedriver String chromeDriverLocation = currentDir + "/../tools/chromedriver/chromedriver.exe"; System.setProperty("webdriver.chrome.driver", chromeDriverLocation); ChromeOptions options = new ChromeOptions(); options.addArguments("disable-plugins"); options.addArguments("disable-extensions"); driver = new ChromeDriver(options); checkSimpleCtrlBInteractionWorks(); }
Example #7
Source File: WebDriverCreator.java From webtau with Apache License 2.0 | 6 votes |
private static ChromeDriver createChromeDriver() { ChromeOptions options = new ChromeOptions(); if (BrowserConfig.getChromeBinPath() != null) { options.setBinary(BrowserConfig.getChromeBinPath().toFile()); } if (BrowserConfig.getChromeDriverPath() != null) { System.setProperty(CHROME_DRIVER_PATH_KEY, BrowserConfig.getChromeDriverPath().toString()); } if (BrowserConfig.isHeadless()) { options.addArguments("--headless"); options.addArguments("--disable-gpu"); } if (System.getProperty(CHROME_DRIVER_PATH_KEY) == null) { setupDriverManagerConfig(); downloadDriverMessage("chrome"); WebDriverManager.chromedriver().setup(); } return new ChromeDriver(options); }
Example #8
Source File: StabilityTest.java From webdrivermanager-examples with Apache License 2.0 | 6 votes |
@Test public void test() throws InterruptedException { CountDownLatch latch = new CountDownLatch(NUM_THREADS); ExecutorService executorService = newFixedThreadPool(NUM_THREADS); for (int i = 0; i < NUM_THREADS; i++) { executorService.submit(() -> { try { WebDriverManager.chromedriver().setup(); ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); WebDriver driver = new ChromeDriver(options); driver.get( "https://bonigarcia.github.io/selenium-jupiter/"); String title = driver.getTitle(); System.out.println(title); driver.quit(); } finally { latch.countDown(); } }); } latch.await(); executorService.shutdown(); }
Example #9
Source File: ChromeDevice.java From agent with MIT License | 6 votes |
@Override protected Capabilities newCaps(Capabilities capsToMerge) { ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--ignore-certificate-errors"); chromeOptions.addArguments("no-default-browser-check"); // **** 以上capabilities可被传入的caps覆盖 **** chromeOptions.merge(capsToMerge); // **** 以下capabilities具有更高优先级,将覆盖传入的caps **** if (!StringUtils.isEmpty(browser.getPath())) { chromeOptions.setBinary(browser.getPath()); } return chromeOptions; }
Example #10
Source File: DefaultSessionFactory.java From JTAF-ExtWebDriver with Apache License 2.0 | 6 votes |
private ChromeOptions setChromeOptions(ClientProperties properties){ HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); // for downloading with Chrome if(properties.getDownloadFolder() != null) { chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", properties.getDownloadFolder()); } if(properties.shouldEnableFlash()) { chromePrefs.put("profile.default_content_setting_values.plugins",1); chromePrefs.put("profile.content_settings.plugin_whitelist.adobe-flash-player",1); chromePrefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player",1); } ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setExperimentalOption("prefs", chromePrefs); return chromeOptions; }
Example #11
Source File: SearchTestWithChromeMobileEmulation.java From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License | 6 votes |
@BeforeMethod public void setup() { System.setProperty("webdriver.chrome.driver", "./src/test/resources/drivers/chromedriver"); Map<String, Object> deviceMetrics = new HashMap<>(); deviceMetrics.put("width", 411); deviceMetrics.put("height", 823); deviceMetrics.put("pixelRatio", 3.0); Map<String, Object> mobileEmulation = new HashMap<>(); mobileEmulation.put("deviceMetrics", deviceMetrics); mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 8.0.0;" + "Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/67.0.3396.99 Mobile Safari/537.36"); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation); driver = new ChromeDriver(chromeOptions); driver.get("http://demo-store.seleniumacademy.com/"); }
Example #12
Source File: ScriptFinder.java From burp-javascript-security-extension with GNU General Public License v3.0 | 6 votes |
/** * Start the Selenium chrome driver instance with lean options */ public void startDriver(){ if (serviceManager != null){ ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); options.addArguments("--no-sandbox"); options.addArguments("--disable-dev-shm-usage"); HashMap<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.managed_default_content_settings.images", 2); options.setExperimentalOption("prefs", prefs); driver = new RemoteWebDriver(serviceManager.getService().getUrl(), options); driver.manage().timeouts().implicitlyWait(PAGE_WAIT_TIMEOUT, TimeUnit.SECONDS); // Wait for the page to be completely loaded. Or reasonably loaded. } else { System.err.println("[JS-SRI][-] You must set a driver service manager before you can start a driver."); } }
Example #13
Source File: LiveWebPageITCase.java From charles with BSD 3-Clause "New" or "Revised" License | 5 votes |
private WebDriver webDriver() { final ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setBinary(System.getProperty("google.chrome")); chromeOptions.addArguments("--headless"); chromeOptions.addArguments("--disable-gpu"); final DesiredCapabilities dc = new DesiredCapabilities(); dc.setJavascriptEnabled(true); dc.setCapability( ChromeOptions.CAPABILITY, chromeOptions ); return new ChromeDriver(dc); }
Example #14
Source File: ChromeHeadlessTest.java From webdrivermanager-examples with Apache License 2.0 | 5 votes |
@Before public void setupTest() { ChromeOptions options = new ChromeOptions(); // Tested in Google Chrome 59 on Linux. More info on: // https://developers.google.com/web/updates/2017/04/headless-chrome options.addArguments("--headless"); options.addArguments("--disable-gpu"); driver = new ChromeDriver(options); }
Example #15
Source File: SetProxyForWebDriver.java From neodymium-library with MIT License | 5 votes |
@Test public void testChrome() { DesiredCapabilities capabilities = createCapabilitiesWithProxy(); ChromeOptions options = new ChromeOptions(); options.merge(capabilities); Assert.assertTrue(options.getCapability(CapabilityType.PROXY) != null); }
Example #16
Source File: ChromeUser.java From openvidu with Apache License 2.0 | 5 votes |
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options) { super(userName, timeOfWaitInSeconds); options.setAcceptInsecureCerts(true); options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE); options.addArguments("--disable-infobars"); options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"}); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.media_stream_mic", 1); prefs.put("profile.default_content_setting_values.media_stream_camera", 1); options.setExperimentalOption("prefs", prefs); String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME"); if (REMOTE_URL != null) { log.info("Using URL {} to connect to remote web driver", REMOTE_URL); try { this.driver = new RemoteWebDriver(new URL(REMOTE_URL), options); } catch (MalformedURLException e) { e.printStackTrace(); } } else { log.info("Using local web driver"); this.driver = new ChromeDriver(options); } this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.configureDriver(); }
Example #17
Source File: SeleniumTestUtilities.java From Spring-Security-Third-Edition with MIT License | 5 votes |
public static WebDriver getChromeDriver(String pathToChromeExecutable) { String path = System.getProperty("user.dir") + "\\Drivers\\chromedriver.exe"; System.setProperty("webdriver.chrome.driver",path); Map<String, Object> chromeOptions = new HashMap<String, Object>(); chromeOptions.put("binary", pathToChromeExecutable); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); return new ChromeDriver(capabilities); }
Example #18
Source File: SeleniumExtension.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private WebDriver getChromeWebDriver() { if (System.getenv(CIProperties.CHROME_DRIVER) != null) { ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setBinary("/usr/bin/google-chrome-stable"); chromeOptions.setHeadless(true); chromeOptions.setCapability(SUPPORTS_JAVASCRIPT, true); return new ChromeDriver(chromeOptions); } else { return new ChromeDriver(); } }
Example #19
Source File: ChromeDriverOptions.java From functional-tests-core with Apache License 2.0 | 5 votes |
public ChromeOptions loadChromeDriverOptions(WebSettings webSettings) { ChromeOptions options = new ChromeOptions(); if (webSettings.platform == PlatformType.VSCode) { options.setBinary(this.getFileLocation("code")); } else { } //String chromeDriverFullPath = OSUtils.runProcess("which chromedriver"); //System.setProperty("webdriver.chrome.driver", "/usr/local/Cellar/chromedriver/2.22/bin/chromedriver"); return options; }
Example #20
Source File: WebDriverFactoryImpl.java From IridiumApplicationTesting with MIT License | 5 votes |
private ChromeOptions buildChromeOptions() { final ChromeOptions options = new ChromeOptions(); final Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("credentials_enable_service", false); prefs.put("password_manager_enabled", false); options.setExperimentalOption("prefs", prefs); SYSTEM_PROPERTY_UTILS.getPropertyAsOptional(Constants.CHROME_EXECUTABLE_LOCATION_SYSTEM_PROPERTY) .ifPresent(options::setBinary); return options; }
Example #21
Source File: FlakyContainerCreationTest.java From testcontainers-java with MIT License | 5 votes |
@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(); } }
Example #22
Source File: Selenium3xTest.java From testcontainers-java with MIT License | 5 votes |
@Test public void testAdditionalStartupString() { try (BrowserWebDriverContainer chrome = new BrowserWebDriverContainer("selenium/standalone-chrome-debug:" + tag) .withCapabilities(new ChromeOptions())) { chrome.start(); } }
Example #23
Source File: BrowserDriver.java From SWET with MIT License | 5 votes |
private static DesiredCapabilities capabilitiesAndroid() { DesiredCapabilities capabilities = DesiredCapabilities.chrome(); Map<String, String> mobileEmulation = new HashMap<>(); mobileEmulation.put("deviceName", "Google Nexus 5"); Map<String, Object> chromeOptions = new HashMap<>(); chromeOptions.put("mobileEmulation", mobileEmulation); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); return capabilities; }
Example #24
Source File: LambdaWebDriverFactory.java From lambda-selenium with MIT License | 5 votes |
private ChromeOptions getLambdaChromeOptions() { ChromeOptions options = new ChromeOptions(); options.setBinary(getLibLocation("chrome")); options.addArguments("--disable-gpu"); options.addArguments("--headless"); options.addArguments("--window-size=1366,768"); options.addArguments("--single-process"); options.addArguments("--no-sandbox"); options.addArguments("--user-data-dir=/tmp/user-data"); options.addArguments("--data-path=/tmp/data-path"); options.addArguments("--homedir=/tmp"); options.addArguments("--disk-cache-dir=/tmp/cache-dir"); return options; }
Example #25
Source File: W3CRemoteDriverTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void shouldSetCapabilityToOptionsAddedAfterTheCallToSetCapabilities() { RemoteWebDriverBuilder builder = RemoteWebDriver.builder() .addAlternative(new FirefoxOptions()) .setCapability("se:cheese", "brie") .addAlternative(new ChromeOptions()); // We expect the global to be in the "alwaysMatch" section for obvious reasons, but that's not // a requirement. Get the capabilities and check each of them. List<Capabilities> allCaps = listCapabilities(builder); assertThat(allCaps).hasSize(2); assertThat(allCaps.get(0).getCapability("se:cheese")).isEqualTo("brie"); assertThat(allCaps.get(1).getCapability("se:cheese")).isEqualTo("brie"); }
Example #26
Source File: ChromeCaps.java From teasy with MIT License | 5 votes |
@SuppressWarnings("unchecked") // Just in case getCapability return value type changes in future versions public ChromeOptions get() { ChromeOptions chromeOptions = getChromeOptions(); if (!this.customCaps.asMap().isEmpty()) { chromeOptions.merge(this.customCaps); // This is a workaround for ChromeOptions.merge() issue when passed arguments are not being assigned properly Map<String, Object> chromeCapability = (Map<String, Object>) chromeOptions.getCapability(ChromeOptions.CAPABILITY); List<String> arguments = (List<String>) chromeCapability.get("args"); arguments.forEach(chromeOptions::addArguments); } return chromeOptions; }
Example #27
Source File: SystemCompatibilityTests.java From elepy with Apache License 2.0 | 5 votes |
@BeforeAll public static void startBrowser() { final var headlessMode = Boolean.parseBoolean(System.getProperty("headlessMode")); final var chromeOptions = new ChromeOptions(); if (headlessMode) { chromeOptions.addArguments("--no-sandbox", "--window-size=1920,1000", "disable-infobars", "--disable-extensions", "--disable-gpu", "--disable-dev-shm-usage", "--headless"); } chromeDriver = new ChromeDriver(chromeOptions); }
Example #28
Source File: AbstractEmptyDBSystemTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { ChromeOptions options = new ChromeOptions(); /* * This is hard- coded but we cannot do otherwise. The alternative would * be to run a docker grid */ driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); /* * Many suggests to define the size. If you tests requires a different * setting (i.e., MobileApp), change this */ driver.manage().window().setSize(new Dimension(1024, 768)); /* * This is important: docker-compose randomly assign ports and names to * those logical entities so we get them from the rule */ // DockerPort frontend = docker.containers().container("frontend").port(8080); /* * For some reason, I cannot link selenium with codedefender frontend * using docker compose. Since we cannot connect to "localhost" from * within the selenium-chrome, we rely on the host.docker.internal * (internal Docker DNS) to find out where codedefenders runs */ // String codeDefendersHome = frontend.inFormat("http://host.docker.internal:$EXTERNAL_PORT/codedefenders"); codeDefendersHome = "http://frontend:8080/codedefenders"; // driver.get(codeDefendersHome); }
Example #29
Source File: WebDriverFactory.java From dropwizard-experiment with MIT License | 5 votes |
/** * Create a Chrome WebDriver instance. * @return The WebDriver */ public static EventFiringWebDriver createChrome() { String chromeDriverBinary = WebDriverBinaryFinder.findChromeDriver(); System.setProperty("webdriver.chrome.driver", chromeDriverBinary); log.info("Using ChromeDriver binary from {}", chromeDriverBinary); // Prevent annoying yellow warning bar from being displayed. ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("excludeSwitches", ImmutableList.of("ignore-certificate-errors")); DesiredCapabilities caps = getCapabilities(); caps.setCapability(ChromeOptions.CAPABILITY, options); return withReports(new ChromeDriver(caps)); }
Example #30
Source File: RemoteDriverConfigTest.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
@Test public void shouldHaveProxyInCapability() { final Capabilities capabilities = config.createCapabilities(); assertThat(capabilities.getCapability(CapabilityType.PROXY), is(notNullValue())); assertThat(capabilities.getCapability(ChromeOptions.CAPABILITY), is(notNullValue())); assertThat(capabilities.isJavascriptEnabled(), is(true)); }