1. 程式人生 > >使用UiAutomator中swipe(Point[], int)方法繪製解鎖圖案

使用UiAutomator中swipe(Point[], int)方法繪製解鎖圖案

swipe(Point[] segments, int segmentSteps)

實現的方法,從point陣列中的第一個點滑動到第二個點,第二個點滑動到第三個點,依次滑動,形成一條條折線,每條直線所有步伐segmentSteps

例如:
這裡寫圖片描述

package com.vv7;

import junit.framework.Assert;

import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

import android.graphics.Point;
import android.os.RemoteException;

public class UnlockCase extends UiAutomatorTestCase {

    public void testUnlockCase() throws RemoteException,
            UiObjectNotFoundException {
        if (getUiDevice().isScreenOn()) {
            getUiDevice().sleep();
        }
        getUiDevice().wakeUp();// 喚醒螢幕
        // 向上滑動,調出圖案解鎖面板
        getUiDevice().swipe(540, 1576, 540, 676, 10);
        sleep(3000);
        //繪製解鎖圖案
        Point p1 = new Point();
        Point p2 = new Point();
        Point p3 = new Point();
        Point p4 = new Point();
        Point p5 = new Point();
        p1.x = 215;p1.y = 872;
        p2.x = 545;p2.y = 872;
        p3.x = 545;p3.y = 1202;
        p4.x = 545;p4.y = 1532;
        p5.x = 875;p5.y = 1532;
        Point[] p = { p1, p2, p3, p4, p5 };
        getUiDevice().swipe(p, 40);
        sleep(3000);
        getUiDevice().pressHome();
        UiObject extDateWidget = new UiObject(
                new UiSelector()
                        .resourceId("com.android.deskclock:id/imageview"));
        Assert.assertEquals("日期", extDateWidget.getContentDescription());

    }

}