转自:http://blog.csdn.net/codekxx/article/details/50577381
手势密码在很多手机应用都会运到,手势密码都要求至少连接4个点,但AppiumLibrary并没有提供对应的关键字,本人尝试连续使用Swipe关键字两次解决该问题,为什么要用两次呢?因为Swipe的参数只是起点和终点,如果直接给出手势密码的起点和终点,则会忽略中间的点。
手机QQ手势密码如下:
AppiumLibrary它是开源的,就直接去修改其源代码。
于是,去到AppiumLibrary安装的文件夹,默认安装路径为:C:\Python27\Lib\site-packages\AppiumLibrary\keywords),再到keywords目录中找到_touch.py文件,就是它了。
给这个文件的类_TouchKeywords加上一个方法nine_palace_unlock,具体代码如下:
def nine_palace_unlock(self, locator): """nine palace""" driver = self._current_application() action = TouchAction(driver) lock_pattern = driver.find_element_by_xpath(locator) x = lock_pattern.location.get(‘x‘) y = lock_pattern.location.get(‘y‘) width = lock_pattern.size.get(‘width‘) height = lock_pattern.size.get(‘height‘) offset = width / 6 p11 = int(x + width / 6), int(y + height / 6) p12 = int(x + width / 2), int(y + height / 6) p13 = int(x + width - offset), int(y + height / 6) p21 = int(x + width / 6), int(y + height / 2) p22 = int(x + width / 2), int(y + height / 2) p23 = int(x + width - offset), int(y + height / 2) p31 = int(x + width / 6), int(y + height - offset) p32 = int(x + width / 2), int(y + height - offset) p33 = int(x + width - offset), int(y + height - offset) print(p11,p12,p13) print(p21,p22,p23) print(p31,p32,p33) p2 = p12[0] - p11[0] print(p2) sleep(3) action.press(x=p11[0],y=p11[1]).move_to(x=p2,y=0).wait(1000).move_to(x=p2,y=0).wait(1000). move_to(x=-p2,y=p2).wait(1000).move_to(x=-p2,y=p2).wait(1000).release().wait(1000).perform()
代码如下:
代码如下:
*** Settings *** Suite Setup Suite Teardown Library AppiumLibrary *** Variables *** *** Test Cases *** 手机QQ Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=19 deviceName=127.0.0.1:21503 app=${CURDIR}${/}QQ_794.apk appPackage=com.tencent.mobileqq ... appActivity=com.tencent.mobileqq.activity.SplashActivity unicodeKeyboard=True resetKeyboard=True Wait Until Page Contains Element xpath=//android.widget.LinearLayout[@resource-id=\"com.tencent.mobileqq:id/name\"]/android.view.View[5] #等待手机QQ打开完成 Nine Palace Unlock //android.widget.LinearLayout[@resource-id=\"com.tencent.mobileqq:id/name\"]/android.view.View[5] [Teardown] Close All Applications *** Keywords ***
原文地址:https://www.cnblogs.com/yrxns/p/8478123.html
时间: 2024-10-11 22:01:19