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

项目: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;
}
项目:menggeqa    文件:WebDriverUnpackUtility.java   
/**
 * @param driver is an instance of {@link org.openqa.selenium.WebDriver}.
 * @return it returns current mobile platform name. Take a look at
 *     {@link MobilePlatform}.
 *     Note: the given {@link org.openqa.selenium.WebDriver} should implement
 *     @link org.openqa.selenium.HasCapabilities} also. This method will return null
 *     otherwise.
 */
public static String getPlatform(WebDriver driver) {
    if (driver == null) {
        return null;
    }

    Class<?> driverClass = driver.getClass();
    if (AndroidDriver.class.isAssignableFrom(driverClass)) {
        return MobilePlatform.ANDROID;
    }

    if (IOSDriver.class.isAssignableFrom(driverClass)) {
        return MobilePlatform.IOS;
    }

    //it is possible that somebody uses RemoteWebDriver or their
    //own WebDriver implementation. At this case capabilities are used
    //to detect platform
    if (HasCapabilities.class.isAssignableFrom(driverClass)) {
        return String.valueOf(((HasCapabilities) driver).getCapabilities()
            .getCapability(MobileCapabilityType.PLATFORM_NAME));
    }

    return null;
}
项目:find    文件:FindSessionITCase.java   
@Test
public void testDocumentPreview(){
    assumeThat(((HasCapabilities) getDriver()).getCapabilities().getBrowserName(), is("firefox"));

    final ListView results = findService.search("The Season");
    final FindResult searchResult = results.searchResult(1);

    deleteCookies();

    final DocumentViewer docViewer = searchResult.openDocumentPreview();
    final Frame frame = new Frame(getDriver(), docViewer.frame());
    frame.operateOnContent(content -> {
        verifyThat("Authentication Fail frame displayed correctly", content, allOf(
                containsText("403"),
                containsText("Authentication Failed"),
                containsText("You do not have permission to view this page")
        ));
        return null;
    });
}
项目: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");
    }
}
项目:bobcat    文件:TestEventCollectorImpl.java   
/**
 * Retrieves browser info from webDriver instance and stores it in the current test. If the
 * webDriver lacks capabilities, browserInfo will create an error entry.
 */
public final void browserInfo() {
  final WebDriver webDriver = webDriverProvider.get();
  if (webDriver instanceof HasCapabilities) {
    currentTest.get().addBrowserInfo();
  } else {
    currentTest.get()
        .error("Your WebDriver doesn't provide capabilities, so we can't log its info.");
  }
}
项目:xframium-java    文件:DeviceWebDriver.java   
@Override
public Capabilities getCapabilities()
{
    if ( webDriver instanceof HasCapabilities )
        return ((HasCapabilities) webDriver).getCapabilities();
    else
        return null;
}
项目:menggeqa    文件:WebDriverUnpackUtility.java   
/**
 *
 * @param driver is an instance of {@link org.openqa.selenium.WebDriver}.
 * @return it returns current automation type. Take a look at
 * {@link AutomationName}.
 *     Note: the given {@link org.openqa.selenium.WebDriver} should implement
 * {@link org.openqa.selenium.HasCapabilities} also. This method will return null
 *      otherwise.
 *
 */
