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

    手势操作

    1、手势相关操作

    2、相关API介绍

    返回值 API 描述
    boolean performMultiPointerGesture(PointerCoords[]... touches) 执行单手触控手势,可定义任意手势与形状
    boolean performTwoPointerGesture(Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps) 执行任意两个手指触控手势,模拟两个手指手势
    boolean pinchIn(int percent, int steps) 手势操作,两点向内收缩
    boolean pinchOut(int percent, int steps) 手势操作,两点向外扩张

     3、API应用举例

    package com.test.uiobject;
    
    import java.io.File;
    
    import android.graphics.Rect;
    import android.view.KeyEvent;
    
    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="testGesTure";
            androidId="1";
            new UiAutomatorHelper(jarName,testClass,testName,androidId);
    
        }
        
        public void testGesTure() throws UiObjectNotFoundException{
            //返回home页
            UiDevice.getInstance().pressHome();
            sleep(2000);    
            
            //打开浏览器
            UiObject browser=new UiObject(new UiSelector().text("Browser"));
            browser.click();
            sleep(2000);
            
            //将光标移动到URL输入框行尾,点击backspace键删除里面的URL
            UiObject editText=new UiObject(new UiSelector().className("android.widget.EditText"));
            editText.click();
            sleep(1000);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_MOVE_END);
            UiObject url=new UiObject(new UiSelector().text("Search or type URL"));
            while(!url.exists()){
                UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_DEL);
            }
            sleep(2000);
            
            //输入www.baidu.com 点击enter打开百度首页
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_W);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_W);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_W);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_PERIOD);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_B);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_A);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_I);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_D);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_U);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_PERIOD);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_C);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_O);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_M);
            sleep(500);
            UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_ENTER);
            sleep(10000);
            
            //截屏,保存
            UiDevice.getInstance().takeScreenshot(new File("sdcard/image1.png"));
            sleep(2000);
            
            //进入图片所在的位置
            UiDevice.getInstance().pressHome();
            sleep(2000);
            UiObject apps=new UiObject(new UiSelector().descriptionContains("Apps"));
            apps.clickAndWaitForNewWindow();
            UiObject fileManager=new UiObject(new UiSelector().text("File Manager"));
            fileManager.clickAndWaitForNewWindow();
            UiObject listView=new UiObject(new UiSelector().text("image1.png"));
            listView.clickAndWaitForNewWindow();
            
            //放大缩小图片
            UiObject image=new UiObject(new UiSelector().resourceId("com.android.gallery:id/image"));
            image.pinchIn(80, 50);
            image.pinchOut(80, 50);    
        }
    
    }
    Demo.java
  • 相关阅读:
    一百三十二:CMS系统之前端动态获取后台添加的轮播图
    一百三十一:CMS系统之轮播图上传图片功能
    一百三十:CMS系统之七牛js和python的SDK使用示例
    Python中文件编码的检测
    三目运算符
    三级菜单
    购物车程序
    计算机进制转换
    Python字典练习题
    VS Code常用快捷键总结
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4577170.html
Copyright © 2011-2022 走看看