Appium仅在Cordova应用程序上显示本地_App上下文[英] Appium only shows NATIVE_APP context on a Cordova App

本文是小编为大家收集整理的关于Appium仅在Cordova应用程序上显示本地_App上下文的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在Windows上运行Appium,直接在Android设备上测试Cordova应用程序.但是,当我尝试获取上下文并切换到包含WEBVIEW的一个(基本上是推荐过程)时,它只返回一个上下文,NATIVE_APP.

当我使用检查员时,我可以看到一个WebView的孩子和许多附加在其中的孩子,这与应用程序中的每个元素有关.因此,尽管它没有在WebView模式下显示元素树,但我可以看到它使用WebView,但以某种方式无法连接到该特定上下文.

对此有任何想法吗?

推荐答案

它的工作.我尝试了不同的功能组合和持久的工作组合.使用automationname,不要将平台交换放在功能中.

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

如果您检查服务器日志,也可以看到此. 可用的上下文:本机_App,webview_0

这意味着,您必须按以下方式切换上下文.

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

请注意,上面的设置适用于4.4岁以上的Android版本.如果您有Kitkat或更高版本,只需删除AutomationName即可.使用AutomationName,它将无法正常工作,因为它仅返回本机_App作为可用上下文.

其他推荐答案

您是否尝试强制选择WebView?例如在Java中:

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

我还在测试Cordova应用程序,并且运行良好.

本文地址:https://www.itbaoku.cn/post/102525.html

问题描述

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?

推荐答案

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.

其他推荐答案

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.