Java Code Examples for org.openqa.selenium.Capabilities#getBrowserName()
The following examples show how to use
org.openqa.selenium.Capabilities#getBrowserName() .
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 |
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 |
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: AI.java From neodymium-library with MIT License | 5 votes |
/** * Returns the browser name using Selenium methods * * @param webDriver * the WebDriver to query * @return the browser name */ private String getBrowserName(final WebDriver webDriver) { EventFiringWebDriver firingWebDriver = ((EventFiringWebDriver) webDriver); final Capabilities capabilities = ((RemoteWebDriver) firingWebDriver.getWrappedDriver()).getCapabilities(); final String browserName = capabilities.getBrowserName(); // TODO: change to browserProfileName in a next dev step since resolution influences the detection anyway // final String browserName = Context.get().browserProfileName; return browserName == null ? "unknown" : browserName; }
Example 4
Source File: VisualAssertion.java From neodymium-library with MIT License | 5 votes |
/** * Returns the browser name using Selenium methods * * @param webDriver * the WebDriver to query * @return the browser name */ private String getBrowserName(final WebDriver webDriver) { final Capabilities capabilities = ((RemoteWebDriver) webDriver).getCapabilities(); final String browserName = capabilities.getBrowserName(); return browserName == null ? "unknown" : browserName; }
Example 5
Source File: DefaultLocalDriverProvider.java From webdriver-factory with Apache License 2.0 | 5 votes |
public WebDriver createDriver(Capabilities capabilities) { String browserName = capabilities.getBrowserName(); Function<Capabilities, WebDriver> creator = creators.get(browserName); if (creator != null) { return creator.apply(capabilities); } String className = externalDriverClasses.get(browserName); if (className != null) { return new ReflectionBasedInstanceCreator(className).createDriver(capabilities); } throw new DriverCreationError("Can't find local driver provider for capabilities " + capabilities); }
Example 6
Source File: BrowserWebDriverContainer.java From testcontainers-java with MIT License | 5 votes |
public static String getImageForCapabilities(Capabilities capabilities, String seleniumVersion) { String browserName = capabilities.getBrowserName(); switch (browserName) { case BrowserType.CHROME: return String.format(CHROME_IMAGE, seleniumVersion); case BrowserType.FIREFOX: return String.format(FIREFOX_IMAGE, seleniumVersion); default: throw new UnsupportedOperationException("Browser name must be 'chrome' or 'firefox'; provided '" + browserName + "' is not supported"); } }
Example 7
Source File: DriverFactoryTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void testShouldReturnMatchIfOneFieldMatchesAndOnlyOneDriverIsRegistered() { Capabilities template = new DesiredCapabilities("foo", "1.0", Platform.getCurrent()); DriverProvider provider = mockDriverProviderFor(template); factory.registerDriverProvider(provider); Capabilities example = new ImmutableCapabilities(BROWSER_NAME, template.getBrowserName()); assertEquals(provider, factory.getProviderMatching(example)); }
Example 8
Source File: ReportingWebDriverEventListener.java From dropwizard-experiment with MIT License | 5 votes |
/** * 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 9
Source File: DefaultExtWebDriver.java From JTAF-ExtWebDriver with Apache License 2.0 | 5 votes |
@Override public String getBrowserName() { if (wd != null) { Capabilities capabilities = ((HasCapabilities) wd) .getCapabilities(); if (capabilities != null) { return capabilities.getBrowserName(); } return null; } return null; }
Example 10
Source File: SeleniumDriver.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
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 11
Source File: ConsoleUtils.java From Quantum with MIT License | 4 votes |
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 12
Source File: CapabilitiesComparator.java From selenium with Apache License 2.0 | 4 votes |
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)); }