您的位置:首页 > 产品设计 > UI/UE

Uiautomator API简介-摘要

2016-01-12 10:02 561 查看

本文适合初学者

uiautomator API在 uiautomator.jar 文件中

1.UiDevice

UiDevice代表设备状态。在测试中,可以通过UiDevice实例主要进行以下两个方面的操作:

1.检测设备的各种属性

e.g.:例如当前的屏幕方向以及屏幕尺寸

a)getUiDevice().getDisplayRotation()

b)getUiDevice().getDisplayHeight()

2.通过UiDevice实例来执行设备级别的操作

e.g.:例如 把设备设置为横屏或者竖屏、按下Home按键

a)getUiDevice().pressHome()

b)getUiDevice().pressMenu()

c)getUiDevice().pressBack()

2.UiSelector

UiSelector代表一种搜索条件,可以在当前界面上查询和获取特定元素的句柄,当找到多余一个的匹配元素,则返回布局层次结构上第一个匹配元素作为目标UiObject,当构造一个UiSelector对象时,可以使用链式调用多个属性来缩小查询范围

例如:

“`

package com.uiselectortest;

import com.android.uiautomator.core.UiObject;

import com.android.uiautomator.core.UiObjectNotFoundException;

import com.android.uiautomator.core.UiSelector;

import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class Demo extends UiAutomatorTestCase {

/**

* @param args

*/

public static void main(String[] args) {

String jarName, testClass, testName, androidId;
jarName="demo";
testClass="com.testuiselector.Demo";
testName="testDemo";
androidId="1";
new UiAutomatorHelper(jarName, testClass, testName, androidId);

}

public void testDemo() throws UiObjectNotFoundException{

UiSelector l=new UiSelector().text("People");
UiObject p=new UiObject(l);
p.click();

}


}


“`

各个属性详细介绍

点我哈

常见Android组件属性



未完-待续

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: