Luk*_*uke 3 android android-testing android-uiautomator
我无法UiObject2在 androidTest 中使用 UiAutomator 找到元素 ( )。我获得了 UiDevice 实例并尝试使用以下命令查找对象:
MY_UI_DEVICE.findObject(By.res(CURRENT_PACKAGE, id));
Run Code Online (Sandbox Code Playgroud)
CURRENT_PACKAGE是我的应用程序的包MY_UI_DEVICE.getCurrentPackageName()。我也尝试过这个:
MY_UI_DEVICE.wait(Until.findObject(By.res(CURRENT_PACKAGE, id)), 10000);
Run Code Online (Sandbox Code Playgroud)
我可以看到应用程序在右侧屏幕上等待 10 秒(所需的对象仍然存在),但超时后它无法找到它并且测试失败。它在模拟器 (API 23) 上总是失败,但在真实设备 (API 25) 上很少能正常工作。
当我调试代码时,我可以看到,我可以通过手动调用getChild(index)方法序列来获取正确的元素AccessibilityNodeInfo,但在运行时,即使应用程序在我期望的特定元素的正确屏幕上等待,它仍然会失败。
我正在使用不同的 UiDevice 功能,但没有任何帮助,而且我没有想法,所以任何帮助将不胜感激。
我的测试有两个问题:
UiDevice在静态块中获取/初始化实例(作为 util 类中的静态字段)。我将其移入@Before并帮助部分解决了问题。UiDevice. 我用google SamplesInstrumentationRegistry.getTargetContext().getPackageName();中的方法替换了 getting package 。| 归档时间: |
|
| 查看次数: |
10713 次 |
| 最近记录: |