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<
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.