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


Java ChromeOptions.setCapability方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: getCapabilities

import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@Override
public ChromeOptions getCapabilities() {
    ChromeOptions chromeOptions = new ChromeOptions();
    // useful defaults
    chromeOptions.setCapability(
            "chrome.switches",
            singletonList("--no-default-browser-check"));
    chromeOptions.setCapability(
            "chrome.prefs",
            ImmutableMap.of("profile.password_manager_enabled", "false"));

    // Use Chrome's built in device emulators
    if (Property.DEVICE.isSpecified()) {
        chromeOptions.setExperimentalOption(
                "mobileEmulation",
                ImmutableMap.of("deviceName", Property.DEVICE.getValue()));
    }

    // Allow user to provide their own user directory, for custom chrome profiles
    if (Property.CHROME_USER_DATA_DIR.isSpecified()) {
        chromeOptions.addArguments(
                "user-data-dir=" + Property.CHROME_USER_DATA_DIR.getValue());
    }
    chromeOptions.setHeadless(Property.HEADLESS.getBoolean());
    return chromeOptions;
}
 
开发者ID:Frameworkium,项目名称:frameworkium-core,代码行数:27,代码来源:ChromeImpl.java

示例6: configuration

import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@Override
public Capabilities configuration(final XmlConfig config) {
    final ChromeOptions options = new ChromeOptions();
    options.setCapability("enableVNC", true);
    options.setCapability("enableVideo", true);
    options.setCapability("name", config.getTestName());
    options.setCapability("screenResolution", "1280x1024x24");
    return merge(config, options);
}
 
开发者ID:sskorol,项目名称:qaa-amazon,代码行数:10,代码来源:Chrome.java

示例7: convert

import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
@Override
public Capabilities convert(WebDriverProperties properties) {
    Map<String, Object> deviceMetrics = new HashMap<>();
    Map<String, Object> mobileEmulation = new HashMap<>();
    ChromeOptions chromeOptions = new ChromeOptions();

    // general options for logging purpose
    chromeOptions.setCapability(CAPABILITY_AUTOCLOSE, properties.isAutoClose());
    addToChromeOptionsIfNoEmptyValue(chromeOptions, CAPABILITY_DRIVER_VERSION, properties.getDriverVersion());
    addToChromeOptionsIfNoEmptyValue(chromeOptions, CAPABILITY_BROWSER_SIZE, properties.getBrowserSize());

    //https://cs.chromium.org/chromium/src/chrome/test/chromedriver/chrome/mobile_device_list.cc
    addToMapIfNoEmptyValue(mobileEmulation, CAPABILITY_DEVICE_NAME, properties.getDeviceName());
    addToMapIfNoEmptyValue(mobileEmulation, CAPABILITY_USER_AGENT, properties.getUserAgent());

    // calculate the deviceMetrics
    if (isNotEmpty(properties.getViewportSize())) {
        String[] dimension = properties.getViewportSize().split("x");
        int width = Integer.parseInt(dimension[0]);
        int height = Integer.parseInt(dimension[1]);
        deviceMetrics.put("width", width);
        deviceMetrics.put("height", height);
    }
    if (properties.getPixelRatio() != 0.0) {
        deviceMetrics.put(CAPABILITY_PIXEL_RATIO, properties.getPixelRatio());
    }

    // add deviceMetrics and mobileEmulation
    if(!deviceMetrics.isEmpty())
        mobileEmulation.put("deviceMetrics", deviceMetrics);

    if(!mobileEmulation.isEmpty()) {
        chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
    }

    // setting additional arguments
    // https://sites.google.com/a/chromium.org/chromedriver/capabilities
    chromeOptions.addArguments("--disable-device-discovery-notifications");
    chromeOptions.addArguments("--disable-infobars");
    if(properties.isHeadless())
        chromeOptions.setHeadless(true);

    return chromeOptions;
}
 
开发者ID:isgarlo,项目名称:givemeadriver,代码行数:45,代码来源:ChromeCapabilitiesConverter.java

示例8: addToChromeOptionsIfNoEmptyValue

import org.openqa.selenium.chrome.ChromeOptions; //导入方法依赖的package包/类
private void addToChromeOptionsIfNoEmptyValue(ChromeOptions chromeOptions, String key, String value) {
    if (isNotEmpty(value)) {
        chromeOptions.setCapability(key, value);
    }
}
 
开发者ID:isgarlo,项目名称:givemeadriver,代码行数:6,代码来源:ChromeCapabilitiesConverter.java


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