译者序: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.OnAccessibilityEventListenerand 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新框架官方简介的更多相关文章

  1. 推荐一款新框架PyScript:在 HTML 嵌入 Python 代码!

    一.介绍 网页浏览器是目前世界上最普遍,最可携的计算机环境.几乎所有人都可以在计算机或是手机上使用网页浏览器,以没有基础设施障碍的方式访问程序. 在 PyCon US 2022 上,知名 Python ...

  2. ReactiveCocoa - iOS开发的新框架

    本文转载至 http://www.infoq.com/cn/articles/reactivecocoa-ios-new-develop-framework ReactiveCocoa(其简称为RAC ...

  3. 新技术新框架不断涌现,目前学习web前端开发都要掌握什么?

    web前端开发由网页制作演变而来,随着web2.0的发展,网页不再只是承载单一的文字和图片,各种丰富媒体让网页的内容更加生动,网页上软件化的交互形式为用户提供了更好的使用体验,这些都是基于前端技术实现 ...

  4. 放弃OT了,找了个新框架ThinkCMF

    放弃OT了,找了个新框架ThinkCMF,感觉还不错,用用看. 选择OT的原因: 1. OT基于ThinkPHP 2. OT对ThinkPHP进行了封装,使得开发应用更加简单 3. yershop应用 ...

  5. Facebook新框架React Native,一套搞定App开发[转]

    Facebook新框架React Native,一套搞定App开发 本文来自微信公众号“给产品经理讲技术”(pm_teacher),欢迎关注. 做为一名产品经理,你是否遇到过这样的窘境,“帮我把字体调 ...

  6. 接口测试入门(5)----新框架重构,使用轻量级的HTTP开发库 Unirest

    之前的第一套框架在使用过程中发现存在以下问题: 一.  框架1缺点: 1.登陆的账号每个人写的不一样,一旦用户在测试环境被修改,则导致用例失败 2.每次读取访问网址,需要在同一个java文件下切换测试 ...

  7. Java引入的一些新特性

    Java引入的一些新特性 Java 8 (又称为 jdk 1.8) 是 Java 语言开发的一个主要版本. Oracle 公司于 2014 年 3 月 18 日发布 Java 8 ,它支持函数式编程, ...

  8. 郑晔谈 Java 开发:新工具、新框架、新思维【转载】【整理】

    原文地址 导语:"我很惊讶地发现,现在许多程序员讨论的内容几乎和我十多年前刚开始做 Java 时几乎完全一样.要知道,我们生存的这个行业号称是变化飞快的.其实,这十几年时间,在开发领域已经有 ...

  9. 读《3M 利率分析新框架》

    目录 读<3M 利率分析新框架> 前言 传统的利率研究框架 3M 利率研究新框架 Macro Monetary Macro Prudence 总结 参考文献 <3M 利率分析新框架& ...

随机推荐

  1. 默认情况下安装的应用程序C盘后提示权限不足,当你开始介意。。。

    最近,不少用户抱怨的经销商.正在使用win 7我们的计算机系统上安装软件后,提示权限不够开放系统,无法启动软件. 在xp该系统是没有问题的.原因是,我们会选择在默认安装路径系统C-disk.和win ...

  2. 于windows建筑物Cocos2d-x win32开发环境

     这份文件是从cocos2d-x复制的官网.. . 在windows7上搭建COCOS2D-X开发环境并不难. 可是因为框架更新过快,非常多用户都有困难.我希望你们觉得这个教程实用. 建议:为了避 ...

  3. oracle Constraint[相似 constraint使用方法总结 I]

    约束简单介绍 约束用于确保数据库数据满足特定的商业逻辑或者企业规则,假设定义了约束,而且数据不符 合约束,那么DML操作(INSERT.UPDATE.DELETE)将不能成功运行.约束包含NOT NU ...

  4. 微软MVP社区夏日巡讲诚邀您的参与: 北京,上海,西宁,成都,西安

  5. zigbee、profile、cluster、 endpoint、

    1.引用ZigBee联盟的说法 Profile: a collection of device descriptions, which together form a cooperative appl ...

  6. Hadoop加zookeeper构建高可靠集群

    事前准备 1.更改Linux主机名,每个人都有配置 vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=hadoop-server1 2.改动IP / ...

  7. zoj-3792-Romantic Value-最小割+数值转化

    假设不须要求边的个数的话,就是一个裸的最小割问题. 求边的个数就用边的权值记录一下. #include <stdio.h> #include <iostream> #inclu ...

  8. 关于Java和.NET之间的通信问题(JSON)

    前言: 最近项目在某XX领导的所谓指引下,非要转型Java,转就转吧,在转的过程前期是个痛苦期,特别.NET旧有项目和Java新项目需要通信时. 进入主题,Java和.NET之间需要通信,这时媒介很多 ...

  9. RabbitHub开源

    RabbitHub开源情况及计划   之前写过一篇”.NET 平台下的插件化开发内核(Rabbit Kernel)”,已经过去三个月了,期间RabbitHub并不是没有了发展更不是放弃了发展,在Rab ...

  10. WebAPI 和 WebService的区别

    webapi用的是http协议,webservice用的是soap协议 webapi无状态,相对webservice更轻量级.webapi支持如get,post等http操作 http soap关系 ...