Android4.3引入的UiAutomation新框架官方简介
译者序:Google在Android 4.3发布时提供了一套新的UiAutomation框架来支持用户界面自动化测试,该框架通过运用已有的Accessibility APIs来模拟用户跟设备用户界面的交互:比如获取窗口界面控件和注入事件等。如在4.3之前UiAutomator工具是通过InputManager或者更早的WindowManager来注入KeyEvent等,4.3之后用的就是新框架UiAutomation使用的Accessibility APIs来注入事件了。
Class Overview/概览
Class for interacting with the device's UI by simulation user actions and introspection of the screen content. It relies on the platform accessibility APIs to introspect the screen and to perform some actions on the remote view tree. It also allows injecting of arbitrary raw input events simulating user interaction with keyboards and touch devices. One can think of a UiAutomation as a special type of AccessibilityService
which does not provide hooks for the service life cycle and exposes other APIs that are useful for UI test automation. 这是一个通过模拟用户操作来与设备用户界面交互以及获取屏幕内容的类。它依赖于平台的辅助功能APIs来在远程的控件树上获取屏幕内容以及执行一些操作。同时它也允许通过注入原生事件(译者注:指的就是InputEvent. KeyEvent也是继承于InputEvent的,所以说它是原生事件)来模拟用户的按键和触屏操作。我们可以认为UiAutomation就是一个特殊类型的AccessibilityService,其既不会为控制服务的生命周期而提供钩子函数,也不会暴露任何其他可以直接用于用户界面测试自动化的APIs. The APIs exposed by this class are low-level to maximize flexibility when developing UI test automation tools and libraries. Generally, a UiAutomation client should be using a higher-level library or implement high-level functions. For example, performing a tap on the screen requires construction and injecting of a touch down and up events which have to be delivered to the system by a call to injectInputEvent(InputEvent, boolean)
. 这个类暴露出来的APIs是很低层的,目的就是为了在开发用户界面测试自动化框架和库时提供最大的弹性。总的来说,一个UiAutomation客户端应该使用一些(基于UiAutomation的)更高层次的库或者实现更高层次的方法。比如,模拟一个用户在屏幕上的点击事件需要构造并注入一个按下和一个弹起事件,然后必须调用UiAutomation的一个injectInputEvent(InputEvent, boolean)的调用来发送给操作系统。 The APIs exposed by this class operate across applications enabling a client to write tests that cover use cases spanning over multiple applications. For example, going to the settings application to change a setting and then interacting with another application whose behavior depends on that setting. 这个类暴露出来的APIs可以跨应用,这样用户就可以编写可以跨越多个应用的测试用例脚本了。比如,打开系统的设置应用去修改一些设置然后再与另外一个依赖于该设置的应用进行交互(译者注:这个在instrumentation这个框架可以做不到的)。 Testing and Debugging(来自android 4.3的APIs官方改动文档)
Automated UI testing/用户界面测试自动化
The new UiAutomation
class provides APIs that allow you to simulate user actions for test automation. By using the platform's AccessibilityService
APIs, the UiAutomation
APIs allow you to inspect the screen content and inject arbitrary keyboard and touch events. 新的UiAutomation这个类提供了一系列的APIs来允许你在测试自动化时模拟用户的操作。通过封装使用了平台上的AccessibilityService APIs, UiAutomation
APIs允许你获取窗口(控件)内容并且注入按键和触屏事件。 To get an instance of UiAutomation
, call Instrumentation.getUiAutomation()
. In order for this to work, you must supply the -w
option with the instrument
command when running your InstrumentationTestCase
from adb shell
. 你可以通过调用Instrumentation.getUiAutomation()来获得UiAutomation的一个实例。为了让它工作起来,当你在adb shell上运行你的InstrumentationTestCase的时候你还需要为instrument命令提供-w这个选项。
With the UiAutomation
instance, you can execute arbitrary events to test your app by callingexecuteAndWaitForEvent()
, passing it a Runnable
to perform, a timeout period for the operation, and an implementation of the UiAutomation.AccessibilityEventFilter
interface. It's within yourUiAutomation.AccessibilityEventFilter
implementation that you'll receive a call that allows you to filter the events that you're interested in and determine the success or failure of a given test case. 通过UiAutomation的实例,你可以调用其executeAndWaitForEvent()对你的应用注入不同的事件来进行测试:该函数会接受一个可执行 Runnable线程对象用来执行事件注入操作,一个操作超时,以及一个实现了UiAutomation.AccessibilityEventFilter的类的实例。正是在这个UiAutomation.AccessibilityEventFilter实现类里面你会收到一个回调来让你过滤那些你喜欢的事件并决定你的测试用例是否通过。
To observe all the events during a test, create an implementation of UiAutomation.OnAccessibilityEventListener
and pass it to setOnAccessibilityEventListener()
. Your listener interface then receives a call toonAccessibilityEvent()
each time an event occurs, receiving an AccessibilityEvent
object that describes the event. 如果要在测试时监控所有的事件,你需要创建一个UiAutomation.OnAccessibilityEventListener的实现类然后把它的实例传递给setOnAccessibilityEventListener()。你的监听接口将会在每次有事件触发的时候接收到一个发送给onAccessibilityEvent()的回调,里面的参数就是一个描述该事件的AccessibilityEvent
的对象 There is a variety of other operations that the UiAutomation
APIs expose at a very low level to encourage the development of UI test tools such as uiautomator. For instance, UiAutomation
can also: UiAutomation
APIs还暴露了很多其他的低层次的操作来鼓励大家去开发如uiautomator这样的用户界面测试工具。比如UiAutomation还可以做以下事情:
- Inject input events/注入事件
- Change the orientation of the screen/改变屏幕的方向
- Take screenshots/截屏
And most importantly for UI test tools, the UiAutomation
APIs work across application boundaries, unlike those inInstrumentation
. 最为用户界面自动化测试工具,最重要的一点是,UiAutomation
APIs 可以跨应用工作,而不像Instrumentation提供了的那些APIs.
作者 | 自主博客 | 微信服务号及扫描码 | CSDN |
天地会珠海分舵 | http://techgogogo.com | 服务号:TechGoGoGo扫描码:![]() |
http://blog.csdn.net/zhubaitian |
Android4.3引入的UiAutomation新框架官方简介的更多相关文章
- 推荐一款新框架PyScript:在 HTML 嵌入 Python 代码!
一.介绍 网页浏览器是目前世界上最普遍,最可携的计算机环境.几乎所有人都可以在计算机或是手机上使用网页浏览器,以没有基础设施障碍的方式访问程序. 在 PyCon US 2022 上,知名 Python ...
- ReactiveCocoa - iOS开发的新框架
本文转载至 http://www.infoq.com/cn/articles/reactivecocoa-ios-new-develop-framework ReactiveCocoa(其简称为RAC ...
- 新技术新框架不断涌现,目前学习web前端开发都要掌握什么?
web前端开发由网页制作演变而来,随着web2.0的发展,网页不再只是承载单一的文字和图片,各种丰富媒体让网页的内容更加生动,网页上软件化的交互形式为用户提供了更好的使用体验,这些都是基于前端技术实现 ...
- 放弃OT了,找了个新框架ThinkCMF
放弃OT了,找了个新框架ThinkCMF,感觉还不错,用用看. 选择OT的原因: 1. OT基于ThinkPHP 2. OT对ThinkPHP进行了封装,使得开发应用更加简单 3. yershop应用 ...
- Facebook新框架React Native,一套搞定App开发[转]
Facebook新框架React Native,一套搞定App开发 本文来自微信公众号“给产品经理讲技术”(pm_teacher),欢迎关注. 做为一名产品经理,你是否遇到过这样的窘境,“帮我把字体调 ...
- 接口测试入门(5)----新框架重构,使用轻量级的HTTP开发库 Unirest
之前的第一套框架在使用过程中发现存在以下问题: 一. 框架1缺点: 1.登陆的账号每个人写的不一样,一旦用户在测试环境被修改,则导致用例失败 2.每次读取访问网址,需要在同一个java文件下切换测试 ...
- Java引入的一些新特性
Java引入的一些新特性 Java 8 (又称为 jdk 1.8) 是 Java 语言开发的一个主要版本. Oracle 公司于 2014 年 3 月 18 日发布 Java 8 ,它支持函数式编程, ...
- 郑晔谈 Java 开发:新工具、新框架、新思维【转载】【整理】
原文地址 导语:"我很惊讶地发现,现在许多程序员讨论的内容几乎和我十多年前刚开始做 Java 时几乎完全一样.要知道,我们生存的这个行业号称是变化飞快的.其实,这十几年时间,在开发领域已经有 ...
- 读《3M 利率分析新框架》
目录 读<3M 利率分析新框架> 前言 传统的利率研究框架 3M 利率研究新框架 Macro Monetary Macro Prudence 总结 参考文献 <3M 利率分析新框架& ...
随机推荐
- 使用shell/python获取hostname/fqdn释疑(转)
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Li ...
- Android+NDK+OpenGLES开发环境配置
1.资源 (1).Android的eclipse开发环境 我用adt-bundle-windows-x86.官方主页就能下载.这是一个打包的版本号,直接执行eclipse.exe你可以开始 (2).N ...
- 使用Java快速实现进度条(转)
基于有人问到怎样做进度条,下面给个简单的做法: 主要是使用JProgressBar(Swing内置javax.swing.JProgressBar)和SwingWorker(Swing内置javax. ...
- 使用Inno Setup 打包jdk、mysql、tomcat、webapp等为一个exe安装包(转)
之前一直都没涉及到打包安装方面的东西,都是另一个同事负责的,使用的工具(installshield)也比较高大上一点,可是后来他离职以后接受的同事也只能是在这个基础上做个简单的配置,然后打包,可是现在 ...
- 【C疯狂的教材】(四)C语言分支语句
1.程序的结构 程序默认从上到下顺序运行(顺序结构) 程序的结构:顺序结构.分支结构.循环结构 2.if分支语句 程序运行的过程中能够有多个选择 格式: if(表达式){ 语句块; } ...... ...
- [ACM] POJ 3252 Round Numbers (的范围内的二元0数大于或等于1数的数目,组合)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8590 Accepted: 3003 Des ...
- zoj 3829 Known Notation(2014在牡丹江区域赛k称号)
Known Notation Time Limit: 2 Seconds Memory Limit: 131072 KB Do you know reverse Polish notatio ...
- 【ThinkingInC++】2、输入和输出流
/** *特征:输入和输出流 *时间:2014年8月8日07:37:35 *作者:cutter_point */ #include<iostream> using namespace st ...
- java基金会成立
在java在,数据收集的操作,应使用非常.最近看了零星收集的小知识,在这里,一点点排序. 它基本上是四个常用的类操作点总结集合. 首先.集合大致分为两个方向.一种是普通的集合类型,通过接口collec ...
- 安装Team Foundation Server 2012过程截图
原文:安装Team Foundation Server 2012过程截图 专题图 1,下载Team Foundation Server 2012 官方下载: http://www.microsoft ...