Appium only shows NATIVE_APP context on a Cordova App

丶灬走出姿态 提交于 2019-12-18 12:41:49

问题


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?


回答1:


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.




回答2:


Did you try to force select of webview? For example in JAVA:

driver.switchTo().window("WEBVIEW");

I'm also testing cordova app and it is working well.



来源:https://stackoverflow.com/questions/24426385/appium-only-shows-native-app-context-on-a-cordova-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!