/** * 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; }
/** * @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; }
@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; }); }
/** * 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"); } }
/** * 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."); } }
@Override public Capabilities getCapabilities() { if ( webDriver instanceof HasCapabilities ) return ((HasCapabilities) webDriver).getCapabilities(); else return null; }
/** * * @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; }
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); }
@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)); }
@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")); }
@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())); }
@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); }
@Override public String getBrowserName() { if (wd != null) { Capabilities capabilities = ((HasCapabilities) wd) .getCapabilities(); if (capabilities != null) { return capabilities.getBrowserName(); } return null; } return null; }
@Override public String getBrowserVersion() { if (wd != null) { Capabilities capabilities = ((HasCapabilities) wd) .getCapabilities(); if (capabilities != null) { return capabilities.getVersion(); } return null; } return null; }
/** * Retrieves capabilities info from webDriver and stores the BrowserInfoEntry. */ public void addBrowserInfo() { Capabilities caps = ((HasCapabilities) webDriver).getCapabilities(); browserInfoEntry = new BrowserInfoEntry(caps); }
/** * @return The capabilities of the current driver. */ @Override public Capabilities getCapabilities() { return ((HasCapabilities) super.getWrappedDriver()).getCapabilities(); }
@Override public Capabilities getCapabilities() { return ((HasCapabilities) driver).getCapabilities(); }
public static String getBrowserName(final WebDriver webDriver) { return ((HasCapabilities) webDriver).getCapabilities().getBrowserName(); }
public InternetExplorerActions(final WebDriver webDriver) { super(webDriver); js = (JavascriptExecutor) webDriver; this.hasCapabilities = (HasCapabilities) webDriver; }