Android Gradle 托管设备测试失败需要读取 WindowHierarchy

问题描述 投票:0回答:1

我想转储窗口层次结构并从 gradle 管理的设备读取文件,但在写入文件时我不断遇到文件问题。它应该将其输出到目录 app/build/outputs/managed_device....

java.io.FileNotFoundException:window_dump.xml:打开失败:libcore.io.IoBridge.open处的EROFS(只读文件系统)(IoBridge.java:574)

gradle命令:

./gradlew app:phonesGroupDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.regressions.OnboardingRegressions

OnboardingRegressions.kt

...
// this finds the title but can't find and click the button
val objectTitle = device.findObject(By.textContains("to send you notifications?"))
assert(objectTitle.text.contains("to send you notifications?"))

// want to read why the Allow button is not seen, 
device.dumpWindowHierarchy(File("window_dump.xml"))

// Test fails here when above line is commented out
device.findObject(By.text("Allow")).click()
...

仅供参考,测试在 IDE 中的模拟器上运行完美,但一旦我在托管设备上运行,它就无法找到该按钮。仅供参考,这是一个 API 34 设备

android android-testing gradle-managed-device
1个回答
0
投票

使用它可以在控制台视图或 logcat 中查看它。

 device.dumpWindowHierarchy(System.out as OutputStream)
© www.soinside.com 2019 - 2024. All rights reserved.