对于应用中图案解锁的功能,使用appium可以很好的完成这个功能。
这里以锁屏时图案解锁为例:
图案设置为:
在该锁屏界面解锁:
获取图案中9个点的坐标时,可以使用sdk tools目录下的hierarchyviewer工具获取。
下面贴上图案解锁的代码:
package com.xuxu.autotest; import java.net.URL; import io.appium.java_client.AppiumDriver; import io.appium.java_client.TouchAction; import io.appium.java_client.android.AndroidDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.remote.DesiredCapabilities; public class UnlockTest { private AppiumDriver driver; public UnlockTest() { } @Before public void setUp() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName", "Android Emulator"); capabilities.setCapability("platformVersion", "4.4"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("appPackage", "com.android.settings"); capabilities.setCapability("appActivity", ".Settings"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); sleep(2000); } @After public void tearDown() throws Exception { driver.quit(); } @Test public void test() { driver.sendKeyEvent(26); // 按power键锁屏 sleep(3000); driver.sendKeyEvent(26); // 按power键点亮屏幕 driver.tap(1, 540, 960, 500); // 触摸屏幕中间,显示图案解锁框 sleep(2000); //图案解锁 TouchAction action = new TouchAction(driver); action.press(215, 870).moveTo(540, 870).moveTo(862, 870) .moveTo(540, 1195).moveTo(215, 1195).moveTo(215, 1518) .moveTo(540, 1518).moveTo(862, 1518).moveTo(862, 1195) .release().perform(); } private void sleep(int i) { try { Thread.sleep(i); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
原文地址:http://blog.csdn.net/gb112211/article/details/42461517