Android無線測試之—UiAutomator UiObject API介紹六

來源:互聯網
上載者:User

標籤:

手勢操作

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

 

Android無線測試之—UiAutomator UiObject API介紹六

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.