11.UiDevice
access and perform operations on the device on which the target app is running. You can call its methods to access device properties such as current orientation or display size. The UiDevice
class also let you perform actions such as:
- Change the device rotation
- Press a D-pad button
- Press the Back, Home, or Menu buttons
- Open the notification shade
- Take a screenshot of the current window
For example, to simulate a Home button press, call the UiDevice.pressHome()
method.
UI Automator APIs
The UI Automator APIs allow you to write robust tests without needing to know about the implementation details of the app that you are targeting. You can use these APIs to capture and manipulate UI components across multiple apps:
-
UiCollection
: Enumerates a container's UI elements for the purpose of counting, or targeting sub-elements by their visible text or content-description property. -
UiObject
: Represents a UI element that is visible on the device. -
UiScrollable
: Provides support for searching for items in a scrollable UI container. -
UiSelector
: Represents a query for one or more target UI elements on a device. -
Configurator
: Allows you to set key parameters for running UI Automator tests.
For example, the following code shows how you can write a test script that brings up the default app launcher in the device:
// Initialize UiDevice instance mDevice =UiDevice.getInstance(getInstrumentation()); // Perform a short press on the HOME button mDevice().pressHome(); // Bring up the default launcher by searching for // a UI component that matches the content-description for the launcher button UiObject allAppsButton = mDevice .findObject(newUiSelector().description("Apps")); // Perform a click on the button to bring up the launcher allAppsButton.clickAndWaitForNewWindow();
To learn more about using UI Automator, see the API reference and Testing UI for Multiple Apps training.
相关推荐
uiautomator API 包含uiautomator api 5大类 方便使用uiautomator自动化测试的同学们参考与使用
用UiAutomator javadoc 生成的chm文件, 方便查看
主要分析 Android uiautomator常用的api,并结合实例和具体介绍
它仅通过通过adb连接的Android设备即可在Android 4.1+(API级别16〜30)上运行,而无需在Android设备上安装任何内容。 from uiautomator import device as d d . screen . on () d ( text = "Clock" ). click () ...
uiautomator源码从android sdk api 16开始,Android SDK开始支持两个做功能UI测试的新工具。 uiautomatorviewer,一个用以扫描以及分析Android应用程序的UI部件的工具。 以及uiautomator ,一个提供API用以自定义UI...
UiAutomator1.0和2.0_Android_API表与一些实例 内容: 1.一份包含1.0和2.0的xls表格式的api 2.一些关键类库的实例代码 3.一份uiautomator2.0_android工程样式 4.google官网uiautomator2.0 离线网页版本api
Configurator类介绍与API解说.mp4
LabVIEW 学习札记,详细、高效的学习资料。
import uiautomator2 as u2 from Config.Config import Config from Api.Public.PyApiLog import PyApiLog import datetime import os import time from unittest import TestCase class Action: def __init__...
基于UiAutomator框架,自动模拟用户手势操作,类似于触摸精灵,按键精灵的app。
Uiautomator 有 API 来设置可编辑字段中的文本。 如果文本仅包含 ASCII 字符,但不能输入任何非 ASCII 字符(例如日语),则该 API 运行良好。 此限制阻止了非英语应用程序的开发人员使用 uiautomator 进行测试。 ...
uiautomator在android api21以下如何启动apk,进行自动化测试
UiAutomator要用到的全部内容API,还有结合实际的现实案例代码,帮助理解和使用,只要看这文档就能写出你要的东西,不用再费劲去百度了。
uiautomator 源代码 Android uiautomator 源代码 4.4.4_r1 Google Android Platform - KitKat, API level 19 (KTU84P) http://source.android.com Release date: 17 March 2014 License: Apache 2.0
可以供Robotium等实现跨进程的Uiautomator.jar,直接导入即可调用 API e.g: UiDevice uiDevice = UiDevice.getInstance(getInstrumentation());
针对入门学者,能够详细的了解具体的方法,在实操过程中能够直接选择使用。
Android自动化测试UIautomator-UiWatcher api 介绍
Android自动化测试UIautomator-UiScrollable api介绍
Android自动化测试UIautomator-UiSelector api介绍
Android自动化测试UIautomator-UiObject api介绍