/** * Gets names of available contexts * * @return Names of contexts */ public Set<String> getContextHandles() { return this.driver.getContextHandles(); }
@Ignore @Test public void whenIOSHybridAppIsLaunched() { assertTrue(check(serverAppCapabilitiesSupplier, appFileSupplierFunction.apply(webViewApp), (by, aClass) -> { new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(id("login"))) .click(); driver.findElementByAccessibilityId("webView").click(); new WebDriverWait(driver, 30) .until(ExpectedConditions .presenceOfElementLocated(AccessibilityId("Webview"))); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } driver.getContextHandles().forEach((handle) -> { if (handle.contains("WEBVIEW")) { driver.context(handle); } }); return commonPredicate.test(by, aClass); }, partialLinkText("login"), IOSElement.class)); }
@PublicAtsApi public String[] getAvailableContexts() { return (String[]) this.appiumDriver.getContextHandles() .toArray(new String[this.appiumDriver.getContextHandles() .size()]); }
@Nullable private String getWebContext(AppiumDriver driver) { ArrayList<String> contexts = new ArrayList(driver.getContextHandles()); for (String context : contexts) { if (!context.equals("NATIVE_APP")) { return context; } } return null; }
@Nullable private String getWebContext(AppiumDriver driver) { ArrayList<String> contexts = new ArrayList(driver.getContextHandles()); for (String context : contexts) { if (!context.equals("NATIVE_APP")) { return context; } } return null; }
public static String getNodesFromFile(String xml, long currentDepth) throws Exception{ log.info("Method: getNodesFromFile"); log.info("Context: " + Driver.driver.getContextHandles().toString());
if (appiumDriver.getContextHandles().size() > 1 && !originalContext.equalsIgnoreCase(NATIVE_APP)) { appiumDriver.context(NATIVE_APP);
/** * Checks if web description is loaded. * * Note: Will fail if Android version is < 4.4 or >= 6.0. Hybrid views are not compatible with * versions < 4.4 and Appium context switching is currently buggy on devices running versions >= 6.0. * * @return true if it is, else false. */ public boolean webDescriptionIsLoaded() throws InterruptedException { Object[] contextHandles = driver.getContextHandles().toArray(); String androidVersion = driver.getCapabilities().getCapability("platformVersion").toString(); if (versionLessThan(androidVersion, "4.4")) { return true; } else if (versionGreaterThanOrEqual(androidVersion, "6.0")) { return false; } String webViewContent = (String) contextHandles[contextHandles.length - 1]; WebDriver webDriver = driver.context(webViewContent); try { WebDriverWait wait = new WebDriverWait(webDriver, MAX_WEBSITE_LOAD_TIME); wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(WEB_HEADER_CSS_NAME))); wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(WEB_HEADER_CSS_NAME))); } catch (TimeoutException e) { return false; // MAX_WEBSITE_LOAD_TIME timeout exceeded - bad internet connection. } WebElement webHeader = webDriver.findElement(By.cssSelector(WEB_HEADER_CSS_NAME)); return webHeader.isDisplayed(); }