日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python图案绘制解锁_PythonAppium实现安卓手机图形解锁案例

發布時間:2023/12/29 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python图案绘制解锁_PythonAppium实现安卓手机图形解锁案例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先,在解鎖狀態下,建立一個Session,打開APP。然后,調用press_keycode()方法傳入整型數值"26",鎖定屏幕。通過implicitly_wait()方法等待兩秒后,再次調用press_keycode()方法按下電源鍵,點亮屏幕。這時候看到的手機界面如下所示:

此時,我們需要調用login_unlock()方法繪制圖案解鎖手機(預先設置好的解鎖圖形如上圖所示)。

login_unlock()方法的詳細介紹如下:

1、通過find_element_by_id()方法找到九宮格的View。

lock_pattern = self.driver.find_element_by_id("com.android.keyguard:id/lockPatternView")

2、通過lock_pattern變量獲取View的初始坐標值和寬度高度。

x = lock_pattern.location.get('x')y = lock_pattern.location.get('y')width = lock_pattern.size.get('width')height = lock_pattern.size.get('height')

3、通過寬度計算偏移量。

offset = width / 6

4、通過偏移量計算九宮格內九個點各自的x,y坐標值。

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)

5、計算從當前點移動到下一個點的偏移量。

p3 = p13[0] - p11[0]

6、執行移動操作。

TouchAction(self.driver).press(x=p11[0], y=p11[1]).move_to(x=p3, y=0).wait(1000).move_to(x=0, y=p3).wait(1000).release().perform()

完整代碼如下:

import unittestfrom appium import webdriverfrom appium.webdriver.common.touch_action import TouchActionfrom time import sleep# 圖形解鎖class unlockTest(unittest.TestCase):

def test_unlock(self):

desired_caps = {}

desired_caps['platformName'] = 'Android'

desired_caps['platformVersion'] = '4.4.4'

desired_caps['app'] = '/Users/a140/Downloads/test.apk'

desired_caps['deviceName'] = '03083025d0250909'

self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) ? ? ? ?# 按電源鍵,鎖屏

self.driver.press_keycode(26)

self.driver.implicitly_wait(2) ? ? ? ?# 按電源鍵,解鎖

self.driver.press_keycode(26) ? ? ? ?# 調用解鎖的方法

self.login_unlock() ? ?# 解鎖

def login_unlock(self):

# 通過ID找到九宮格的View

lock_pattern = self.driver.find_element_by_id("com.android.keyguard:id/lockPatternView") ? ? ? ?# 獲取View的x,y坐標值

x = lock_pattern.location.get('x')

y = lock_pattern.location.get('y') ? ? ? ?# 獲取View的寬度和高度

width = lock_pattern.size.get('width')

height = lock_pattern.size.get('height') ? ? ? ?# 偏移量

offset = width / 6

# 計算九宮格內九個點的x,y坐標值

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) ? ? ? ?# 計算移動到下一個點的偏移量

p3 = p13[0] - p11[0]

sleep(3) ? ? ? ?# 執行移動操作

TouchAction(self.driver).press(x=p11[0], y=p11[1]).move_to(x=p3, y=0).wait(1000).move_to(x=0, y=p3).wait( ? ? ? ? ? ?1000).release().perform()if __name__ == '__main__':

suite = unittest.TestLoader().loadTestsFromTestCase(unlockTest)

unittest.TextTestRunner(verbosity=2).run(suite)

總結

以上是生活随笔為你收集整理的python图案绘制解锁_PythonAppium实现安卓手机图形解锁案例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。