Java Code Examples for org.openqa.selenium.chrome.ChromeOptions#merge()

The following examples show how to use org.openqa.selenium.chrome.ChromeOptions#merge() . 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 vote down vote up
@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: ChromeDevice.java    From agent with MIT License 6 votes vote down vote up
@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 3
Source File: ChromeDriverHandler.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        ChromeOptions chromeOptions = (ChromeOptions) getOptions(parameter,
                testInstance);

        if (chromeOptions.asMap().get(CAPABILITY).toString().toLowerCase()
                .contains("chromium")) {
            WebDriverManager.chromiumdriver().setup();
        }

        if (capabilities.isPresent()) {
            chromeOptions.merge(capabilities.get());
        }

        object = new ChromeDriver(chromeOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example 4
Source File: TestChromeDriver.java    From selenium with Apache License 2.0 6 votes vote down vote up
private static ChromeOptions chromeWithCustomCapabilities(Capabilities originalCapabilities) {
  ChromeOptions options = new ChromeOptions();
  options.addArguments("disable-extensions", "disable-infobars", "disable-breakpad");
  Map<String, Object> prefs = new HashMap<>();
  prefs.put("exit_type", "None");
  prefs.put("exited_cleanly", true);
  options.setExperimentalOption("prefs", prefs);
  String chromePath = System.getProperty("webdriver.chrome.binary");
  if (chromePath != null) {
    options.setBinary(new File(chromePath));
  }

  if (originalCapabilities != null) {
    options.merge(originalCapabilities);
  }

  return options;
}
 
Example 5
Source File: SelenideMultiTest.java    From healenium-web with Apache License 2.0 5 votes vote down vote up
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    Configuration.timeout = 15000;

    WebDriverManager.chromedriver().setup();
    capabilities.setBrowserName("chrome");
    ChromeOptions options = new ChromeOptions();
    options.setHeadless(true);
    options.merge(capabilities);
    WebDriver wd = new ChromeDriver(options);
    return SelfHealingDriver.create(wd);
}
 
Example 6
Source File: SelenideTest.java    From healenium-web with Apache License 2.0 5 votes vote down vote up
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    capabilities.setBrowserName("chrome");
    ChromeOptions options = new ChromeOptions();
    options.setHeadless(true);
    options.merge(capabilities);
    WebDriver wd = new ChromeDriver(options);
    return SelfHealingDriver.create(wd);
}
 
Example 7
Source File: ChromeCaps.java    From teasy with MIT License 5 votes vote down vote up
@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 8
Source File: SetProxyForWebDriver.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testChrome()
{
    DesiredCapabilities capabilities = createCapabilitiesWithProxy();
    ChromeOptions options = new ChromeOptions();
    options.merge(capabilities);

    Assert.assertTrue(options.getCapability(CapabilityType.PROXY) != null);
}
 
Example 9
Source File: ChromeDriverHandler.java    From selenium-jupiter with Apache License 2.0 5 votes vote down vote up
@Override
public MutableCapabilities getOptions(Parameter parameter,
        Optional<Object> testInstance)
        throws IOException, IllegalAccessException {
    ChromeOptions chromeOptions = new ChromeOptions();

    if (parameter != null) {
        // @Arguments
        Arguments arguments = parameter.getAnnotation(Arguments.class);
        if (arguments != null) {
            stream(arguments.value()).forEach(chromeOptions::addArguments);
        }

        // @Extensions
        Extensions extensions = parameter.getAnnotation(Extensions.class);
        if (extensions != null) {
            for (String extension : extensions.value()) {
                chromeOptions.addExtensions(getExtension(extension));
            }
        }

        // @Binary
        Binary binary = parameter.getAnnotation(Binary.class);
        if (binary != null) {
            chromeOptions.setBinary(binary.value());
        }

        // @Options
        ChromeOptions optionsFromAnnotatedField = annotationsReader
                .getFromAnnotatedField(testInstance, Options.class,
                        ChromeOptions.class);
        if (optionsFromAnnotatedField != null) {
            chromeOptions = optionsFromAnnotatedField.merge(chromeOptions);
        }
    }

    return chromeOptions;
}
 
Example 10
Source File: WebDriverFactory.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private static ChromeOptions getChromeEmulatorCaps(DesiredCapabilities caps, String deviceName) {
      Map<String, String> mobileEmulation = new HashMap<>();
      mobileEmulation.put("deviceName", deviceName);
      ChromeOptions chromeOptions = new ChromeOptions();
      chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
chromeOptions.merge(caps);
      //caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
      return chromeOptions;
  }
 
Example 11
Source File: WebDriverFactory.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private static ChromeOptions getChromeUAECaps(DesiredCapabilities caps, Emulator emulator) {
      ChromeOptions chromeOptions = new ChromeOptions();
      if (!emulator.getUserAgent().trim().isEmpty()) {
          chromeOptions.addArguments("--user-agent=" + emulator.getUserAgent());
      }
chromeOptions.merge(caps);
      //caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
      return chromeOptions;
  }
 
Example 12
Source File: CustomDriverProvider.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Устанавливает ChromeOptions для запуска google chrome эмулирующего работу мобильного устройства (по умолчанию nexus 5)
 * Название мобильного устройства (device) может быть задано через системные переменные
 *
 * @return ChromeOptions
 */
private ChromeOptions getMobileChromeOptions(DesiredCapabilities capabilities) {
    log.info("---------------run CustomMobileDriver---------------------");
    String mobileDeviceName = loadSystemPropertyOrDefault("device", "Nexus 5");
    ChromeOptions chromeOptions = new ChromeOptions().addArguments("disable-extensions",
        "test-type", "no-default-browser-check", "ignore-certificate-errors");

    Map<String, String> mobileEmulation = new HashMap<>();
    chromeOptions.setHeadless(getHeadless());
    mobileEmulation.put("deviceName", mobileDeviceName);
    chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
    chromeOptions.merge(capabilities);
    return chromeOptions;
}
 
Example 13
Source File: CustomDriverProvider.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Задает options для запуска Chrome драйвера
 * options можно передавать, как системную переменную, например -Doptions=--load-extension=my-custom-extension
 *
 * @return ChromeOptions
 */
private ChromeOptions getChromeDriverOptions(DesiredCapabilities capabilities) {
    log.info("---------------Chrome Driver---------------------");
    ChromeOptions chromeOptions = !options[0].equals("") ? new ChromeOptions().addArguments(options) : new ChromeOptions();
    chromeOptions.setCapability(CapabilityType.BROWSER_VERSION, loadSystemPropertyOrDefault(CapabilityType.BROWSER_VERSION, VERSION_LATEST));
    chromeOptions.setHeadless(getHeadless());
    chromeOptions.merge(capabilities);
    return chromeOptions;
}