【发布时间】:2016-03-05 19:38:42
【问题描述】:
我正在使用 eclipse 编写 UIAutomator 测试并在命令行上执行以下测试以运行它们,如网络上的几个地方所述:
android create uitest-project -n myUITest -t 2 -p C:\Users\JohnDoe\workspace\myUITest
ant build
adb push bin\myUITest.jar /data/local/tmp
adb shell uiautomator runtest myUITest.jar -c Tests.Test1
但是,我最近将测试代码迁移到 Android Studio 以利用 Android)Junit4,选择 uiautomator 2,并将所有内容集成到一个地方(adb 监视器、构建等)。 我按照步骤将以下内容添加到 app/source/Test 下的 gradle 文件中。到目前为止,一切都很好。
dependencies {
compile 'com.google.guava:guava:18.0'
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
androidTestCompile 'com.android.support:support-annotations:23.0.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
// UiAutomator Testing
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.3'
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.example.android.testing.uiautomator.BasicSample"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
运行测试时,我可以进行 gui 测试,例如唤醒屏幕、滑动、触摸,但我发现我不再能够通过 getRuntime.exec 执行 shell 事件来模拟低级输入(物理按钮按下)像之前一样。运行该代码时没有任何反应。 经过进一步研究,我发现 executeShellCommand(字符串命令)是在级别 21 中添加的提供该功能的新 API。但是,被测设备正在运行 kit kat(API 级别 19)。
// Runtime.getRuntime used to work when working under eclipse before migrating to android studio/uiautomator 2
Runtime.getRuntime().exec("sendevent /dev/input/eventX 1 678 1"); // some low level event
有没有办法运行 shell 命令或发送低级/原始输入事件,因为在使用 UIAutomator2 和 android studio 时,通过Runtime.getRuntime 发送 shell 命令似乎不起作用,我不相信我可以使用UIAutomation executeShellCommand 因为我的设备正在运行 android kit kat (api 19)。
我花了一天多的时间浏览帖子,但找不到解决方案。任何帮助/指导将不胜感激。
【问题讨论】:
标签: android eclipse shell android-uiautomator