當前位置: 首頁>>代碼示例>>Java>>正文


Java Capabilities類代碼示例

本文整理匯總了Java中org.openqa.selenium.Capabilities的典型用法代碼示例。如果您正苦於以下問題:Java Capabilities類的具體用法?Java Capabilities怎麽用?Java Capabilities使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Capabilities類屬於org.openqa.selenium包,在下文中一共展示了Capabilities類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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;
}
 
開發者ID:WasiqB,項目名稱:coteafs-appium,代碼行數:19,代碼來源:Device.java

示例2: canGetArtifact

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:23,代碼來源:PageSourceUtils.java

示例3: caps

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
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;
}
 
開發者ID:usman-h,項目名稱:Habanero,代碼行數:25,代碼來源:SauceLabsDriver.java

示例4: shouldRetrieveBrowserDefaults

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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));
}
 
開發者ID:sskorol,項目名稱:webdriver-supplier,代碼行數:24,代碼來源:CoreTests.java

示例5: getCapabilities

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
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;
}
 
開發者ID:barancev,項目名稱:webdriver-junit5-archetype,代碼行數:21,代碼來源:SuiteConfiguration.java

示例6: settingAllChromeProperties

import org.openqa.selenium.Capabilities; //導入依賴的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

示例7: notSettingDeviceMetrics

import org.openqa.selenium.Capabilities; //導入依賴的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

示例8: settingBrowserSize

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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());

}
 
開發者ID:isgarlo,項目名稱:givemeadriver,代碼行數:19,代碼來源:SafariCapabilitiesConverterTest.java

示例9: settingBrowserSize

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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());

}
 
開發者ID:isgarlo,項目名稱:givemeadriver,代碼行數:19,代碼來源:EdgeCapabilitiesConverterTest.java

示例10: settingBrowserSize

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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());

}
 
開發者ID:isgarlo,項目名稱:givemeadriver,代碼行數:19,代碼來源:InternetExplorerCapabilitiesConverterTest.java

示例11: settingBrowserSize

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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());

}
 
開發者ID:isgarlo,項目名稱:givemeadriver,代碼行數:19,代碼來源:OperaCapabilitiesConverterTest.java

示例12: resolve

import org.openqa.selenium.Capabilities; //導入依賴的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: resolve

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:bonigarcia,項目名稱:selenium-jupiter,代碼行數:17,代碼來源:EdgeDriverHandler.java

示例14: resolve

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:bonigarcia,項目名稱:selenium-jupiter,代碼行數:17,代碼來源:FirefoxDriverHandler.java

示例15: resolve

import org.openqa.selenium.Capabilities; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:bonigarcia,項目名稱:selenium-jupiter,代碼行數:17,代碼來源:OperaDriverHandler.java


注:本文中的org.openqa.selenium.Capabilities類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。