Java Code Examples for org.openqa.selenium.Capabilities#getVersion()

The following examples show how to use org.openqa.selenium.Capabilities#getVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebDriverHandle.java    From caja with Apache License 2.0 6 votes vote down vote up
private void reportVersion(RemoteWebDriver driver) {
  if (reportedVersion) { return; }
  reportedVersion = true;
  Capabilities caps = driver.getCapabilities();
  String name = caps.getBrowserName();
  if (name == null) { name = "unknown"; }
  String version = caps.getVersion();
  if (version == null) { version = "unknown"; }
  // Firefox's version is something like "20.0", which doesn't tell
  // you the exact build, so we also try to report buildID.
  String build = (String) executeScript(
      "return String(navigator.buildID || '')");
  if (build != null && !"".equals(build)) {
    version += " build " + build;
  }
  Echo.echo("webdriver: browser " + name + " version " + version);
}
 
Example 2
Source File: DriverManager.java    From selenium-java-bootstrap with MIT License 5 votes vote down vote up
public static String getInfo() {
    Capabilities cap = ((RemoteWebDriver) DriverManager.getDriver()).getCapabilities();
    String browserName = cap.getBrowserName();
    String platform = cap.getPlatform().toString();
    String version = cap.getVersion();
    return String.format("browser: %s v: %s platform: %s", browserName, version, platform);
}
 
Example 3
Source File: VisualAssertion.java    From neodymium-library with MIT License 5 votes vote down vote up
/**
 * Returns the browser version
 * 
 * @param webDriver
 *            the WebDriver to query
 * @return the browser name
 */
private String getBrowserVersion(final WebDriver webDriver)
{
    final Capabilities capabilities = ((RemoteWebDriver) webDriver).getCapabilities();
    final String browserVersion = capabilities.getVersion();

    return browserVersion == null ? "unknown" : browserVersion;
}
 
Example 4
Source File: ReportingWebDriverEventListener.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
/**
 * Get a short human-readable string that identifies the source of the specified exception.
 *
 * @param throwable The exception
 * @return The description, usable as a filename
 */
private String getFailureSummary(Throwable throwable, WebDriver driver) {
    String failureSite = null;

    Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();
    String browser = caps.getBrowserName() + "-" + caps.getVersion();

    for (StackTraceElement element : throwable.getStackTrace()) {
        try {
            String className = element.getClassName();

            // Only consider our own classes.
            if (className.startsWith(classPrefix)) {
                Class<?> klass = Class.forName(className);
                String location = klass.getSimpleName() + "." + element.getMethodName() + "#" + element.getLineNumber();

                // The first of our classes we find must be the actual site of the failure.
                // Also ignore PageObject as almost all failures will come from there, and we want to be more specific.
                if (failureSite == null && klass != PageObject.class) {
                    failureSite = location;
                }

                Method method = klass.getMethod(element.getMethodName());
                for (Annotation annotation : method.getDeclaredAnnotations()) {
                    if (annotation instanceof Test) {
                        // Once we find one of our classes annotated with @Test it must be the case that fails.
                        return browser + "-" + location + "-" + failureSite;
                    }
                }
            }
        } catch (ReflectiveOperationException e) {
            // Do nothing and proceed to the next element.
        }
    }
    return browser + "-Unknown" + new Random().nextInt(10000);
}
 
Example 5
Source File: DefaultExtWebDriver.java    From JTAF-ExtWebDriver with Apache License 2.0 5 votes vote down vote up
@Override
public String getBrowserVersion() {
	if (wd != null) {
		Capabilities capabilities = ((HasCapabilities) wd)
				.getCapabilities();
		if (capabilities != null) {
			return capabilities.getVersion();
		}
		return null;
	}
	return null;
}
 
