当前位置: 首页>>代码示例>>Java>>正文


Java ChromeOptions类代码示例

本文整理汇总了Java中org.openqa.selenium.chrome.ChromeOptions的典型用法代码示例。如果您正苦于以下问题:Java ChromeOptions类的具体用法?Java ChromeOptions怎么用?Java ChromeOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ChromeOptions类属于org.openqa.selenium.chrome包,在下文中一共展示了ChromeOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDriver

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@Override
public WebDriver createDriver() throws Exception {
    final ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--no-sandbox");
    if (headless) {
        chromeOptions.setHeadless(true);
    }

    final Map<String, String> environmentVariables = new HashMap<>();
    if (!headless && xvfbPort != null) {
        environmentVariables.put("DISPLAY", ":" + String.valueOf(xvfbPort));
    }

    final ChromeDriverService service = new ChromeDriverService.Builder()
            .usingAnyFreePort()
            .withEnvironment(environmentVariables)
            .build();

    final WebDriver driver = new ChromeDriver(service, chromeOptions);
    manage(driver);

    return driver;
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:24,代码来源:ChromeDriverConfig.java

示例2: getChromeDesiredCapabilities

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
private DesiredCapabilities getChromeDesiredCapabilities(Settings settings) {
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        //Added to avoid yellow warning in chrome 35
        ChromeOptions options = new ChromeOptions();
//        options.addArguments("test-type");
        //For view pdf in chrome
        options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type", "--ignore-certificate-errors"));

        if (settings.isHeadlessBrowser()) {
            options.addArguments("headless");
        }

        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capabilities.setPlatform(Platform.WINDOWS);
        setAlertBehaviorCapabilities(capabilities);
        setLoggingPrefs(capabilities);
        setProxy(capabilities);
        return capabilities;
    }
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:21,代码来源:SeleniumTestExecutionListener.java

示例3: setChromeOptions

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
/**
 * Sets the target browser binary path in chromeOptions if it exists in configuration.
 *
 * @param capabilities
 *            The global DesiredCapabilities
 */
private void setChromeOptions(final DesiredCapabilities capabilities, ChromeOptions chromeOptions) {

    // Set custom downloaded file path. When you check content of downloaded file by robot.
    HashMap<String, Object> chromePrefs = new HashMap<>();
    chromePrefs.put("download.default_directory", System.getProperty("user.dir") + File.separator + "downloadFiles");
    chromeOptions.setExperimentalOption("prefs", chromePrefs);

    // Set custom chromium (if you not use default chromium on your target device)
    String targetBrowserBinaryPath = Context.getWebdriversProperties("targetBrowserBinaryPath");
    if (targetBrowserBinaryPath != null && !"".equals(targetBrowserBinaryPath)) {
        chromeOptions.setBinary(targetBrowserBinaryPath);
    }

    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:22,代码来源:DriverFactory.java

示例4: notSettingAnyProperty

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@Test
public void notSettingAnyProperty() {
    // given
    WebDriverProperties properties = new WebDriverProperties();

    // when
    Capabilities convertedCapabilities = chromeCapabilitiesConverter.convert(properties);

    // then
    // expected chrome capabilities
    ChromeOptions expectedChromeOptions = new ChromeOptions();
    expectedChromeOptions.setCapability(CAPABILITY_BROWSER_NAME, "chrome");
    expectedChromeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);

    expectedChromeOptions.addArguments("--disable-device-discovery-notifications");
    expectedChromeOptions.addArguments("--disable-infobars");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedChromeOptions.asMap());
    assertThat(convertedCapabilities).isEqualTo(expectedChromeOptions);
}
 
开发者ID:isgarlo,项目名称:givemeadriver,代码行数:21,代码来源:ChromeCapabilitiesConverterTest.java

