Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mobile Test Automation with Appium

You're reading from  Mobile Test Automation with Appium

Product type Book
Published in Jun 2017
Publisher Packt
ISBN-13 9781787280168
Pages 256 pages
Edition 1st Edition
Languages
Author (1):
Nishant Verma Nishant Verma
Profile icon Nishant Verma

Switching between views - web and native


While testing an app, we often find the need to switch between the Web and native views. A typical example is the Facebook sign-in page in many apps or an intermediate payment page. In those situations, we need to change the application context to WEBVIEW or NATIVE. Use the following code snippet to switch to WebView:

public static void changeDriverContextToWeb(AppiumDriver driver) {
    Set<String> allContext = driver.getContextHandles();
    for (String context : allContext) {
        if (context.contains("WEBVIEW"))
            driver.context(context);
    }
}

It tries to get a list of all the context handles, checks whether there is any context that contains WebView, and then the driver switches to that context. The following code snippet switches to native on a similar logic:

public static void changeDriverContextToNative(AppiumDriver driver) {
    Set<String> contextNames = driver.getContextHandles();
    for (String contextName : contextNames...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}