Example 6
Source File: SeleniumDriver.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
public String getBrowserVersion() {
    if (runContext.BrowserVersion.equalsIgnoreCase("default")) {
        if (!runContext.Browser.equals((Browser.HtmlUnit))) {
            String browser_version;
            Capabilities cap;
            if (driver instanceof ExtendedHtmlUnitDriver) {
                cap = ((ExtendedHtmlUnitDriver) driver).getCapabilities();
            } else if (driver instanceof MobileDriver) {
                cap = ((RemoteWebDriver) driver).getCapabilities();
                Object pV = cap.getCapability("platformVersion");
                return pV == null ? "" : pV.toString();
            } else if (driver instanceof RemoteWebDriver) {
                cap = ((RemoteWebDriver) driver).getCapabilities();
            } else {
                return runContext.BrowserVersion;
            }
            String browsername = cap.getBrowserName();
            // This block to find out IE Version number
            if ("internet explorer".equalsIgnoreCase(browsername)) {
                String uAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
                // uAgent return as "MSIE 8.0 Windows" for IE8
                if (uAgent.contains("MSIE") && uAgent.contains("Windows")) {
                    browser_version = uAgent.substring(uAgent.indexOf("MSIE") + 5, uAgent.indexOf("Windows") - 2);
                } else if (uAgent.contains("Trident/7.0")) {
                    browser_version = "11.0";
                } else {
                    browser_version = "0.0";
                }
            } else {
                // Browser version for Firefox and Chrome
                browser_version = cap.getVersion();
            }
            if (browser_version.contains(".") && browser_version.length() > 5) {
                return browser_version.substring(0, browser_version.indexOf("."));
            } else {
                return browser_version;
            }
        }
    }
    return runContext.BrowserVersion;
}
 
Example 7
Source File: ConsoleUtils.java    From Quantum with MIT License 4 votes vote down vote up
public static String getVersion(Capabilities caps) {
	return caps.getCapability("platformVersion") == null ? 
			(caps.getVersion() == null || caps.getVersion().isEmpty() ?
					caps.getBrowserName() : caps.getVersion())
			: caps.getCapability("platformVersion") + "";
}
 
Example 8
Source File: CapabilitiesComparator.java    From selenium with Apache License 2.0 4 votes vote down vote up
public CapabilitiesComparator(final Capabilities desiredCapabilities,
                              final Platform currentPlatform) {
  final CapabilityScorer<String> browserNameScorer =
      new CapabilityScorer<>(desiredCapabilities.getBrowserName());
  Comparator<Capabilities> byBrowserName =
      Comparator.comparingInt(c -> browserNameScorer.score(c.getBrowserName()));

  final CapabilityScorer<String> versionScorer =
      new VersionScorer(desiredCapabilities.getVersion());
  Comparator<Capabilities> byVersion =
      Comparator.comparingInt(c -> versionScorer.score(c.getVersion()));

  final CapabilityScorer<Boolean> jsScorer =
      new CapabilityScorer<>(desiredCapabilities.is(SUPPORTS_JAVASCRIPT));
  Comparator<Capabilities> byJavaScript =
      Comparator.comparingInt(c -> jsScorer.score(c.is(SUPPORTS_JAVASCRIPT)));

  Platform desiredPlatform = desiredCapabilities.getPlatform();
  if (desiredPlatform == null) {
    desiredPlatform = Platform.ANY;
  }

  final CapabilityScorer<Platform> currentPlatformScorer =
      new CurrentPlatformScorer(currentPlatform, desiredPlatform);
  Comparator<Capabilities> byCurrentPlatform =
      Comparator.comparingInt(c -> currentPlatformScorer.score(c.getPlatform()));

  final CapabilityScorer<Platform> strictPlatformScorer =
      new CapabilityScorer<>(desiredPlatform);
  Comparator<Capabilities> byStrictPlatform =
      Comparator.comparingInt(c -> strictPlatformScorer.score(c.getPlatform()));

  final CapabilityScorer<Platform> fuzzyPlatformScorer =
      new FuzzyPlatformScorer(desiredPlatform);
  Comparator<Capabilities> byFuzzyPlatform =
      Comparator.comparingInt(c -> fuzzyPlatformScorer.score(c.getPlatform()));

  compareWith = Ordering.compound(Arrays.asList(
      byBrowserName,
      byVersion,
      byJavaScript,
      byCurrentPlatform,
      byStrictPlatform,
      byFuzzyPlatform));
}