示例5: doCreateDriver

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
private RemoteWebDriver doCreateDriver(URL webDriverUrl) {
  DesiredCapabilities capability;

  switch (browser) {
    case GOOGLE_CHROME:
      ChromeOptions options = new ChromeOptions();
      options.addArguments("--no-sandbox");
      options.addArguments("--dns-prefetch-disable");

      capability = DesiredCapabilities.chrome();
      capability.setCapability(ChromeOptions.CAPABILITY, options);
      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);
  driver.manage().window().setSize(new Dimension(1920, 1080));

  return driver;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:SeleniumWebDriver.java

示例6: getPerformanceLoggingCapabilities

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
private static DesiredCapabilities getPerformanceLoggingCapabilities() {
    DesiredCapabilities caps = DesiredCapabilities.chrome();

    // Enable performance logging
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    // Enable timeline tracing
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    Map<String, String> perfLoggingPrefs = new HashMap<String, String>();
    // Tracing categories, please note NO SPACE NEEDED after the commas
    perfLoggingPrefs.put("traceCategories", "blink.console,disabled-by-default-devtools.timeline");
    chromeOptions.put("perfLoggingPrefs", perfLoggingPrefs);
    //chromeOptions.put("debuggerAddress", "127.0.0.1:10134");
    caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    return caps;
}
 
开发者ID:hy9be,项目名称:spa-perf,代码行数:20,代码来源:SPAPerfChromeDriver.java

示例7: simpleUserInteractionInGoogleChrome

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@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();
}
 
开发者ID:eviltester,项目名称:webDriverExperiments,代码行数:17,代码来源:AaarghFirefoxWhyDostThouMockMe.java

示例8: siteUp

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@BeforeMethod
public void siteUp () {

	final String exe = "chromedriver.exe";
	final String path = getClass ().getClassLoader ()
		.getResource (exe)
		.getPath ();
	final String webSite = "http://www.naukri.com";
	final String binaryPath = "C:\\Users\\DELL\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
	
	System.setProperty("webdriver.chrome.driver", path);
	ChromeOptions chromeOpt= new ChromeOptions();
	chromeOpt.setBinary(binaryPath);
	
	driver = new ChromeDriver (chromeOpt);
	driver.get(webSite);
	driver.manage ().timeouts ().implicitlyWait (10, TimeUnit.SECONDS);
	driver.manage().window().maximize();
	windowHandling ();
}
 
开发者ID:mfaisalkhatri,项目名称:NaukriSite,代码行数:21,代码来源:Setup.java

示例9: settingAllChromeProperties

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@Test
public void settingAllChromeProperties() throws IOException {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("device", IPHONE_DEVICE);
    properties.setProperty("userAgent", ANY_USER_AGENT);
    properties.setProperty("viewportSize", "378x664");
    properties.setProperty("pixelRatio", "3.0");
    properties.setProperty("headless", "true");

    // when
    Capabilities convertedCapabilities = chromeCapabilitiesConverter.convert(properties);

    // then
    // expected chrome options
    ChromeOptions expectedChromeOptions = new ChromeOptions();
    expectedChromeOptions.setCapability(CAPABILITY_BROWSER_NAME, "chrome");
    expectedChromeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    Map<String, Object> expectedMobileEmulation = new HashMap<>();
    Map<String, Object> expectedDeviceMetrics = new HashMap<>();
    expectedDeviceMetrics.put("width", 378);
    expectedDeviceMetrics.put("height", 664);
    expectedDeviceMetrics.put(CAPABILITY_PIXEL_RATIO, 3.0);
    expectedMobileEmulation.put("deviceMetrics", expectedDeviceMetrics);
    expectedMobileEmulation.put(CAPABILITY_DEVICE_NAME, IPHONE_DEVICE);
    expectedMobileEmulation.put(CAPABILITY_USER_AGENT, ANY_USER_AGENT);
    expectedChromeOptions.setExperimentalOption("mobileEmulation", expectedMobileEmulation);
    expectedChromeOptions.addArguments("--disable-device-discovery-notifications");
    expectedChromeOptions.addArguments("--disable-infobars");
    expectedChromeOptions.addArguments("--headless", "--disable-gpu");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedChromeOptions.asMap());
}
 
开发者ID:isgarlo,项目名称:givemeadriver,代码行数:34,代码来源:ChromeCapabilitiesConverterTest.java

