【问题标题】:Automation on Android DeviceAndroid 设备上的自动化
【发布时间】:2015-05-04 01:18:19
【问题描述】:
我正在寻找一种在 Android 上自动打开应用程序的方法。 Windows上的QTP之类的东西。我读到了很多需要将手机通过 USB 连接到笔记本电脑的 Android 测试工具。是否可以编写一个可以在设备上自动打开另一个特定应用程序的 android 应用程序?
我了解,如果是我的应用程序或开源应用程序,我可以获取 UI 元素并使用代码自动执行单击或键入,但我如何访问设备上其他应用程序的 UI 元素。
示例:我的应用应该能够打开我的手机键盘并输入数字,或者打开 Truecaller 之类的应用并在主屏幕上的文本视图中输入?类似于网络自动化,但适用于 Android 设备。任何帮助,将不胜感激!谢谢!
【问题讨论】:
标签:
android
automation
ui-automation
android-testing
android-uiautomator
【解决方案1】:
您可以使用 Intent:
//consider context as being the Context of your current app
PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(PACKAGE_NAME);
context.startActivity(intent);
device.wait(Until.hasObject(By.pkg(PACKAGE_NAME)), 10000); //this is a UiAutomator method to wait for the application to be started (or 10 seconds).
您也可以使用单独的 UiAutomator 方法:打开应用程序菜单,单击应用程序图标。可以看一个例子here