public static String getAutomation(WebDriver driver) {
    if (driver == null) {
        return null;
    }

    if (HasCapabilities.class.isAssignableFrom(driver.getClass())) {
        return String.valueOf(((HasCapabilities) driver).getCapabilities()
            .getCapability(MobileCapabilityType.AUTOMATION_NAME));
    }

    return null;
}
项目:grid-refactor-remote-server    文件:DefaultSession.java   
public EventFiringWebDriver call() throws Exception {
  WebDriver rawDriver = factory.newInstance(capabilities);
  Capabilities actualCapabilities = capabilities;
  if (rawDriver instanceof HasCapabilities) {
    actualCapabilities = ((HasCapabilities) rawDriver).getCapabilities();
    isAndroid = actualCapabilities.getPlatform().is(Platform.ANDROID);
  }
  describedCapabilities = getDescription(rawDriver, actualCapabilities);
  return new EventFiringWebDriver(rawDriver);
}
项目:cinnamon    文件:CinnamonWebDriverOptionsTest.java   
@Test
public void shouldHandleEmptyCookiesForBrowsersThatRequireJavaScript() {
    when(((HasCapabilities) mockDriver).getCapabilities()).thenReturn(DesiredCapabilities.safari());
    doReturn("").when((JavascriptExecutor) mockDriver).executeScript("return (document.cookie);");
    CinnamonWebDriverOptions options = new CinnamonWebDriverOptions(mockDriver);
    assertThat(options.getCookies(), emptyCollectionOf(Cookie.class));
}
项目:cinnamon    文件:CinnamonWebDriverOptionsTest.java   
@Test
public void shouldHandleCookieWithEmptyValueForBrowsersThatRequireJavaScript() {
    when(((HasCapabilities) mockDriver).getCapabilities()).thenReturn(DesiredCapabilities.safari());
    doReturn("cookiea=;cookieb=123;cookiec=").when((JavascriptExecutor) mockDriver).executeScript("return (document.cookie);");
    CinnamonWebDriverOptions options = new CinnamonWebDriverOptions(mockDriver);
    assertThat(options.getCookieNamed("cookiea").getValue(), is(""));
    assertThat(options.getCookieNamed("cookieb").getValue(), is("123"));
}
项目:cinnamon    文件:CinnamonWebDriverOptionsTest.java   
@Test
public void shouldReturnNullForNonExistentCookie() {
    when(((HasCapabilities) mockDriver).getCapabilities()).thenReturn(DesiredCapabilities.safari());
    doReturn("cookiea=123").when((JavascriptExecutor) mockDriver).executeScript("return (document.cookie);");
    CinnamonWebDriverOptions options = new CinnamonWebDriverOptions(mockDriver);
    assertThat(options.getCookieNamed("nonExistentCookie"), is(nullValue()));
}
项目:selenium-grid-demo    文件:SeleniumGridTest.java   
@Parameters({ "browser" })
@BeforeMethod
public void setUp(@Optional("firefox") String browser) throws Exception {
    RemoteWebDriver remoteDriver = new RemoteWebDriver(browserConfig.get(browser));
    driver = remoteDriver;
    capabilities = ((HasCapabilities) remoteDriver).getCapabilities();
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
项目:JTAF-ExtWebDriver    文件:DefaultExtWebDriver.java   
@Override
public String getBrowserName() {
    if (wd != null) {
        Capabilities capabilities = ((HasCapabilities) wd)
                .getCapabilities();
        if (capabilities != null) {
            return capabilities.getBrowserName();
        }
        return null;
    }
    return null;
}
项目:JTAF-ExtWebDriver    文件:DefaultExtWebDriver.java   
@Override
public String getBrowserVersion() {
    if (wd != null) {
        Capabilities capabilities = ((HasCapabilities) wd)
                .getCapabilities();
        if (capabilities != null) {
            return capabilities.getVersion();
        }
        return null;
    }
    return null;
}
项目:bobcat    文件:TestInfo.java   
/**
 * Retrieves capabilities info from webDriver and stores the BrowserInfoEntry.
 */
public void addBrowserInfo() {
  Capabilities caps = ((HasCapabilities) webDriver).getCapabilities();
  browserInfoEntry = new BrowserInfoEntry(caps);
}
项目:bobcat    文件:WebDriverWrapper.java   
/**
 * @return The capabilities of the current driver.
 */
@Override
public Capabilities getCapabilities() {
  return ((HasCapabilities) super.getWrappedDriver()).getCapabilities();
}
项目:easytest    文件:DeviceWebDriver.java   
@Override
public Capabilities getCapabilities() {
    return ((HasCapabilities) driver).getCapabilities();
}
项目:cinnamon    文件:WebDriverUtils.java   
public static String getBrowserName(final WebDriver webDriver) {
    return ((HasCapabilities) webDriver).getCapabilities().getBrowserName();
}
项目:cinnamon    文件:InternetExplorerActions.java   
public InternetExplorerActions(final WebDriver webDriver) {
    super(webDriver);
    js = (JavascriptExecutor) webDriver;
    this.hasCapabilities = (HasCapabilities) webDriver;
}