示例10: notSettingDeviceMetrics

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@Test
public void notSettingDeviceMetrics() throws IOException {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("device", IPHONE_DEVICE);
    properties.setProperty("userAgent", ANY_USER_AGENT);

    // when
    Capabilities convertedCapabilities = chromeCapabilitiesConverter.convert(properties);

    // then
    // expected chrome options
    ChromeOptions expectedChromeOptions = new ChromeOptions();
    Map<String, Object> expectedMobileEmulation = new HashMap<>();
    expectedChromeOptions.setCapability(CAPABILITY_BROWSER_NAME, "chrome");
    expectedChromeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    expectedMobileEmulation.put(CAPABILITY_DEVICE_NAME, IPHONE_DEVICE);
    expectedMobileEmulation.put(CAPABILITY_USER_AGENT, ANY_USER_AGENT);
    expectedChromeOptions.setExperimentalOption("mobileEmulation", expectedMobileEmulation);
    expectedChromeOptions.addArguments("--disable-device-discovery-notifications");
    expectedChromeOptions.addArguments("--disable-infobars");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedChromeOptions.asMap());
}
 
开发者ID:isgarlo,项目名称:givemeadriver,代码行数:25,代码来源:ChromeCapabilitiesConverterTest.java

示例11: createDriver

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    Map<String, Object> preferences = new Hashtable<>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.prompt_for_download", "false");
    String downloadsPath = System.getProperty("user.home") + "/Downloads";
    preferences.put("download.default_directory", loadSystemPropertyOrDefault("fileDownloadPath", downloadsPath));
    preferences.put("plugins.plugins_disabled", new String[]{
            "Adobe Flash Player", "Chrome PDF Viewer"});
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);

    capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(capabilities);
}
 
开发者ID:alfa-laboratory,项目名称:akita-testing-template,代码行数:18,代码来源:AkitaChromeDriverProvider.java

示例12: resolve

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        ChromeOptions chromeOptions = (ChromeOptions) getOptions(parameter,
                testInstance);

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

        object = new ChromeDriver(chromeOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:19,代码来源:ChromeDriverHandler.java

示例13: initialise

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
/**
 * Initialises the WebDriver (client).
 *
 * This method should be called once before each test to ensure that the session state doesn't bleed from one test
 * to another (such as user being logged in).
 */
public void initialise() {

    final ChromeOptions chromeOptions = new ChromeOptions();

    final Map<String, Object> chromePrefs = new HashMap<>();
    log.info("Setting WebDriver download directory to '{}'.", downloadDirectory);
    chromePrefs.put("download.default_directory", downloadDirectory.toAbsolutePath().toString());

    chromeOptions.setExperimentalOption("prefs", chromePrefs);
    log.info("Configuring WebDriver to run in {} mode.", isHeadlessMode ? "headless" : "full, graphical");
    if (isHeadlessMode) {
        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("window-size=1920,1080");
    }

    webDriver = new RemoteWebDriver(webDriverServiceProvider.getUrl(), chromeOptions);
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:24,代码来源:WebDriverProvider.java

示例14: newDriverForTest

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
private WebDriver newDriverForTest() {
    ChromeOptions theOptions = new ChromeOptions();
    theOptions.addArguments("headless");
    theOptions.addArguments("disable-gpu");

    LoggingPreferences theLoggingPreferences = new LoggingPreferences();
    theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
    theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);

    DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
    theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);

    return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
 
开发者ID:mirkosertic,项目名称:Bytecoder,代码行数:15,代码来源:BytecoderUnitTestRunner.java

示例15: createDriver

import org.openqa.selenium.chrome.ChromeOptions; //导入依赖的package包/类
/**
 * Создание instance google chrome эмулирующего работу на мобильном устройстве (по умолчанию nexus 5)
 * Мобильное устройство может быть задано через системные переменные
 *
 * @param capabilities настройки Chrome браузера
 * @return возвращает новый instance Chrome драйера
 */

@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    log.info("---------------run CustomMobileDriver---------------------");
    String mobileDeviceName = loadSystemPropertyOrDefault("device", "Nexus 5");
    Map<String, String> mobileEmulation = new HashMap<>();
    mobileEmulation.put("deviceName", mobileDeviceName);

    Map<String, Object> chromeOptions = new HashMap<>();
    chromeOptions.put("mobileEmulation", mobileEmulation);

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    desiredCapabilities.setBrowserName(desiredCapabilities.chrome().getBrowserName());
    return new ChromeDriver(desiredCapabilities);
}
 
开发者ID:alfa-laboratory,项目名称:akita,代码行数:24,代码来源:MobileChrome.java


注:本文中的org.openqa.selenium.chrome.ChromeOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。