Android無線測試之—UiAutomator UiScrollable API介紹七

來源:互聯網
上載者:User

標籤:

滑動到某個對象

一、滑動到某個對象相關API

傳回值 API 描述
boolean scrollIntoView(UiSelector selector) 滑動到條件元素所在位置,並且盡量讓其居於螢幕中央
boolean scrollIntoView(UiObject obj) 滑動到對象所在位置,並且盡量讓其居於螢幕中央
boolean scrollTextIntoView(String text) 滑動到文字物件所在位置,並且盡量讓其居於螢幕中央
boolean scrollDescriptionIntoView(String text) 滑動到文本描述對象所在位置,並且盡量讓其居於螢幕中央
boolean scrollToBeginning(int maxSwipes) 自訂掃動次數,滑動到開始位置
boolean scrollToBeginning(int maxSwipes, int steps) 自訂掃動次數與步長,滑動到開始位置
boolean scrollToEnd(int maxSwipes) 自訂掃動次數,滑動到結束位置
boolean scrollToEnd(int maxSwipes, int steps) 自訂掃動次數與步長,滑動到結束位置

 

 

 

 

 

 

 

 

說明:所有函數都是先在當前介面尋找是否有要找的對象,沒找到則先向上滑動指定的掃動次數,然後再向下滑動的同時尋找有沒有這個對象,但也僅向下滑動指定的掃動次數,找不到則會報錯。 

二、相關API應用舉例

package com.testuiselector;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.core.UiObject;import com.android.uiautomator.core.UiObjectNotFoundException;import com.android.uiautomator.core.UiScrollable;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="demo2";        testClass="com.testuiselector.Demo";        testName="testScrollIntoView";        androidId="1";        new UiAutomatorHelper(jarName, testClass, testName, androidId);    }        public void testScrollIntoView() throws UiObjectNotFoundException{        UiDevice.getInstance().pressHome();        sleep(1000);                UiObject people=new UiObject(new UiSelector().text("People"));        people.click();        sleep(2000);                UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));                scroll.scrollToBeginning(50);        sleep(3000);                UiSelector testview=new UiSelector().text("test");        scroll.scrollIntoView(testview);        sleep(3000);                scroll.scrollToBeginning(50, 5);        sleep(3000);                UiObject test=new UiObject(testview);        scroll.scrollIntoView(test);        sleep(3000);                scroll.scrollToEnd(50);        sleep(3000);                scroll.scrollTextIntoView("test");        sleep(3000);                scroll.scrollToEnd(50,5);        sleep(3000);                scroll.scrollDescriptionIntoView("Quick contact for test");            }    }
Demo.java

 

Android無線測試之—UiAutomator UiScrollable 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.