通过android sdk tool下载提供的tool\uiautomatorviewer 定位节点元素,可以获取哪些节点信

在Android 4.1发布的时候包含了一种新的测试工具–,uiautomator是用来做UI测试的。也就是普通的手工测试,点击每个控件元素 看看输出的结果是否符合预期。比如 登陆界面 分别输入正确和错误的用户名密码然后点击登陆按钮看看是否能否登陆以及是否有错误提示等。
功能性或者黑盒UI测试不需要测试人员了解程序如何实现的,只需要验证各种操作的结果是否符合预期即可。这样的测试可以分离团队的开发人员和测试人员。大家各干各的没有太多的交集。
常用的UI测试方式就是人工验证啦,就是测试人员拿着各种手机分别安装要测试的程序然后看看是否能正确完成各种预定的功能。但是这种验证方式是非常耗时间的,每次回归都要全部验证一边,并且还容易出现人为错误。比较高效和可靠的UI测试方式就是自动化测试。自动化UI测试创建测试代码来执行测试任务,各种测试任务分别覆盖不同的使用场景,然后使用测试框架来运行这些测试任务。
uiautomator 就是你的自动化UI测试工具。
Android SDK在4.1中提供了如下工具来支持UI自动化测试:
uiautomatorviewer – 一个图形界面工具来扫描和分析应用的UI控件。
uiautomator – 一个测试的Java库,包含了创建UI测试的各种API和执行自动化测试的引擎。
要使用该工具,需要满足如下条件:
Android SDK Tools, Revision 21 or higher
Android SDK Platform, API 16 or higher
uiautomator 测试工具的工作流程
下面是uiautomator 工作流程概述:
安装要测试的应用到手机中,分析应用的UI界面元素 并确保被测试应用的各个控件可以被测试工具获取到。
创建知道测试案例来模拟应用中的用户操作步骤。
编译测试案例代码为Jar包并复制该Jar包到安装了待测应用的测试手机中。
运行测试并查看结果
修改任何发现的bug,然后修复并重新测试。
分析待测应用的UI元素
在开始编写测试案例代码之前,需要熟悉待测应用的UI元素。可以通过uiautomatorviewer 工具来获取应用的界面截图并分析。uiautomatorviewer 工具提供了一个便利的方式来查看UI布局结构,并且可以查看各个控件的相关属性。利用这些信息可以用来创建UI测试代码。
uiautomatorviewer 工具截图
分析待测应用UI界面的步骤如下:
1. 把Android手机连接到电脑上
2. 打开命令行窗口并导航到目录 /tools/
运行如下命令:$ uiautomatorviewer
windows下运行 uiautomatorviewer.bat 命令
3. 点击uiautomatorviewer 工具右上角文件夹按钮旁边的“Device Screenshot”按钮来获取当前 屏幕界面信息。
注意:如果当前电脑连接了多个设备,通过设置ANDROID_SERIAL环境变量来指定要分析的设备。步骤如下:
a.运行如下命令获取连接到电脑的设备序列号
adb devices
b.设置ANDROID_SERIAL为需要测试的设备序列号
Windows:set ANDROID_SERIAL=
Unix: export ANDROID_SERIAL=
如果电脑只连接一个设备则无需设置ANDROID_SERIAL 环境变量。
4. 查看待测应用的UI界面元素属性
把鼠标放到uiautomatorviewer工具左边的截图中的控件上来查看该控件的属性。属性显示在右侧界面下方,上方显示当前界面的布局结构。
点击右侧上方的黄三角按钮(Toggle NAF Nodes)来查看不能被uiautomator测试工具访问到的控件。这些控件只设置了有限的属性,所以导致uiautomator无法获取到这些控件。所以你可能很难测试这些控件。这种情况下你可以要求开发者为这些控件添加必要的属性,比如 如果是ImageView或者ImageButton应该添加android:contentDescription属性。
测试准备工作
在开始使用uiautomator 之前需要完成如下准备工作:
把待测应用安装到测试手机(设备)上
当你准备测试的时候,待测的应用可能还没有发布到市场上。但是你应该具有该应用的APK安装文件,你可以通过ADB工具来安装待测应用到手机中,或者通过其他工具来安装Apk。
辨别待测应用UI控件
在开始编写uiautomator测试代码之前,需要先辨别待测应用的UI控件元素。一般而言,优秀的待测应用的UI元素应该是可见的并且用户可以操作的。这些UI元素也应该具有可见的文本标签、android:contentDescription值或者二则兼具。
通过uiautomatorviewer 工具可以查看应用的可见控件。具体使用情况见上面所述。
确保待测应用是可访问的
由于uiautomator 工具依赖Android设备的可访问行来获取UI控件,所以这不是非常重要的。要支持uiautomator 工具需要一下条件:
使用android:contentDescription属性给 ImageButton, ImageView, CheckBox和其他控件设置标签。
使用android:hint 属性来标记EditText 控件,而不是使用里面的文本(文本内容用户是可以修改的)。
对于用来提供操作视觉反馈的UI(文本或者图标),都添加一个android:hint 属性来识别。
确保所有用户可操作的界面元素都可以通过方向控制键选中(例如轨迹球)。
通过uiautomatorviewer 工具来确保所有的UI元素都可以被测试工具访问到。还可以通过“辅助功能”(在设置界面)中的“TalkBack”等服务来测试UI的可访问性。
设置开发环境
如果你使用的是Eclipse(Adt),则Android SDK提供了额外的工具来帮助你编写uiautomator测试代码和打包测试项目。在Eclipse中创建uiautomator测试项目的过程如下:
创建新的Java项目(注意不是Android项目)。在该项目中来创建测试代码。
在Project Explorer视图中,右键点击测试项目,选择“ Properties & Java Build Path”,然后选择“Libraries” tab界面。在“Libraries”界面选择“ Add Library & JUnit”来添加JUnit3 库。然后点击“Add External JARs… ”并导航到Android SDK目录。选择platforms目录下面的 uiautomator.jar 和 android.jar文件。
设置好的build path如下图:
uiautomator项目类路径设置
如果你不使用Eclipse,则需要确保/platforms/目录中的uiautomator.jar 和 android.jar 位于项目Build path中。
配置好开发环境后就可以开始编写测试代码了。
创建uiautomator 测试案例
uiautomator 测试案例(Test case)需要继承至UiAutomatorTestCase 类。而UiAutomatorTestCase 类继承至junit.framework.TestCase类,所以可以用JUnit的Assert类来比较测试结果。
UI测试的首要任务就是访问测试手机。一般都是从手机的主屏开始测试的。通过uiautomator 提供的API可以从主屏来模拟用户的操作。下面会介绍具体示例。
uiautomator API
uiautomator API在 uiautomator.jar 文件中。这些API分别如下:
代表设备状态。在测试中,可以通过UiDevice实例来检测设备的各种属性,例如当前的屏幕方向以及屏幕尺寸。同时还可以通过UiDevice实例来执行设备级别的操作,例如 把设备设置为横屏或者竖屏、按下Home按键等。
如下是模拟按下Home按键的代码:
getUiDevice().pressHome();
UiSelector
代表一个搜索UI控件的条件。如果发现多个满足条件的控件则会返回第一个控件。返回的结果为UiObject对象。在构造UiSelector的时候可以组合使用多个属性来定位具体的控件。如果没有找到控件则会抛出 UiAutomatorObjectNotFoundException 异常。还可以使用childSelector()函数来嵌套UiSelector 对象。例如,下面的代码演示了如何在当前界面中查找第一个ListView中的带有文本属性为Apps的子控件。
UiObject appItem = new UiObject(new UiSelector()
.className("android.widget.ListView").instance(1)
.childSelector(new UiSelector().text("Apps")));
UiObject appItem = new UiObject(new UiSelector().className("android.widget.ListView").instance(1).childSelector(new UiSelector().text("Apps")));
代表一个UI控件。通过UiSelector来查找UiObject。
如下示例代码演示了如何查找当前显示界面中的取消按钮和确认按钮:
UiObject cancelButton = new UiObject(new UiSelector().text("Cancel"));
UiObject okButton = new UiObject(new UiSelector().text("OK"));
<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c
UiObject cancelButton = new UiObject(new UiSelector().text("Cancel"));UiObject okButton = new UiObject(new UiSelector().text("OK"));
查找到的UiObject实例可以在其他测试代码中重用。需要注意的是:每次使用UiObject做操作的时候uiautomator 都会在当前屏幕重新查找该控件。
如下代码uiautomator 工具在当前界面查找文本内容为“OK”的控件。如果存在并且可用则模拟用户点击该控件。
if(okButton.exists() && okButton.isEnabled())
okButton.click();
<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c
if(okButton.exists() && okButton.isEnabled()){okButton.click();}
还可以限制仅仅查找特定类型的控件。例如 如下代码只查找文本为“Cancel”和“OK”的android.widget.Button类型控件。
UiObject cancelButton = new UiObject(new UiSelector().text("Cancel")
.className("android.widget.Button"));
UiObject okButton = new UiObject(new UiSelector().text("OK")
.className("android.widget.Button"));
UiObject cancelButton = new UiObject(new UiSelector().text("Cancel").className("android.widget.Button"));UiObject okButton = new UiObject(new UiSelector().text("OK").className("android.widget.Button"));
UiCollection
代表控件的集合。获取UiCollection的方式和UiObject一样,通过 UiSelector查找。 UiCollection对应Android系统中的ViewGroup以及子控件。
如下代码演示如何通过UiSelector来获取包含视频集合的UiCollection。
UiCollection videos = new UiCollection(new UiSelector()
.className("android.widget.FrameLayout"));
<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c
UiCollection videos = new UiCollection(new UiSelector().className("android.widget.FrameLayout"));
如果每个视频是放到LinearLayout中的,则可以通过如下方式获取视频的数目:
int count = videos.getChildCount(new UiSelector()
.className("android.widget.LinearLayout"));
<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c
int count = videos.getChildCount(new UiSelector().className("android.widget.LinearLayout"));
如果需要查找标签为“Cute Baby Laughing”的视频,并点击。则可以通过如下方式:
UiObject video = videos.getChildByText(new UiSelector()
.className("android.widget.LinearLayout"), "Cute Baby Laughing");
video.click();
<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c<div class="crayon-num" data-line="crayon-58a35c
UiObject video = videos.getChildByText(new UiSelector().className("android.widget.LinearLayout"), "Cute Baby Laughing");video.click();
同样还可以模拟其他用户操作。例如,模拟选择视频的操作如下:
UiObject checkBox = video.getChild(new UiSelector()
.className("android.widget.Checkbox"));
if(!checkBox.isSelected()) checkbox.click();
UiObject checkBox = video.getChild(new UiSelector().className("android.widget.Checkbox"));if(!checkBox.isSelected()) checkbox.click();
UiScrollable
代表可滚动的控件。可以用UiScrollable来模拟水平或者垂直滚动的UI元素。如果需要操作的元素在屏幕外需要滚动屏幕才能看到的情况下需要使用UiScrollable。
例如,下面的代码显示了如何模拟滚动到“Settings ”菜单并点击“About tablet”菜单的操作。
UiScrollable settingsItem = new UiScrollable(new UiSelector()
.className("android.widget.ListView"));
UiObject about = settingsItem.getChildByText(new UiSelector()
.className("android.widget.LinearLayout"), "About tablet");
about.click()
<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c<div class="crayon-num" data-line="crayon-58a35c<div class="crayon-num crayon-striped-num" data-line="crayon-58a35c<div class="crayon-num" data-line="crayon-58a35c
UiScrollable settingsItem = new UiScrollable(new UiSelector().className("android.widget.ListView"));UiObject about = settingsItem.getChildByText(new UiSelector().className("android.widget.LinearLayout"), "About tablet");about.click()
其他API参考uiautomator api文档。
一个简单的uiautomator 测试案例
如下是一个简单的测试案例代码,模拟了点击Home键回到主屏,然后点击所以应用按钮打开所有应用列表,并滚动到时钟应用。打开时钟应用 并选择闹铃界面的第一个闹钟设置,修改该设置的开关。然后返回到时钟界面再进入倒计时界面。
package com.uia.example.
import android.widget.ListV
import android.widget.S
import com.android.uiautomator.core.UiO
import com.android.uiautomator.core.UiObjectNotFoundE
import com.android.uiautomator.core.UiS
import com.android.uiautomator.core.UiS
import com.android.uiautomator.testrunner.UiAutomatorTestC
public class LaunchSettings extends UiAutomatorTestCase {
// TODO 重要注意: 在运行该测试代码的时候 需要先把手机语言环境设置为英文。
public void testDemo() throws UiObjectNotFoundException {
// 模拟 HOME 键点击事件
getUiDevice().pressHome();
// 现在打开了主屏应用,模拟点击所有应用按钮操作来启动所有应用界面。
// 如果你使用了uiautomatorviewer来查看主屏,则可以发现“所有应用”按钮的
// content-description 属性为“Apps”。可以使用该属性来找到该按钮。
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
// 模拟点击所有应用按钮,并等待所有应用界面起来
allAppsButton.clickAndWaitForNewWindow();
// 在所有应用界面,时钟应用位于Apps tab界面中。下面模拟用户点击Apps tab操作。
// 找到 Apps tab 按钮
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// 模拟点击 Apps tab.
appsTab.click();
// 然后在 Apps tab界面,模拟用户滑动到时钟应用的操作。
// 由于Apps界面是可以滚动的,所有用
// UiScrollable 对象.
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// 设置滚动模式为水平滚动(默认为垂直滚动)
appViews.setAsHorizontalList();
if (allAppsButton.exists() && allAppsButton.isEnabled()) {
// allAppsButton在当前界面已经不可见了 所以这里不会执行
allAppsButton.click();
// 查找时钟应用并点击
UiObject settingsApp = appViews.getChildByText(
new UiSelector().className(android.widget.TextView.class.getName()), "Clock");
settingsApp.clickAndWaitForNewWindow();
// 验证当前显示 的应用包名为时钟
UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.google.android.deskclock"));
// 如果不存在则出错提示
assertTrue("Unable to detect Clock", settingsValidation.exists());
// 模拟点击时间tab
UiObject clock = new UiObject(new UiSelector().description("Clock"));
clock.clickAndWaitForNewWindow();
// 模拟点击下方的闹钟图标
UiObject alarms = new UiObject(new UiSelector().description("Alarms"));
alarms.clickAndWaitForNewWindow();
UiScrollable list = new UiScrollable(new UiSelector().className(ListView.class.getName()));
if (list.getChildCount() & 0) {
UiObject listIndex0 = list.getChild(new UiSelector().index(0));
UiObject switchBtn = listIndex0.getChild(new UiSelector().className(Switch.class.getName()));
boolean isChecked = switchBtn.isChecked();
switchBtn.click();
// 模拟点击返回键
getUiDevice().pressBack();
UiObject timer = new UiObject(new UiSelector().description("Timer"));
timer.clickAndWaitForNewWindow();
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
package com.uia.example.my;&import android.widget.ListView;import android.widget.Switch;&import com.android.uiautomator.core.UiObject;import com.android.uiautomator.core.UiObjectNotFoundException;import com.android.uiautomator.core.UiScrollable;import com.android.uiautomator.core.UiSelector;import com.android.uiautomator.testrunner.UiAutomatorTestCase;&public class LaunchSettings extends UiAutomatorTestCase {&&&&&// TODO 重要注意: 在运行该测试代码的时候 需要先把手机语言环境设置为英文。&&&&public void testDemo() throws UiObjectNotFoundException {&&&&&&&&&// 模拟 HOME 键点击事件&&&&&&&&getUiDevice().pressHome();&&&&&&&&&// 现在打开了主屏应用,模拟点击所有应用按钮操作来启动所有应用界面。&&&&&&&&// 如果你使用了uiautomatorviewer来查看主屏,则可以发现“所有应用”按钮的&&&&&&&&// content-description 属性为“Apps”。可以使用该属性来找到该按钮。&&&&&&&&UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));&&&&&&&&&// 模拟点击所有应用按钮,并等待所有应用界面起来&&&&&&&&allAppsButton.clickAndWaitForNewWindow();&&&&&&&&&// 在所有应用界面,时钟应用位于Apps tab界面中。下面模拟用户点击Apps tab操作。&&&&&&&&// 找到 Apps tab 按钮&&&&&&&&UiObject appsTab = new UiObject(new UiSelector().text("Apps"));&&&&&&&&&// 模拟点击 Apps tab.&&&&&&&&appsTab.click();&&&&&&&&&// 然后在 Apps tab界面,模拟用户滑动到时钟应用的操作。&&&&&&&&// 由于Apps界面是可以滚动的,所有用&&&&&&&&// UiScrollable 对象.&&&&&&&&UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));&&&&&&&&&// 设置滚动模式为水平滚动(默认为垂直滚动)&&&&&&&&appViews.setAsHorizontalList();&&&&&&&&&if (allAppsButton.exists() && allAppsButton.isEnabled()) {&&&&&&&&&&&&// allAppsButton在当前界面已经不可见了 所以这里不会执行&&&&&&&&&&&&allAppsButton.click();&&&&&&&&}&&&&&&&&// 查找时钟应用并点击&&&&&&&&UiObject settingsApp = appViews.getChildByText(&&&&&&&&&&&&&&&&new UiSelector().className(android.widget.TextView.class.getName()), "Clock");&&&&&&&&settingsApp.clickAndWaitForNewWindow();&&&&&&&&&// 验证当前显示 的应用包名为时钟&&&&&&&&&UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.google.android.deskclock"));&&&&&&&&// 如果不存在则出错提示&&&&&&&&assertTrue("Unable to detect Clock", settingsValidation.exists());&&&&&&&&&// 模拟点击时间tab&&&&&&&&UiObject clock = new UiObject(new UiSelector().description("Clock"));&&&&&&&&clock.clickAndWaitForNewWindow();&&&&&&&&// 模拟点击下方的闹钟图标&&&&&&&&UiObject alarms = new UiObject(new UiSelector().description("Alarms"));&&&&&&&&alarms.clickAndWaitForNewWindow();&&&&&&&&&UiScrollable list = new UiScrollable(new UiSelector().className(ListView.class.getName()));&&&&&&&&if (list.getChildCount() & 0) {&&&&&&&&&&&&UiObject listIndex0 = list.getChild(new UiSelector().index(0));&&&&&&&&&&&&UiObject switchBtn = listIndex0.getChild(new UiSelector().className(Switch.class.getName()));&&&&&&&&&&&&&boolean isChecked = switchBtn.isChecked();&&&&&&&&&&&&&switchBtn.click();&&&&&&&&}&&&&&&&&// 模拟点击返回键&&&&&&&&getUiDevice().pressBack();&&&&&&&&&UiObject timer = new UiObject(new UiSelector().description("Timer"));&&&&&&&&timer.clickAndWaitForNewWindow();&&&&&}}
打包测试代码并在测试机上运行
如下步骤打包测试代码并在测试机运行的步骤:
1.创建打包测试代码的Build脚本。通过如下命令来生成Build脚本:
&android-sdk&/tools/android create uitest-project -n &name& -t 1 -p &path&
&android-sdk&/tools/android create uitest-project -n &name& -t 1 -p &path&
&name&&span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, font-size: 13 line-height: 19"&是包含测试代码的项目名称,&path&是包含测试代码的项目文件路径。-t后面的1是Android sdk版本id。&/span&
<div class="crayon-num" data-line="crayon-58a35c
&name&&span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, font-size: 13 line-height: 19"&是包含测试代码的项目名称,&path&是包含测试代码的项目文件路径。-t后面的1是Android sdk版本id。&/span&
注意: 在创建Build脚本之前,已经创建好了测试项目并编写好了测试代码。只不过该测试项目还没有包含打包脚本所以无法打包运行。在创建Build脚本的时候,&name&属性就是测试项目的名称、&path&就是已经创建的测试项目在电脑中的文件夹路径。 如果电脑上安装了多个版本的Android sdk,则需要运行/tools/android list target 来查看每个SDK的id。选择4.1以上的id即可。
2. 设置ANDROID_HOME 环境变量。
Windows:set ANDROID_HOME=
Unix:export ANDROID_HOME=
3. 打开命令行创建,导航到第一步中的目录中,运行 ant build 来打包。
4. 通过adb push命令把上一步打包出来的jar文件复制到测试手机中。
adb push &path&/bin/&name&.jar /data/local/tmp/
类似如下代码:
adb push ~/dev/workspace/LaunchSettings/bin/LaunchSettings.jar /data/local/tmp/
运行uiautomator 测试
下面是运行 LaunchSettings.jar jar包中测试代码的命令。测试代码位于com.uia.example.my包中。
adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.LaunchSettings
关于uiautomator 的更多信息参考这里:
下面是一些使用uiautomator 做UI测试的最佳实践
在待测应用可能运行的尽可能多的设备上跑uiautomator 测试。例如 在不同的屏幕密度、不同的屏幕尺寸上运行测试。
还应该在一些常规场景下测试UI,例如 电话打入情况、网络连接断开的情况等。
本文出自 云在千峰,转载时请注明出处及相应链接。本文永久链接: /?p=504
&#404;回顶部Android uiautomator 使用入门官方教程
我的图书馆
Android uiautomator 使用入门官方教程
Android uiautomator 使用入门官方教程
本文英文原文
已把其翻译为中文,希望各位多多了解uiautomator 安卓自动化测试工具,非常好用,我很喜欢!
In addition to unit testing the individual components that
make up your Android application (such as activities, services, and content
providers), it is also important that you test the behavior of your
application’s user interface (UI) when it is running on a device. UI testing
ensures that your application returns the correct UI output in response to a
sequence of user actions on a device, such as entering keyboard input or
pressing toolbars, menus, dialogs, images, and other UI controls.
除了对组成安卓应用的单独的组件(如,activities、services、和content
providers)进行单元测试,测试应用运行时的界面行为也很必要。UI测试确保应用在一系列用户操作后,如键盘输入、按压工具栏、菜单、对话框、图片或其他UI空间,返回正确的UI输出。
Functional or black-box UI testing does not require testers
to know the internal implementation details of the app, only its expected output
when a user performs a specific action or enters a specific input. This approach
allows for better separation of development and testing roles in your
organization.
功能或黑盒测试不需要测试人员知晓应用的内部实现细节,只要明白在一系列用户操作后返回期望的UI输出即可。这种测试方法运行开发、测试角色的可以由组织中的不同团队来担任。
One common approach to UI testing is to run tests manually
and verify that the app is behaving as expected. However, this approach can be
time-consuming, tedious, and error-prone. A more efficient and reliable approach
is to automate the UI testing with a software testing framework. Automated
testing involves creating programs to perform testing tasks (test cases) to
cover specific usage scenarios, and then using the testing framework to run the
test cases automatically and in a repeatable manner.
UI测试的通用方式是手工运行测试,验证应用如期望般运行。然而,此种方法非常耗时、无趣、易出错。更有效、更可靠的方式是使用软件测试框架自动化UI测试。自动化测试涉及创建程序执行测试任务(测试用例)来覆盖指定的用户场景,然后使用测试框架自动化重复地运行测试用例。
Overview 概述
The Android SDK provides the following tools to support
automated, functional UI testing on your application:
Android SDK提供下述工具;来支持自动化的功能界面测试:
uiautomatorviewer – A GUI tool to scan and analyze the UI components of an
Android application. 扫描、分析待测应用的UI组件的图像工具 uiautomator – A Java library containing APIs to create customized functional
UI tests, and an execution engine to automate and run the tests.
包含创建定制功能界面测试API和自动化运行测试用例的引擎的JAVA类库。
To use these tools, you must have the following versions of
the Android development tools installed:
为使用这些工具,需要安装的android工具工具的版本信息:
Android SDK Tools, Revision 21 or higherAndroid SDK Platform, API 16 or higher
Workflow for the the uiautomator testing framework&
使用uiautomator测试框架的工作流程
Here’s a short overview of the steps required to automate
UI testing:
简单介绍下UI自动化测试的主要步骤:
Prepare to test by installing the app on a test device, analyzing the app’s
UI components, and ensuring that your application is accessible by the test
automation framework.
安装待测应用到待测设备,准备测试,分享待测应用的UI组件,区别待测应用可以被uiautomator测试框架访问。 Create automated tests to simulate specific user interactions on your
application. 创建自动化测试来模拟指定的用户和待测应用的交互 Compile your test cases into a JAR file and install it on your test device
along with your app. 编译测试用例成jar文件,安装到装有待测应用的待测设备上 Run the tests and view the test results. &执行测试、检查测试结果 Correct any bugs or defects discovered in testing .修正测试时发现的缺陷
Analyzing Your Application’s UI& 分析应用的UI界面
Before you start writing your test cases, it’s helpful to
familiarize yourself with the UI components (including the views and controls)
of the targeted application. You can use the uiautomatorviewer tool to take a
snapshot of the foreground UI screen on any Android device that is connected to
your development machine. The uiautomatorviewer tool provides a convenient
visual interface to inspect the layout hierarchy and view the properties of the
individual UI components that are displayed on the test device. Using this
information, you can later create uiautomator tests with selector objects that
target specific UI components to test.
在写测试用例之前,你最好熟悉待测应用的UI组件(包括视图views和控件controls)。uiautomatorviewer可以帮助你实现这一点,uiautomatorviewer获取当前UI界面的快照,提供一个可视化的界面,来检查布局层次、查看每一个显示在设备上的UI组件的属性。在以后的uiautomator测试中,你可以利用uiautomator提供的信息来选择特定的UI组件。
Figure 1.&The uiautomatorviewer showing the captured
interface of a test deviice.
图1&&uiautomatorviewer捕获的测试设备的界面
To analyze the UI components of the application that you
want to test:
Connect your Android device to your development machine.Open a terminal window and navigate to &android-sdk&/tools/.Run the tool with this command: $ uiautomatorviewer
To capture a screen for analysis, click the&Device Screenshot&button in the
GUI of the uiautomatorviewer tool.
Note:&If you have more than one device connected, specify the device for
screen capture by setting theANDROID_SERIAL environment variable:
Find the serial numbers for your connected devices by running this command:
$ adb devices Set the ANDROID_SERIAL environment variable to select the device to test:
In Windows: set &ANDROID_SERIAL =&
device serial number & In UNIX: export &ANDROID_SERIAL =&
device serial number &
If you are connected to only a single device, you do not need to set the
ANDROID_SERIAL environment variable.View the UI properties for your application:
Hover over the snapshot in the left-hand panel to see the UI components
identified by the uiautomatorviewer tool. You can view the component’s
properties listed in the lower right-hand panel, and the layout hierarchy in the
upper right-hand panel.Optionally, click on the&Toggle NAF Nodes&button to see UI components that
are not accessible to the uiautomatortesting framework. Only limited information
may be available for these components.
分析待测程序的UI组件的步骤: & &&&1. 将android设备连接到有开发环境机器上
& &&&2. 打开命令行终端窗口,进入android sdk tool所在目录 & &&&3.
运行以下命令: & && && &&&$ uiautomatorviewer & &&&4.
捕获到待分析的界面后,点击设备快照“Device Screenshot”按钮 & && &&
&注意:如果你连接了多个设备,需要指定ANDROID_SERIAL 环境变量,来说明对哪个设备进行截屏: & && && &&
&& && &a. 运行以下命令,找到你的设备序列号 & && && && && && && &&&$ adb
devices & && && && && && &b. 设置环境变量ANDROID_SERIAL
& && && && && && && &&&在windows上: & && && && && && &&
&& && && &set ANDROID_SERIAL=&device serial number& & &&
&& && && && && &&&在*nix上: & && && && && && && && && && &export
ANDROID_SERIAL=&device serial number& & && && &
如果你只连接一个设备,则不需要设置 & && &5.
查看应用的UI属性 & && && & 1.
在快照的左侧面板上,可以看到uiautomatorviewer显示的UI组件;在右侧,下边是组件的属性,上边是布局的层次 &
&& && & 2. 你也可以点击”Toggle NAF
Nodes“按钮,来显示uiautomator框架无法访问的UI组件。对于那些组件,只有有限的属性信息可以供uiautomator使用。
Preparing to Test 准备测试
Before using the uiautomator testing framework, complete
these pre-flight tasks:
在开始使用uiautomator测试框架之前,完成下述准备工作:
Load the application to a device& 安装待测应用到待测设备
If you are reading this document, chances are that the
Android application that you want to test has not been published yet. If you
have a copy of the APK file, you can install the APK onto a test device by using
the adb tool. To learn how to install an APK file using the adb tool, see the&
&documentation.
若你阅读本文档,可能意味着待测的安卓应用还没有发布。若有有APK文件的安装文件,你可以使用adb工具安装APK文件到待测设备上。为了解更多如何安装APK的知识请参考ADB文档。
Identify the application’s UI components& 识别待测应用的UI组件
Before writing your uiautomator tests, first identify the
UI components in the application that you want to test. Typically, good
candidates for testing are UI components that are visible and that users can
interact with. The UI components should also have visible text labels,&
&values, or
You can inspect the visible screen objects in an
application conveniently by using the uiautomatorviewer tool. For more
information about how to analyze an application screen with this tool, see the
. For more
information about the common types of UI components provided by Android, see&
在编写uiautomator测试前,首先识别待测应用的UI组件。一般来说,适合测试的是可以访问的,用户可以交互的UI组件。UI组件还应该包含可见的文本标签,
&值,或全部。可以使用uiautomatorviewer工具来方便地查看待测应用在屏幕上的
对象。关于如何使用该工具分析应用屏幕的更多信息,可以参考本文档的相应部分。关于安卓提供的通用类型的UI组件,可以参考安卓官方文档。
Ensure that the application is accessible& 确保待测应用可访问
This step is required because the uiautomator tool depends
on the accessibility features of the Android framework to execute your
functional UI tests. You should include these minimum optimizations to support
the uiautomator tool:
本步骤非常必要,因为uiautomator工具依赖安卓的可访问特性来执行功能界面测试。你应该在你的程序中加入下述简单的优化来支持uiautomator测试框架:
&attribute to
label the&
&and other user interface
controls. 使用&
和其他界面控件的标签 Provide an&
&attribute& instead
&of a content description for&
&fields 为&
&输入框提供&
&属性,而不是
Associate an&
&attribute with any graphical
icons used by controls that provide feedback to the user (for example, status or
state information). 用于反馈给用户信息(如状态、声明信息)的控件的图标应该包含
属性 Make sure that all the user interface elements are accessible with a
directional controller, such as a trackball or D-pad.确保在使用方向控制键(如trackball或 D-pad)时所有的UI元素也是可访问的, Use the uiautomatorviewer tool to ensure that the UI component is accessible
to the testing framework. You can also test the application by turning on
accessibility services like TalkBack and Explore by Touch, and try using your
application using only directional controls.使用uiautomatorviewer工具确保UI组件可以被uiautomator工具访问。你还能通过打开如TalkBack
或Explore by Touch的可访问服务,使用方向控制键盘来测试应用的可访问性。
For more information about implementing and testing
accessibility, see&
关于实现和测试可访问性的更多信息,可以参考android官方站点。
Note:&To identify the non-accessible components in the UI,
click on the&Toggle NAF Nodes&option in theuiautomatorviewer tool.
Generally, Android application developers get accessibility
support for free, courtesy of the&
&classes. However, some
applications use custom view components to provide a richer user experience.
Such custom components won’t get the accessibility support that is provided by
the standard Android UI components. If this applies to your application, ensure
that the application developer exposes the custom drawn UI components to Android
accessibility services, by implementing the
&class. For more
information about making custom view components accessible, see&
备注:为识别不可访问的UI组件,使用uiautomatorviewer工具的的Toggle NAF
Nodes选项。通常,android应用开发者不需要考虑是否支持可访问性,既然UI组件继承View和ViewGroup类。然而,对于使用定制试图组件提供用户体验的应用,无法获得自由标准androidUI组件才有的可访问性支持。如果你的测试项目有类似情况,确保应用开发者通过实现
暴露定制组件给android可访问性服务。关于更多信息,可以参考android官方站点。
Configure your development environment& 配置测试开发环境
If you’re developing in Eclipse, the Android SDK provides
additional tools that help you write test cases using uiautomatorand buiild your
JAR file. In order to set up Eclipse to assist you, you need to create a project
that includes the uiautomatorclient library, along with the Android SDK library.
To configure Eclipse:
若使用eclipse进行开发,android
sdk提供额外的工具帮助开发者编写、构建uiautomator测试用例。首先需要创建一个包括uiautomator客户端库文件和android
sdk库的测试项目,步骤如下:
Create a new Java project in Eclipse, and give your project a name that is
relevant to the tests you’re about to create (for example, “MyAppNameTests”). In
the project, you will create the test cases that are specific to the application
that you want to test. &创建一个eclipse java项目,注意命名,如:
“MyAppNameTests”。在项目中,编写测试用例来测试指定的待测应用。 From the&Project Explorer, right-click on the new project that you created,
then select&Properties & Java Build Path, and do the following:
在项目资源管理器视图下,右击新建的项目,选择属性-java 构建路径,完成下述设置:
Click&Add Library & JUnit&then select&JUnit3&to add JUnit support.&
添加junit3类库,支持junit。 Click&Add External JARs…&and navigate to the SDK directory. Under the
platforms directory, select the latest SDK version and add both the
uiautomator.jar and android.jar files. 添加类库 uiautomator.jar 和
android.jar。
If you did not configure Eclipse as your development
environment, make sure that the uiautomator.jar and android.jarfiles from the
&android-sdk&/platforms/&sdk& directory are in your Java class
Once you have completed these prerequisite tasks, you’re
almost ready to start creating your uiautomator tests.
若测试环境开发环境部署eclipse,确保&
&android-sdk&/platforms/&sdk&目录下的
uiautomator.jar 和android.jar在类路径中。一旦完成上述配置,就可以开始编写uiautomator测试用例了。
Creating uiautomator Tests& 创建uiautomator测试用例
To build a test that runs in the uiautomator framework,
create a test case that extends the&
&class. In Eclipse,
the test case file goes under the src directory in your project. Later, you will
build the test case as a JAR file, then copy this file to the test device. The
test JAR file is not an APK file and resides separately from the application
that you want to test on the device.
Because the&
&class extends
junit.framework.TestCase, you can use the JUnit Assert class to test that UI
components in the app return the expected results. To learn more about JUnit,
you can read the documentation on the&
&home page.
The first thing your test case should do is access the
device that contains the target app. It’s also good practice to start the test
from the Home screen of the device. From the Home screen (or some other starting
location you’ve chosen in the target app), you can use the classes provided by
the uiautomator API to simulate user actions and to test specific UI components.
For an example of how to put together a uiautomator test case, see the&
为创建使用uiautomator测试框架的测试,创建继承UiAutomatorTestCase类的测试用例即可。在eclipse中,测试用例文件维护在项目的src文件中。稍后,会被测试用例构建为jar文件,然后复制jar文件到待测设备。jar文件不是APK文件,独立存在于待测设备上的待测应用。因为
&junit.framework.TestCase,可以使用junit断言类Assert来验证UI元素放火期望的结果。为了解更多关于JUnit的姿势,可以访问junit.org站点。创建测试用例时,首先应该访问包含待测应用的待测设备。最佳实践是,从设备的主屏幕开始运行测试。从主屏幕开始,你能使用uiautomator提供的API类来模拟用户动作、检测UI组件。本文提供一个例子来演示如何使用uiautomator执行测试。见下文。
uiautomator API &uiautomator 编程接口API
The uiautomator API is bundled in the uiautomator.jar file
under the &android-sdk&/platforms/ directory. The API includes these key
classes that allow you to capture and manipulate UI components on the target
包含uiautomator API的 uiautomator.jar位于
&android-sdk&/platforms/ 目录下,uiautomator
API包含关键的类,可以用来捕获和操控待测安卓应用的UI组件。
Represents the device state. In your tests, you can call methods on the&
&instance to check for the state
of various properties, such as current orientation or display size. Your tests
also can use the&
&instance to perform device level
actions, such as forcing the device into a specific rotation, pressing the d-pad
hardware button, or pressing the Home and Menu buttons.
UiDevice代表设备状态。在测试时,可以调用UiDevice实例的方法来检查不同属性的状态,如当前的屏幕旋转方向货展示大小。测试代码还能使用UiDevice实例来执行设备级的操作,如强制设备横竖屏,按压d-pad硬件按钮,或按压主屏幕键和菜单键。
To get an instance of&
&and simulate a Home button
获取UiDevice实例,模拟按压主屏幕键的代码如下:
getUiDevice (). pressHome
Represents a search
criteria to query and get a handle on specific elements in the currently
displayed UI. If more than one matching element is found, the first matching
element in the layout hierarchy is returned as the target UiObject. When
constructing a&
, you can chain together
multiple properties to refine your search. If no matching UI element is found, a
thrown. You can use the&
&method to nest multiple&
&instances. For example, the
following code example shows how to specify a search to find the first&
&in the currently displayed UI,
then search within that&
&to find a UI element with the
text property Apps.
UiSelector代表一种搜索标准,可以在当前展示界面上查询和获取特定元素的句柄。若找到多于一个的匹配元素,则返回布局层次结构上的第一个匹配元素作为目标UiObject。当构造一个UiSelector对象时,可以使用链式调用多个属性来缩小查询范围。如无匹配元素,则返回异常
。你还可以使用
&方法来嵌套多个Uiselector实例。例如。下面的代码演示如何制定查询来定位在当前界面的第一个ListView,然后在返回的ListView内定位一个带有Apps文本属性的界面元素。
UiObject &appItem& =
& new & UiObject
( new & UiSelector
() . className
( “android.widget.ListView” ).
instance ( 1 )
. childSelector (
new & UiSelector ().
text ( “Apps” )));
Represents a UI element. To
&instance, use a UiSelector that
describes how to search for, or select, the UI element.
The following code example shows how to construct&
&instances that represent
a&Cancel&button and a&OKbutton in your application.
UiObject代表一个UI元素。为创建一个UiObject实例,使用用来描述如何搜索、选定UI元素的UiSelector实例:
UiObject &cancelButton& =
& new & UiObject
( new & UiSelector
(). text ( “Cancel”
)); UiObject &okButton&
UiObject ( new &
UiSelector (). text (
“OK” ));
You can reuse the&
&instances that you have created
in other parts of your app testing, as needed. Note that the uiautomator test
framework searches the current display for a match every time your test uses a&
instance to click on a UI element
or query a property.
In the following code example, the uiautomator test framework searches for a
UI element with the text property OK. If a match is found and if the element is
enabled, the framework simulates a user click action on the element.
必要时,可以重用测试项目中已经创建的UiObject实例。注意,测试用例每次使用UiObject实例来点击UI元素或查询属性时,uiautomator测试框架会搜索当前的界面来寻找匹配。在下面的代码中,uiautomator测试框架搜索带有OK文本属性的UI元素。若发现匹配,并且该元素启用,框架会模拟用户的在该元素上的点击操作。
if ( okButton .
exists () & &&
&okButton . isEnabled ())
{ okButton .
click (); }
You can also restrict the search to find only elements of a specific class.
For example, to find matches of the&
还可以限制搜索在几个特定的类中寻找元素,例如,为发现Button类的匹配: UiObject
&cancelButton& = & new
& UiObject ( new
& UiSelector (). text
( “Cancel” )
. className (
“android.widget.Button” ));
UiObject &okButton& =
& new & UiObject
( new & UiSelector
(). text ( “OK”
) . className
( “android.widget.Button” ));
Represents a collection
of items, for example songs in a music album or a list of emails in an inbox.
Similar to a
, you construct a&
&instance by specifying a&
should search for a UI
element that is a container or wrapper of other child UI elements (such as a
layout view that contains child UI elements). For example, the following code
snippet shows how to construct a&
&to represent a video album
that is displayed within a&
UiCollection代表元素条目的集合,例如音乐专辑中的歌曲或邮箱收件箱列表。类似UiObject,需要指定UiSelector来构造UiCollection。
用于构造UiCollection的UiSelector一般搜索容器或包裹器类的界面元素,这样的容器或包裹器类的界面元素包含其他子UI元素,例如包含子元素的布局视图。下面举例说明,下面的代码片段演示如何构造一个UiCollection实例,该实例代表一个包含在FrameLayout布局中的视频专辑。
UiCollection &videos& = &
new & UiCollection (
new & UiSelector ()
. className (
“android.widget.FrameLayout” ));
If the videos are listed within a&
&view, and you want to to
retrieve the number of videos in this collection:
如果视频专辑包含在LinearLayout视图下,你能获取视频集合的数目: int
&count& = &videos .
getChildCount ( new &
UiSelector () .
className ( “android.widget.LinearLayout”
If you want to find a specific video that is labeled with the text element
Cute Baby Laughing from the collection and simulate a user-click on the
若想从视频集合中寻找带有文本元素 Cute Baby
Laughing的标签的视频,然后模拟用户在该视频上进行点击,可使用如下代码: UiObject
&video& = &videos .
getChildByText ( new &
UiSelector () .
className ( “android.widget.LinearLayout”
), & “Cute Baby Laughing” );
video . click ();
Similarly, you can simulate other user actions on the UI object. For example,
if you want to simulate selecting a checkbox that is associated with the
类似的,还能模拟其他用户操作,如,如想模拟选定一个关联视频的多选框,可以使用如下代码:
UiObject &checkBox& =
&video . getChild (
new & UiSelector ()
. className (
“android.widget.Checkbox” ));
if (! checkBox
. isSelected ()) &checkbox
. click ();
Represents a scrollable
collection of UI elements. You can use the&
&class to simulate vertical
or horizontal scrolling across a display. This technique is helpful when a UI
element is positioned off-screen and you need to scroll to bring it into view.
For example, the following code shows how to simulate scrolling down the
Settings menu and clicking on an&About tablet&option:
UiScrollable代码可滑动的UI元素集合。可以使用UiScrollable类来模拟界面的横竖屏的滑动。该技术可以应用于界面元素隐藏在屏幕外,可以通过滑动来展示的情况下。例如,下面的代码演示如何模拟下滑设置按钮,然后点击About
tablet选项。 UiScrollable &settingsItem&
UiScrollable ( new &
UiSelector () .
className ( “android.widget.ListView”
)); UiObject &about&
= &settingsItem .
getChildByText ( new &
UiSelector () .
className ( “android.widget.LinearLayout”
), & “About&&tablet” );
about . click ()
For more information about these APIs, see the&
&reference. 更多关于API的信息,请参考官方参考文档。
A sample uiautomator test case&
uiautomator测试用例的一个例子
The following code example shows a simple test case which
simulates a user bringing up the Settings app in a stock Android device. The
test case mimics all the steps that a user would typically take to perform this
task, including opening the Home screen, launching the&All Apps&screen,
scrolling to the&Settings&app icon, and clicking on the icon to enter the
Settings app.
下面的代码例子演示一个简单的测试用例,它可以用来模拟用户在一个安卓设备上启动设置Settings应用。该测试用例模拟用户完成这样的场景的所有步骤,包括打开主屏幕,启动全部应用All
Apps & 屏幕,滑动到设置应图标上,点击该图标进入设置应用。
package &com .
uia . example .
// Import the uiautomator libraries import
&com . android .
uiautomator . core .
UiObject ; import
&com . android .
uiautomator . core .
UiObjectNotFoundException ;
import &com .
android . uiautomator .
core . UiScrollable ;
import &com .
android . uiautomator .
core . UiSelector ;
import &com .
android . uiautomator .
testrunner . UiAutomatorTestCase
public & class &
LaunchSettings & extends &
UiAutomatorTestCase & {
public & void &testDemo
() & throws &
UiObjectNotFoundException & {
// Simulate a short press on the HOME button. //模拟触压一下主屏幕键
& && &getUiDevice (). pressHome
// We’re now in the home screen. Next, we want to simulate&
// a user bringing up the All Apps screen. //
If you use the uiautomatorviewer tool to capture a snapshot& //
of the Home screen, notice that the All Apps button’s& //
content-description property has the value “Apps”.&&We can& //
use this property to create a UiSelector to find the button.
//现在在主屏幕上,接下来,需要模拟用户进入全部应用的屏幕上。
//若你使用uiautomatorviewer工具捕获主屏幕的快照,注意一下”全部应用All
Apps“的按钮的content-description属性值为“Apps”. //我们使用该属性创建一个UiSelector 对象来定位该按钮。
& && & UiObject
&allAppsButton& = & new
& UiObject ( new
& UiSelector ()
. description (
“Apps” ));
// Simulate a click to bring up the All Apps screen.
//模拟点击进入全部应用的屏幕 & && &allAppsButton
. clickAndWaitForNewWindow ();
// In the All Apps screen, the Settings app is located in&
// the Apps tab. To simulate the user bringing up the Apps tab,
// we create a UiSelector to find a tab with the text&
// label “Apps”.
//在全部应用的屏幕上,设置应用位于Apps选项卡内。为模拟用户进入该选项卡,我们创建一个UiSelector
对象来定位该带“Apps”文本标签属性的选项卡。 & && & UiObject
&appsTab& = & new
& UiObject ( new
& UiSelector ()
“Apps” ));
// Simulate a click to enter the Apps tab. //模拟点击进入Apps选项卡
& && &appsTab . click
// Next, in the apps tabs, we can simulate a user swiping until
// they come to the Settings app icon.&&Since the container
view& // is scrollable, we can use a UiScrollable object.
//接下来在apps选项卡内,我们模拟用户滑动屏幕直至找到设置应用的图标。
//既然容器视图可以滑动,我们可以使用UiScrollable 对象。
UiScrollable &appViews&
UiScrollable ( new &
UiSelector () .
scrollable ( true ));
// Set the swiping mode to horizontal (the default is vertical)
//社会中滑动模式为水平,默认为垂直滑动 & && &appViews
. setAsHorizontalList ();
// Create a UiSelector to find the Settings app and simulate& && &
// a user click to launch the app.
//创建一个UiSelector对象来定位设置应用,模拟用户点击来启动该应用 & && &
UiObject &settingsApp& =
&appViews . getChildByText (
new & UiSelector ()
. className (
android . widget .
TextView . class .
getName ()), “Settings”
); settingsApp .
clickAndWaitForNewWindow ();
// Validate that the package name is the expected one
//验证包名与预期一致 UiObject
&settingsValidation& = & new
& UiObject ( new
& UiSelector ()
. packageName (
“com.android.settings” )); assertTrue
( “Unable to detect Settings” ,
settingsValidation . exists
Building and Deploying Your uiautomator Tests&
构建和部署uiautomator测试
Once you have coded your test, follow these steps to build
and deploy your test JAR to your target Android test device:
完成测试编码后,依据下面的步骤来构建和部署你的测试jar文件到android测试设备上:
Create the required build configuration files to build the output JAR. To
generate the build configuration files, open a terminal and run the following
command: &android-sdk& /tools/android create
uitest-project -n& &name& &-t 1 -p&
&path& The &name& is the name of the project that
contains your uiautomator test source files, and the &path& is the path to
the corresponding project directory. &&
创建需要的构建配置文件来构建要输出的JAR文件。为了生成构建配置文件,打开一个命令行终端,运行下面的命令:
&android-sdk& /tools/android create uitest-project
-n & &name& & -t 1
-p & &path&,其中
&name&是包含uiautomator测试源文件的测试项目名称,&path&
&是对应的测试项目目录的路径。 From the command line, set the ANDROID_HOME variable:
在命令行窗口中,设置ANDROID_HOME变量。
In Windows: set &ANDROID_HOME =&
path_to_your_sdk & In UNIX: export &ANDROID_HOME =&
path_to_your_sdk & Go to the project directory where your build.xml file is located and build
your test JAR.& ant build& 进入包括build.xml文件的测试项目目录下,使用命令ant
build构建你的测试的JAR文件。 Deploy your generated test JAR file to the test device by using the adb push
command: adb push& &path_to_output_jar&
& / data /
local / tmp /
&部署生成的测试的JAR文件到待测设备上的命令为:db push command:adb push
&path_to_output_jar& /data/local/tmp/
Here’s an example: 例子如下:
adb push& ~ /dev/
workspace / LaunchSettings /
bin / LaunchSettings .
jar& / data /
local / tmp /
Running uiautomator Tests& 运行uiautomator测试用例
Here’s an example of how to run a test that is implemented
in the LaunchSettings.jar file. The tests are bundled in thecom.uia.example.my
package: 下面的例子演示如何运行实现在
LaunchSettings.jar文件中的一个测试用例,该测试用例包含在包
com.uia.example.my中。 adb shell
uiautomator runtest& LaunchSettings .
jar& - c com .
uia . example .
my . LaunchSettings
To learn more about the syntax, subcommands, and options
for uiautomator, see the&
&reference.
更多关于uiautomator的语法语义,子命令或选项,请参考uiautomator的官方引用文档。
Best Practices& 最佳实践
Here are some best practices for functional UI testing with
the uiautomator framework:
下面是一些使用uiautomator测试框架进行功能界面测试的最佳实践:
Ensure that you validate the same UI functions on your application across
the various types of devices that your application might run on (for example,
devices with different screen densities).务必要在待测应用要运行的各种设备上验证待测应用的界面功能&&(例如,不同屏幕密度的各种设备) You should also test your UI against common scenarios such as in-coming
phone calls, network interruptions, and user-initiated switching to other
applications on the device.还应在各种通用场景下测试UI界面,比如忽然来电、网络中断和用户切换应用到设备上的其他应用等等。
发表评论:
TA的最新馆藏[转]&[转]&[转]&}

我要回帖

更多关于 uiautomatorviewer 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信