Java 类org.openqa.selenium.Capabilities 实例源码

项目:coteafs-appium    文件:Device.java   
@SuppressWarnings ("unchecked")
private D init (final URL url, final Capabilities capability) {
    log.trace ("Initializing driver...");
    final TypeToken <D> token = new TypeToken <D> (getClass ()) {
        private static final long serialVersionUID = 1562415938665085306L;
    };
    final Class <D> cls = (Class <D>) token.getRawType ();
    final Class <?> [] argTypes = new Class <?> [] { URL.class, Capabilities.class };
    try {
        final Constructor <D> ctor = cls.getDeclaredConstructor (argTypes);
        return ctor.newInstance (url, capability);
    }
    catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
            | IllegalArgumentException | InvocationTargetException e) {
        fail (DeviceDriverInitializationFailedError.class, "Error occured while initializing device driver.", e);
    }
    return null;
}
项目:Selenium-Foundation    文件:PageSourceUtils.java   
/**
 * Determine if the specified driver is capable of producing page source.
 * 
 * @param optDriver optional web driver object
 * @param logger SLF4J logger object
 * @return 'true' if driver can produce page source; otherwise 'false
 */
public static boolean canGetArtifact(Optional<WebDriver> optDriver, Logger logger) {
    if (optDriver.isPresent()) {
        WebDriver driver = optDriver.get();
        if (driver instanceof HasCapabilities) {
            Capabilities caps = ((HasCapabilities) driver).getCapabilities();
            // if driver explicitly reports that it cannot produce page source
            if (Boolean.FALSE.equals(caps.getCapability(TAKES_ELEMENT_SCREENSHOT))) {
                logger.warn("This driver is not capable of producing page source.");
            } else {
                return true;
            }
        }
    }
    return false;
}
项目:Habanero    文件:SauceLabsDriver.java   
private static Capabilities caps(String platform, String browserName, String browserVersion) {
    try {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        String buildName = SystemProperties.getCurrentShortDate() + " "
                + WebDriverDiscovery.getBrowserName() + " "
                + WebDriverDiscovery.getBrowserVersion() + " "
                + WebDriverDiscovery.getPlatform();

        capabilities.setCapability("browserName", browserName);
        capabilities.setCapability("version", browserVersion);
        capabilities.setCapability("platform", platform);
        capabilities.setCapability("resolution", "1024x768");
        capabilities.setCapability("sauce-advisor", false);
        capabilities.setCapability("record-video", true);
        capabilities.setCapability("record-screenshots", true);
        capabilities.setCapability("build", buildName);

        LOG.info("capabilities : " + capabilities.asMap().toString());
        return capabilities;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:webdriver-supplier    文件:CoreTests.java   
@Test
public void shouldRetrieveBrowserDefaults() {
    final Map<String, String> chromeParameters = new HashMap<>();
    chromeParameters.put(BROWSER_NAME, "chrome");

    final XmlConfig config = new XmlConfig(chromeParameters);
    final Browser chrome = StreamEx.of(browsers)
                                   .findFirst(b -> b.name() == Browser.Name.Chrome)
                                   .orElseThrow(() -> new AssertionError("Unable to retrieve Chrome"));

    assertThat(chrome.isRemote()).isFalse();
    assertThat(chrome.url()).isEqualTo("http://localhost:4444/wd/hub");
    assertThat(chrome.defaultConfiguration(config))
            .extracting(Capabilities::getBrowserName)
            .containsExactly("chrome");
    assertThat(chrome.defaultConfiguration(config))
            .extracting(Capabilities::getVersion)
            .containsExactly("");
    assertThat(chrome.defaultConfiguration(config))
            .extracting(Capabilities::getPlatform)
            .containsExactly(Platform.getCurrent());
    assertThat(chrome.configuration(config)).isEqualTo(chrome.defaultConfiguration(config));
}
项目:webdriver-junit5-archetype    文件:SuiteConfiguration.java   
public Capabilities getCapabilities() throws IOException {
  String capabilitiesFile = properties.getProperty("capabilities");

  Properties capsProps = new Properties();
  capsProps.load(SuiteConfiguration.class.getResourceAsStream(capabilitiesFile));

  DesiredCapabilities capabilities = new DesiredCapabilities();
  for (String name : capsProps.stringPropertyNames()) {
    String value = capsProps.getProperty(name);
    if (value.toLowerCase().equals("true") || value.toLowerCase().equals("false")) {
      capabilities.setCapability(name, Boolean.valueOf(value));
    } else if (value.startsWith("file:")) {
      capabilities.setCapability(name, new File(".", value.substring(5)).getCanonicalFile().getAbsolutePath());
    } else {
      capabilities.setCapability(name, value);
    }
  }

  return capabilities;
}
项目:givemeadriver    文件:ChromeCapabilitiesConverterTest.java   
@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());
}
项目:givemeadriver    文件:SafariCapabilitiesConverterTest.java   
@Test
public void settingBrowserSize() {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("browserSize", "1690x1000");

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

    // then
    // expected safari options
    SafariOptions expectedSafariOptions = new SafariOptions();
    expectedSafariOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    expectedSafariOptions.setCapability(CAPABILITY_BROWSER_SIZE, "1690x1000");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedSafariOptions.asMap());

}
项目:givemeadriver    文件:EdgeCapabilitiesConverterTest.java   
@Test
public void settingBrowserSize() {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("browserSize", "1690x1000");

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

    // then
    // expected safari options
    EdgeOptions expectedEdgeOptions = new EdgeOptions();
    expectedEdgeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    expectedEdgeOptions.setCapability(CAPABILITY_BROWSER_SIZE, "1690x1000");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedEdgeOptions.asMap());

}
项目:givemeadriver    文件:InternetExplorerCapabilitiesConverterTest.java   
@Test
public void settingBrowserSize() {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("browserSize", "1690x1000");

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

    // then
    // expected safari options
    InternetExplorerOptions expectedInternetExplorerOptions = new InternetExplorerOptions();
    expectedInternetExplorerOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    expectedInternetExplorerOptions.setCapability(CAPABILITY_BROWSER_SIZE, "1690x1000");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedInternetExplorerOptions.asMap());

}
项目:givemeadriver    文件:OperaCapabilitiesConverterTest.java   
@Test
public void settingBrowserSize() {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("browserSize", "1690x1000");

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

    // then
    // expected safari options
    OperaOptions expectedOperaOptions = new OperaOptions();
    expectedOperaOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    expectedOperaOptions.setCapability(CAPABILITY_BROWSER_SIZE, "1690x1000");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedOperaOptions.asMap());

}
项目:selenium-jupiter    文件:ChromeDriverHandler.java   
@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);
    }
}
项目:selenium-jupiter    文件:EdgeDriverHandler.java   
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        EdgeOptions edgeOptions = (EdgeOptions) getOptions(parameter,
                testInstance);
        if (capabilities.isPresent()) {
            edgeOptions.merge(capabilities.get());
        }
        object = new EdgeDriver(edgeOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
项目:selenium-jupiter    文件:FirefoxDriverHandler.java   
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        FirefoxOptions firefoxOptions = (FirefoxOptions) getOptions(
                parameter, testInstance);
        if (capabilities.isPresent()) {
            firefoxOptions.merge(capabilities.get());
        }
        object = new FirefoxDriver(firefoxOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
项目:selenium-jupiter    文件:OperaDriverHandler.java   
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        OperaOptions operaOptions = (OperaOptions) getOptions(parameter,
                testInstance);
        if (capabilities.isPresent()) {
            operaOptions.merge(capabilities.get());
        }
        object = new OperaDriver(operaOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
项目:Java-Testing-Toolbox    文件:AbstractWebDriverConfiguration.java   
/**
 * Merge two {@link Capabilities} (default capabilities and other) together and return the union of the two as a new {@link Capabilities} instance. Capabilities from {@code other} will override those in {@code this}.
 * 
 * @param other
 *            Other capabilities. (Null is accepted)
 * 
 * @param defaultIfNull
 *            Default capabilities if null return. (Null is accepted)
 * 
 * @return The merged capabilities.
 */
protected Capabilities mergeCapabilities(Capabilities other, Capabilities defaultIfNull) {
    Capabilities capabilities = this.getDefaultCapabilities();

    if (capabilities == null) {
        if (other != null) {
            return other;
        }
    } else {
        if (other == null) {
            return capabilities;
        } else {
            return capabilities.merge(other);
        }
    }

    return defaultIfNull;
}
项目:qaa-amazon    文件:Chrome.java   
@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);
}
项目:qaa-amazon    文件:Firefox.java   
@Override
public Capabilities configuration(final XmlConfig config) {
    final FirefoxOptions options = new FirefoxOptions();
    options.setCapability("enableVNC", true);
    options.setCapability("name", config.getTestName());
    options.setCapability("screenResolution", "1280x1024x24");
    return merge(config, options);
}
项目:Selenium-Foundation    文件:SeleniumConfig.java   
/**
 * Convert the configured browser specification from JSON to {@link Capabilities} object.
 * 
 * @return {@link Capabilities} object for the configured browser specification
 */
public Capabilities getBrowserCaps() {
    if (browserCaps == null) {
        String jsonStr = null;
        String nameStr = getString(SeleniumSettings.BROWSER_NAME.key());
        if (nameStr != null) {
            InputStream inputStream = 
                    Thread.currentThread().getContextClassLoader().getResourceAsStream(nameStr + "Caps.json");
            if (inputStream != null) {
                try {
                    jsonStr = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
                } catch (IOException eaten) {
                    LOGGER.warn("Unable to get browser configuration file contents: {}", eaten.getMessage());
                }
            }

            if (jsonStr == null) {
                jsonStr = String.format(CAPS_PATTERN, nameStr);
            }
        }

        if (jsonStr == null) {
            jsonStr = getString(SeleniumSettings.BROWSER_CAPS.key());
        }

        RegistrationRequest config = RegistrationRequest.getNewInstance(JSON_HEAD + jsonStr + JSON_TAIL);
        browserCaps = config.getCapabilities().get(0);
    }
    return browserCaps;
}
项目:Selenium-Foundation    文件:WebDriverUtils.java   
/**
 * Get the capabilities of the specified search context
 * 
 * @param context search context
 * @return context capabilities
 */
public static Capabilities getCapabilities(SearchContext context) {
    WebDriver driver = getDriver(context);

    if (driver instanceof HasCapabilities) {
        return ((HasCapabilities) driver).getCapabilities();
    } else {
        throw new UnsupportedOperationException("The specified context is unable to describe its capabilities");
    }
}
项目:Selenium-Foundation    文件:SeleniumConfig.java   
/**
 * Convert the configured browser specification from JSON to {@link Capabilities} object.
 * 
 * @return {@link Capabilities} object for the configured browser specification
 */
public Capabilities getBrowserCaps() {
    if (browserCaps == null) {
        String jsonStr = null;
        String nameStr = getString(SeleniumSettings.BROWSER_NAME.key());
        if (nameStr != null) {
            InputStream inputStream = 
                    Thread.currentThread().getContextClassLoader().getResourceAsStream(nameStr + "Caps.json");
            if (inputStream != null) {
                try {
                    jsonStr = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
                } catch (IOException eaten) {
                    LOGGER.warn("Unable to get browser configuration file contents: {}", eaten.getMessage());
                }
            }

            if (jsonStr == null) {
                jsonStr = String.format(CAPS_PATTERN, nameStr);
            }
        }

        if (jsonStr == null) {
            jsonStr = getString(SeleniumSettings.BROWSER_CAPS.key());
        }

        JsonObject json = new JsonParser().parse(JSON_HEAD + jsonStr + JSON_TAIL).getAsJsonObject();
        GridNodeConfiguration config = GridNodeConfiguration.loadFromJSON(json);
        browserCaps = config.capabilities.get(0);
    }
    return browserCaps;
}
项目:marathonv5    文件:JavaDriver.java   
private static JavaProfile extractProfile(Capabilities desiredCapabilities, Capabilities requiredCapabilities) {
    JavaProfile javaProfile = new JavaProfile();
    if (requiredCapabilities == null) {
        return javaProfile;
    }
    return javaProfile;
}
项目:marathonv5    文件:JavaDriverTest.java   
public void javaDriver() {
    driver = new JavaDriver();
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertEquals("java", capabilities.getBrowserName());
    AssertJUnit.assertEquals(true, capabilities.is("takesScreenshot"));
    AssertJUnit.assertEquals(false, capabilities.is("nativeEvents"));
}
项目:marathonv5    文件:JavaDriverTest.java   
public void succeedsWhenRequestingNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(capabilities.is("nativeEvents"));
}
项目:marathonv5    文件:JavaDriverTest.java   
public void succeedsWhenRequestingNonNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", false);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(!capabilities.is("nativeEvents"));
}
项目:marathonv5    文件:JavaDriverCapabilitiesTest.java   
public void javaDriver() {
    driver = new JavaDriver();
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertEquals("java", capabilities.getBrowserName());
    AssertJUnit.assertEquals(true, capabilities.is("takesScreenshot"));
    AssertJUnit.assertEquals(false, capabilities.is("nativeEvents"));
}
项目:webdriver-supplier    文件:Firefox.java   
@Override
public Capabilities configuration(final XmlConfig config) {
    final FirefoxOptions options = new FirefoxOptions();
    options.setCapability("enableVNC", true);
    options.setCapability("name", config.getTestName());
    options.setCapability("screenResolution", "1280x1024x24");
    return merge(config, options);
}
项目:KITE    文件:TestManager.java   
/**
 * Constructs a list of web drivers against the number of provided browsers.
 *
 * @throws MalformedURLException if no protocol is specified in the remoteAddress of a browser, or
 *         an unknown protocol is found, or spec is null.
 */
