baj*_*sko 5 android automated-tests android-uiautomator
我从可访问性获取
Got null根节点 - 重试...
来自的消息UiAutomator,我不知道为什么.
不久:
我们正在对我们的应用程序执行E2E测试,每个测试都从启动活动开始.第一次测试成功运行.当第二次测试开始时,在我们开始寻找UiObject之前一切正常.在那次通话中,我们收到了错误.
详细:
第一次测试开始StartActivity并通过入门导航到MainScreen.
开始屏幕开始:
val intent = Intent(appContext, StartActivity::class.java)
appContext.startActivity(intent)
Run Code Online (Sandbox Code Playgroud)
我也尝试过这样:
val intent = appContext.packageManager.getLaunchIntentForPackage(appContext.originalPackageName).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
appContext.startActivity(intent)
Run Code Online (Sandbox Code Playgroud)
但没有区别,因为测试运行器会在测试运行后自动检查是否存在正在运行的活动,并清除它.
当第二次测试运行时,它仍然从启动,StartActivity但现在跳过启动过程,并且用户(测试运行器)被导航到包含Continue按钮的屏幕.因此,我们找到带有文本的UiObject Continue并等待它出现在屏幕上.一旦出现,我们将点击它.但是,一旦我们启动"查找继续按钮",标题中的消息就会开始出现,几秒钟后,所有内容都会崩溃:
测试运行失败:由于"进程崩溃",仪表运行失败.
片段:
val continueButton = viewByText { appContext stringOf R.string.all_continue }
continueButton.waitToBecomeVisible(1.minute)
continueButton.click()
Run Code Online (Sandbox Code Playgroud)
我猜最后的问题是,是什么导致UiAutomator丢失所有根节点?在调试方法UiDevice一样getUiAutomation,getWindowRoots与实际getRootNode()距离QueryContoller,这是记录上述消息,并没有帮助.
语法糖:
appContext
val appContext: Context get() = InstrumentationRegistry.getTargetContext()
Run Code Online (Sandbox Code Playgroud)
viewByText:
fun viewByText(text: () -> String): UiObject = device.objectByText { text() }
infix fun UiDevice.objectByText(text: () -> String): UiObject =
findObject(UiSelector().text(text()))
Run Code Online (Sandbox Code Playgroud)
waitToBecomeVisible:
infix fun UiObject.waitToBecomeVisible(timeOutMillis: Long) {
if(!waitForExists(timeOutMillis)){
throw UiObjectNotFoundException(
"Timeout: ${timeOutMillis.toDouble()/1000}s. ${this.selector}"
)
}
}
Run Code Online (Sandbox Code Playgroud)
我觉得有必要回答这个问题,因为这根本不是问题UIAutomator。
Got null root node from accessibility - Retrying...您随时可以在日志中找到该消息。然而,UIAutomator 在几次重试后能够继续。
在我们的例子中,我们测试的应用程序与有缺陷的“生命周期”实现进行了 SignalR 集成。结合上述状态,当重试正在进行时,SignalR 因 NPE 失败,导致应用程序崩溃,因此测试仪器进程也崩溃。
我们花了很长时间才弄清楚这种情况对应用程序和测试的因果关系,但好消息是,我们解决了 SignalR 中的讨厌错误。
因此,如果测试仪器运行程序崩溃并Got null...记录了一堆消息,请尝试寻找其他原因,因为主线程在重试期间被阻塞,并且生命周期感知组件可能会遇到麻烦。
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |