Android无线测试之—UiAutomator UiDevice API介绍六

一、灭屏和唤醒屏幕相关知识:

1)灭屏:按电源键将屏幕熄灭

2)唤醒屏幕:在灭屏状态下按电源键唤醒屏幕

二、灭屏与唤屏相关的API:

返回值 方法名 描述
void wakeUp() 模拟按电源键,如果屏幕是唤醒的没有任何作用
void sleep() 模拟按电源键,如果屏幕是关闭的则没有任何作用
boolean isScreenOn() 检查屏幕是否亮屏

 

 

 

 

 

三、API应用举例:

package com.uiautomatortest;

import android.graphics.Point;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.KeyEvent;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class Test extends UiAutomatorTestCase {
    
    public void testSleepAndWakeUp() throws RemoteException{
        
        if(UiDevice.getInstance().isScreenOn()==true){
            
            UiDevice.getInstance().sleep();
            sleep(2000);
            UiDevice.getInstance().wakeUp();
            sleep(2000);
            //(159,515) (320,515)
            int startX, startY, endX, endY, steps;
            startX=159;
            startY=515;
            endX=320;
            endY=515;
            steps=100;
            UiDevice.getInstance().drag(startX, startY, endX, endY, steps);
        }
    }

}
Test.java

 

posted on 2015-06-03 21:12  发卡  阅读(629)  评论(0编辑  收藏  举报