码迷,mamicode.com
首页 > 移动开发 > 详细

Android无线测试之—UiAutomator UiObject API介绍二

时间:2015-06-09 20:01:02      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

点击与长按

一、组件区域位置关系

  Rect 对象代表一个矩形区域 [Left,Top] [Right,Bottom]

技术分享

二、点击与长按API

返回值 API 描述
boolean click() 点击对象
boolean clickAndWaitForNewWindow(lang timeout) 点击对象,等待新窗口出现,参数为等待超长时间
boolean clickAndWaitForNewWindow() 点击对象,等待新窗口出现
boolean clickBottomRight() 点击对象的右下角
boolean clickTopLeft() 点击对象的左上角
boolean longClick() 长按对象,对对象执行长按操作
boolean longClickBottomRight() 长按对象右下角
boolean longClickTopLeft() 长按对象左上角

 

 

 

 

 

 

 

 

三、API应用举例

技术分享
package com.test.uiobject;

import com.android.uiautomator.core.UiDevice;
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.test.uiobject.Demo";
        testName="testLongClick";
        androidId="1";
        new UiAutomatorHelper(jarName,testClass,testName,androidId);

    }
    
    public void testClick() throws UiObjectNotFoundException{
        UiDevice.getInstance().pressHome();
        sleep(1000);
        
        //click()
        UiObject clock=new UiObject(new UiSelector().resourceId("com.android.deskclock:id/analog_appwidget"));
        clock.click();
        sleep(2000);
        
        UiDevice.getInstance().pressBack();
        sleep(2000);
        
        //clickAndWaitForNewWindow()
        clock.clickAndWaitForNewWindow();
        
        UiDevice.getInstance().pressBack();
        sleep(2000);
        
        //clickAndWaitForNewWindow(timeout)
        clock.clickAndWaitForNewWindow(5000);
        
        UiDevice.getInstance().pressBack();
        sleep(2000);
        
        //clickBottomRight()
        clock.clickBottomRight();
        sleep(2000);
        
        UiDevice.getInstance().pressBack();
        sleep(2000);
        
        //clickTopLeft()
        clock.clickTopLeft();
        sleep(2000);
        UiDevice.getInstance().pressBack();
        
    }
    
    public void testLongClick() throws UiObjectNotFoundException{
        UiDevice.getInstance().pressHome();
        sleep(2000);
        
        //longClick()
        UiObject people=new UiObject(new UiSelector().text("People"));
        people.longClick();
        sleep(2000);
        
        //longClickBottomRight()
        people.longClickBottomRight();
        sleep(2000);
        
        //longClickTopLeft()
        people.longClickTopLeft();
    }

}
Demo.java

 

Android无线测试之—UiAutomator UiObject API介绍二

标签:

原文地址:http://www.cnblogs.com/fsw-blog/p/4564187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!