zoukankan      html  css  js  c++  java
  • Android无线测试之—UiAutomator UiDevice API介绍五

    屏幕旋转

    一、屏幕旋转相关知识:

    1)旋转方向:0度,90度(向左转),180度,270度(向右转)

    2)重力感应器:重力感应器是旋转所依靠的

    3)固定位置:指将屏幕方向固定在0度,90度或者180度等

    4)物理旋转:物理旋转与重力感应器关联在一块,关闭物理旋转就是关闭了重力感应器,反之亦然)

    二、旋转屏幕相关API:

    返回值 方法名 描述
    void setOrientationLeft() 通过禁用传感器,然后模拟设备向左转,并且固定位置
    void setOrientationNatural() 通过禁用传感器,然后模拟设备转到其自然默认的方向,并且固定位置
    void setOrientationRight() 通过禁用传感器,然后模拟设备向右转,并且固定位置
    void unfreezeRotation() 重新启动传感器和允许物理旋转
    boolean isNaturalOrientation() 检测设备是否处于默认旋转状态
    int getDisplayRotation()

    返回当前的显示旋转,0度,90度,180度,270度值分别为:0、1、2、3

    void freezeRotation() 禁用传感器和冻结装置物理旋转在其当前旋转状态

    三、API应用举例:

    package com.UiAutomator;
    
    import java.io.File;
    
    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 Test1 extends UiAutomatorTestCase {
        
        public void testOrientation() throws RemoteException{
            
            int r=UiDevice.getInstance().getDisplayRotation();
            if(r==0){
                System.out.println("r="+r);
                UiDevice.getInstance().setOrientationLeft();
            }
            if(r==1){
                UiDevice.getInstance().setOrientationNatural();
                sleep(1000);
                UiDevice.getInstance().setOrientationLeft();
            }
            if(r==2){
                UiDevice.getInstance().setOrientationNatural();
                sleep(1000);
                UiDevice.getInstance().setOrientationLeft();
            }
            if(r==3){
                UiDevice.getInstance().setOrientationNatural();
            }
            
        }
    
    }
    Test.java
  • 相关阅读:
    解决docx4j 变量替换 由于变量存在样式式或空白字符 导致替换失败问题
    redis批量删除key 远程批量删除key
    idea 集成sonarLint检查代码bugs
    mac jmeter 的使用
    tomcat配置管理员-走后门
    终端mysql Operation not permitted错误解决方案
    update使用inner join
    hibernate 三种状态的转换
    数据库中间表插入乱序
    解决https证书验证不通过的问题
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4546302.html
Copyright © 2011-2022 走看看