在 Kotlin 测试中使用 UIAutomator dumpWindowHierarchy

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

我正在使用

UIAutomator
编写一些 Android UI 测试,并希望利用
UiDevice.dumpWindowHierarchy()
功能。

现在我正在调用它,并将完整路径传递给我使用

adb shell uiautomator dump

放置转储的同一位置

这是电话:

device.dumpWindowHierarchy("/<full-path>/window_dump.xml")

设备设置位置

device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

但是在我的测试中,当我在代码中达到该点时,我得到了

java.io.FileNotFoundException: /<path>/window_dump.xml: open failed: EPERM (Operation not permitted)

有人对我如何获得此输出有任何建议吗?到目前为止我尝试过的一切都失败了。

android kotlin adb android-uiautomator
1个回答
0
投票

您可以使用字节数组来避免文件权限问题,如下例所示:https://github.com/dtmilano/CulebraTester2-public/blob/master/app/src/main/java/com/dtmilano/ android/culebratester2/location/UiDevice.kt#L139.

毕竟,您可能会将文件的内容读入字节数组中以对其执行某些操作。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.