Hybrid app automation using appium

Some important points

  1. Hybrid app contains native as well as web elements
  2. We need to switch to web context to automate web elements and then switch back to native context to perform actions on native controls
  3. In Android hybrid apps, developers may disable web context switching. So In this case, you need to ask them to enable the web debugging in the app settings.
  4. In same way, we can do this action in iOS as well

Below hypothetical code demonstrates how you can perform actions in hybrid app using appium.

package org.softpost.android.simulator;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

 * Created by Sagar on 10-07-2016.
public class HybridTest {
    AndroidDriver driver;
    public void test1() throws Exception{
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("platformName", "android");

        caps.setCapability("deviceName", "Pixel 9");
        caps.setCapability("appPackage", "com.android.calculator2");

try {
    driver = new AndroidDriver<AndroidElement>(new URL(""), caps);
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);



    //We are assuming that calculator app has 2 contexts
    Set<String> contextNames = driver.getContextHandles();
    for (String contextName : contextNames) {
        System.out.println("Context -> " + contextName);
        if (contextName.toLowerCase().contains("webview"))

    //web actions

    //Now switch back to Native app context

}catch (Exception ex) {

}finally {



Web development and Automation testing

solutions delivered!!