Search code examples
androidcordovaappium

Appium only shows NATIVE_APP context on a Cordova App


I'm running Appium on Windows to test a Cordova app directly on an Android device. However, when I try to fetch the contexts and switch to the one containing WEBVIEW (basically, the recommended process), it only returns one context, NATIVE_APP.

When I use the inspector, I'm able to see a WebView child and a lot of View children appended to it, which relate to each one of the elements inside the app. So, despite it doesn't show the element tree in Webview mode, I'm able to see it's using a WebView, but somehow isn't able to connect to that specific context.

Any ideas about this?


Solution

  • Its working. I tried with a different combinations of capabilities and at-last I found the working combination. Use automationName and dont put platformVersion in capabilities.

    final File app = new File(appDir, "HybridSample.apk");
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("deviceName", "Android Emulator");
    // capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("automationName", "Selendroid");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("appPackage", "com.mcc.hybrid"); // Optional
    capabilities.setCapability("appActivity", ".HybridSample"); // Optional
    

    If you inspect server logs, you can also see this. Available contexts: NATIVE_APP,WEBVIEW_0

    That means, you have to switch context as follows.

    for (final String contextName : contextNames) {
      System.out.println(contextName);
      if (contextName.contains("WEBVIEW_0")) {
        driver.context(contextName);
      }
    }
    

    Please note that above settings are for Android version older than 4.4. If you have KitKat or later, just remove automationName. With automationName, it will not work correctly as it returns only NATIVE_APP as available context.