private void populateDrivers(String testName) throws MalformedURLException {
  this.webDriverList = new ArrayList<WebDriver>();
  for (Browser browser : this.browserList) {
    WebDriver webDriver = WebDriverFactory.createWebDriver(browser, testName);
    Capabilities capabilities = ((RemoteWebDriver) webDriver).getCapabilities();
    browser.setWebDriverVersion(capabilities.getVersion());
    browser.setWebDriverPlatform(capabilities.getPlatform().name());
    this.webDriverList.add(webDriver);
  }
}
项目:givemeadriver    文件:FirefoxCapabilitiesConverter.java   
@Override
public Capabilities convert(WebDriverProperties properties) {
    FirefoxOptions firefoxOptions = new FirefoxOptions();

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

    return firefoxOptions;
}
项目:givemeadriver    文件:OperaCapabilitiesConverter.java   
@Override
public Capabilities convert(WebDriverProperties properties) {
    OperaOptions operaOptions = new OperaOptions();

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

    return operaOptions;
}
项目:givemeadriver    文件:EdgeCapabilitiesConverter.java   
@Override
public Capabilities convert(WebDriverProperties properties) {
    EdgeOptions edgeOptions = new EdgeOptions();

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

    return edgeOptions;
}
项目:givemeadriver    文件:PhantomJSCapabilitiesConverter.java   
@Override
public Capabilities convert(WebDriverProperties properties) {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    // general options for logging purpose
    capabilities.setCapability(CAPABILITY_BROWSER_NAME, properties.getBrowser());
    capabilities.setCapability(CAPABILITY_AUTOCLOSE, properties.isAutoClose());
    addToCapabilitiesIfNoEmptyValue(capabilities, CAPABILITY_DRIVER_VERSION, properties.getDriverVersion());
    addToCapabilitiesIfNoEmptyValue(capabilities, CAPABILITY_BROWSER_SIZE, properties.getBrowserSize());

    capabilities.setCapability("phantomjs.cli.args",
            new String[]{"--web-security=no", "--ignore-ssl-errors=yes"});

    return capabilities;
}
项目:givemeadriver    文件:SafariCapabilitiesConverter.java   
@Override
public Capabilities convert(WebDriverProperties properties) {
    SafariOptions safariOptions = new SafariOptions();

    // general options for logging purpose
    safariOptions.setCapability(CAPABILITY_AUTOCLOSE, properties.isAutoClose());
    if (isNotEmpty(properties.getBrowserSize())) {
        safariOptions.setCapability(CAPABILITY_BROWSER_SIZE, properties.getBrowserSize());
    }

    return safariOptions;
}
项目:givemeadriver    文件:RemoteCapabilitiesConverter.java   
@Override
public Capabilities convert(WebDriverProperties properties) {
    DesiredCapabilities capabilities = new DesiredCapabilities(properties.asMap());

    capabilities.setCapability(CAPABILITY_AUTOCLOSE, properties.isAutoClose());
    if (isNotEmpty(properties.getBrowserSize())) {
        capabilities.setCapability(CAPABILITY_BROWSER_SIZE, properties.getBrowserSize());
    }
    return capabilities;
}
项目:givemeadriver    文件:HtmlUnitCapabilitiesConverter.java   
@Override
public Capabilities convert(WebDriverProperties properties) {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    // general options for logging purpose
    capabilities.setCapability(CAPABILITY_BROWSER_NAME, properties.getBrowser());
    capabilities.setCapability(CAPABILITY_AUTOCLOSE, properties.isAutoClose());
    if (isNotEmpty(properties.getBrowserSize())) {
        capabilities.setCapability(CAPABILITY_BROWSER_SIZE, properties.getBrowserSize());
    }

    return capabilities;
}
项目:givemeadriver    文件:ChromeCapabilitiesConverterTest.java   
@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());
}
项目:givemeadriver    文件:RemoteCapabilitiesConverterTest.java   
@Test
public void settingManyRemoteCapabilities() throws MalformedURLException {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("remote", "https://remote.grid.url");
    properties.setProperty("os", "windows");
    properties.setProperty("os_version", "7");
    properties.setProperty("browser", "firefox");
    properties.setProperty("browser_version", "48.0");
    properties.setProperty("resolution", "1680x1050");
    properties.setProperty("browserSize", "14400x1050");

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

    // then
    // expected capabilities
    DesiredCapabilities expectedCapabilities = new DesiredCapabilities();
    expectedCapabilities.setCapability("remote","https://remote.grid.url");
    expectedCapabilities.setCapability("os", "windows");
    expectedCapabilities.setCapability("os_version", "7");
    expectedCapabilities.setCapability("browser", "firefox");
    expectedCapabilities.setCapability("browser_version", "48.0");
    expectedCapabilities.setCapability("resolution", "1680x1050");
    expectedCapabilities.setCapability("browserSize", "14400x1050");
    expectedCapabilities.setCapability(CAPABILITY_AUTOCLOSE, false);

    assertThat(convertedCapabilities).isEqualTo(expectedCapabilities);
}
项目:givemeadriver    文件:PhantomJSCapabilitiesConverterTest.java   
@Test
public void notSettingAnyProperty() {
    // given
    WebDriverProperties properties = new WebDriverProperties();

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

    // then
    String[] expectedPhantomJSCliArgs = new String[]{"--web-security=no", "--ignore-ssl-errors=yes"};
    assertThat(convertedCapabilities.getCapability("phantomjs.cli.args")).isEqualTo(expectedPhantomJSCliArgs);
}
项目:selenium-jupiter    文件:AppiumDriverHandler.java   
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);

        Optional<URL> url = annotationsReader.getUrl(parameter,
                testInstance);
        if (capabilities.isPresent()) {
            URL appiumServerUrl;
            if (url.isPresent()) {
                appiumServerUrl = url.get();
            } else {
                appiumDriverLocalService = AppiumDriverLocalService
                        .buildDefaultService();
                appiumDriverLocalService.start();
                appiumServerUrl = appiumDriverLocalService.getUrl();
            }

            object = new AndroidDriver<>(appiumServerUrl,
                    capabilities.get());
        } else {
            String noCapsMessage = "Was not possible to instantiate AppiumDriver: Capabilites not present";
            if (throwExceptionWhenNoDriver()) {
                throw new SeleniumJupiterException(noCapsMessage);
            } else {
                log.warn(noCapsMessage);
            }
        }
    } catch (Exception e) {
        handleException(e);
    }
}
项目:Java-Testing-Toolbox    文件:OperaConfiguration.java   
/**
 * {@inheritDoc}
 */
@Override
public OperaDriver start(Capabilities other) {
    Capabilities capabilities = this.mergeCapabilities(other);

    if (capabilities == null) {
        return new OperaDriver();
    }

    return new OperaDriver(capabilities);
}
项目:Java-Testing-Toolbox    文件:FirefoxConfiguration.java   
/**
 * {@inheritDoc}
 */
@Override
public FirefoxDriver start(Capabilities other) {
    Capabilities capabilities = this.mergeCapabilities(other);

    if (capabilities == null) {
        return new FirefoxDriver();
    }

    return new FirefoxDriver(capabilities);
}