標籤:out 手勢 view framework self work on() version net
轉自: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 SetupSuite TeardownLibrary 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 ***
RobotFramework:App九宮格滑動解鎖