RobotFramework:App九宮格滑動解鎖

來源:互聯網
上載者:User

標籤: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九宮格滑動解鎖

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.