Testing the hybrid Android application using Appium

Testing the Hybrid apps is very simple. All you have to do is switch the context to Webview and perform normal selenium operations. Note that Webview debugging should be enabled in the app by developer otherwise you will not be able to switch the context to Webview.

package hybridtests;

import io.appium.java_client.android.AndroidDriver;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class LaunchLocaleur {

    private AndroidDriver driver;
public void test() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "4.4.4");
    capabilities.setCapability("deviceName", "sagarcell");
    capabilities.setCapability("browser_Name", "Android");
    capabilities.setCapability("appPackage", "package1");

    driver = new AndroidDriver(new URL(""), capabilities) {
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    //get contexts
    //If your app has got any WebViews, count should be more than 1.
    System.out.println("Context count " + driver.getContextHandles().size());

    for (Object contextName : driver.getContextHandles()) {
        System.out.println("Context Name -> " + contextName);
        if (contextName.toString().toUpperCase().contains("WEBVIEW")){
            System.out.println("Switched to WebView Context");

    //Switch back to Native app

You may also like...