【发布时间】:2017-03-31 09:17:47
【问题描述】:
我正在为 Android 上的 Hydrid 应用编写自动化测试。我有两个问题:
-
在 Appium Inspector 中,我看到了一个具有属性的元素
resource-id: login_button所以我用
点击了这个按钮androidDriver.findElement(By.id("login-button")).click();我得到这个错误:
"An element could not be located with..."当然,如果我找到带有
的元素classname "android.widget.Button"然后就可以了。我问开发者,通常
resource-id会是这样的resource-id: <APP_PACKAGE_NAME>:id/login_button但他说对于 Hydrid 应用程序,他没有
bundleID (APP_PACKAGE_NAME)。 Hydrid APP 没有bundleID是否正确?以及为什么 Appium Inspector 可以看到"resource-id: login_button"但该元素无法找到且无法点击?
-
所以我也尝试使用以下代码将上下文切换到
WEBVIEW:Set<String> contextHandles = appiumDriver.getContextHandles(); Map<String,String> hashMap= new HashMap<String,String>(); for (String contextname : contextHandles){ if (contextname.contains("NATIVE")){ hashMap.put("native", contextname); } else { hashMap.put("webview", contextname); } } //webview androidDriver.context(hashMap.get("webview"));contextHandles有 2 个值:NATIVE_APP和WEBVIEW_<APP_PACKAGE_NAME>。但是当我将上下文设置为webview时,我得到了错误:"There is no such context"
有人可以帮忙吗?谢谢
【问题讨论】:
标签: java android automated-tests appium