这写的是QQ手势解锁的自动化用例,
之前遇到了一点问题,卡了好久,move_to后边接的是绝对坐标,不是相对坐标
# coding:utf-8
from appium.webdriver.common.touch_action import TouchAction
from time import sleep
import os, time, unittest,sys
from appium import webdriver
desired_caps = {
'platformName': 'Android', # 设备系统
'deviceName': '28f5751a', # 设备名称
'platformVersion': '7.1.1', # 设备系统版本
'noReset': 'True',
'unicodeKeyboard': 'True', # 能输入中文字符
'resetKeyboard': 'True', # 能输入中文字符
'appPackage': 'com.tencent.mobileqq', # apk包名
'appActivity': 'com.tencent.mobileqq.activity.SplashActivity', # apk的launcherActivity
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # 启动app
time.sleep(5)
#这里是用QQ手势锁屏为例写的解锁方法
#获取九宫格的坐标位置
jiu = 'resourceId("com.tencent.mobileqq:id/name").index(6)'
loc = driver.find_element_by_android_uiautomator(jiu).location
print("获取九宫格坐标位置:%s"%loc)
#获取九宫格的宽和高
s = driver.find_element_by_android_uiautomator(jiu).size
print("获取九宫格宽和高:%s"%s)
# 获取九个点的坐标
gongge1 = (loc["x"]+s["width"]/6, loc["y"]+s["height"]/6)
gongge2 = (loc["x"]+s["width"]/2, loc["y"]+s["height"]/6)
gongge3 = (loc["x"]+s["width"]/6*5, loc["y"]+s["height"]/6)
gongge4 = (loc["x"]+s["width"]/6, loc["y"]+s["height"]/2)
gongge5 = (loc["x"]+s["width"]/2, loc["y"]+s["height"]/2)
gongge6 = (loc["x"]+s["width"]/6*5, loc["y"]+s["height"]/2)
gongge7 = (loc["x"]+s["width"]/6, loc["y"]+s["height"]/6*5)
gongge8 = (loc["x"]+s["width"]/2, loc["y"]+s["height"]/6*5)
gongge9 = (loc["x"]+s["width"]/6*5, loc["y"]+s["height"]/6*5)
print(gongge1,gongge2,gongge3,gongge6,gongge9)
sleep(3)
# 执行解锁,这里的解锁图案是1-2-3-6-9,一个7的图案
TouchAction(driver).press(x=gongge1[0],y=gongge1[1]).wait(300).move_to(x=gongge2[0],y=gongge2[1]).wait(1000).\
move_to(x=830,y=877).wait(1000).move_to(x=830,y=1167).wait(1000).move_to(x=830,y=1457).wait(1000).release().perform()