Working with Multiple Webviews in Android Hybrid Apps
It & # x27; s not very common, but it can happen that an Android hybrid app has not just one but two or more webviews (for example, when advertizement are in one webview and app logic is in another). If you & # x27; ve ever found yourself in this position, you may get be frustrated when using Appium & # x27; s context API, specifically with codification like this: For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users. If you have multiple webviews, you might hold expected the Set to contain three point: NATIVE_APP, and two webview-looking strings. But rather you probably launch onlyonewebview context. If you were lucky, it was the one you wanted, but there was an equal chance you got the insignificant advert webview (or whatever). So, how can we be sure to get inside the special webview we want, yet when there are multiple? The answer lies in how Chromedriver works. Appium uses Chromedriver for Chrome automation, and Chromedriver handles multiple webviews in a single Android app by treating them as separatewindows. What this intend is that we have accession to them using the built-in Webdriver window commands, like so: Then, we can swop into any window we want by picking a certain hold: How do we know from the handle which window to prefer? We don & # x27; t, because it will be a random-looking twine like CDwindow-A26869B5EDAEAA9D83947BB274F1D0C7, and it might change from test to test. So our best bet is to switch into each one and perform some validation on the window, to prove that we are in the right one (for example, appear at the URL or rubric as a way of ensuring we & # x27; re in the right webview, and short-circuiting our search when we bump it). Of line, to do any of this we actually receive to be in the webviewcontextfirst, otherwise the getWindowHandles command won & # x27; t do anything. So to conclude, hither & # x27; s a total model that utilizes a new feature of The App, namely a view with two webviews. The idea behind this test is simply to make an assertion found on the substance of the page displayed in each webview, proving that we can indeed enter and automate both of them. As with, we use a helper function getWebContext to get ourselves into the initial web setting so that Chromedriver is operative. Without further ado, here & # x27; s the full sample: That & # x27; s it! With judicious use of both context and window hold commands, automating multiple webviews is totally accomplishable. Don & # x27; t forget to insure out thefull codeon GitHub. Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in crafting engaging narratives and marketing collateral across diverse industries. She surpass in collaborating with cross-functional teams to acquire innovative content scheme and deliver compelling, unquestionable, and impactful content that resonates with target audiences and enhances brand authenticity. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Working with Multiple Webviews in Android Hybrid Apps
AI-Powered Key Takeaways

Check out:
SetAlso assay:
Setdriver.switchTo () .window (handle);Run multiple tests (manual or automatize) on existent Android device without experiencing any slowdown..
importee io.appium.java_client.AppiumDriver; importee io.appium.java_client.MobileBy; import io.appium.java_client.android.AndroidDriver; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import javax.annotation.Nullable; import org.hamcrest.Matchers; signification org.junit.After; import org.junit.Assert; import org.junit.Before; signification org.junit.Test; importation org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Edition073_Multiple_Webviews {private String APP_ANDROID = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.10.0/TheApp-v1.10.0.apk ''; private AndroidDriver driver; private static By hybridScreen = MobileBy.AccessibilityId (`` Dual Webview Demo ''); private static By webview = By.className (`` android.webkit.WebView ''); @ Before public void setUp () throws MalformedURLException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` Android ''); capabilities.setCapability (`` deviceName '', `` Android Emulator ''); capabilities.setCapability (`` automationName '', `` UiAutomator2 ''); capabilities.setCapability (`` app '', APP_ANDROID); driver = new AndroidDriver (new URL (`` http: //localhost:4723/wd/hub ''), capabilities);} @ After public void tearDown () {if (driver! = null) {driver.quit ();}} @ Test public void testDualWebviews_Android () {WebDriverWait wait = new WebDriverWait (driver, 10); // get to three-fold webview screen and make sure it 's loaded wait.until (ExpectedConditions.presenceOfElementLocated (hybridScreen)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (webview)); // navigate to the webview context String webContext = getWebContext (driver); driver.context (webContext); // go into each available window and get the text from the html page ArrayListPiali Mazumdar
Working with Multiple Webviews in Android Hybrid Apps
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for advanced user (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence pragmatic guide for advanced users (Part 4)
Discover how HeadSpin can empower your business with superior testing capabilities







Discover how HeadSpin can empower your business with superior test capabilities
Discover how HeadSpin can empower your concern with superior testing capabilities
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












