python airtest 多线程入门(一)极速版刷视频

 1 from airtest.core.api import *
 2 from poco.drivers.android.uiautomation import AndroidUiautomationPoco
 3 from airtest.core.android.adb import ADB
 4 from airtest.core.android import Android
 5 import random
 6 import threading
 7 
 8 
 9 def run(id):
10     device = Android(id)
11     poco = AndroidUiautomationPoco(device)
12     time.sleep(5)
13     # 关闭程序
14     device.stop_app("com.ss.android.ugc.aweme.lite")
15     time.sleep(5)
16     # 开启程序
17     device.start_app("com.ss.android.ugc.aweme.lite")
18     time.sleep(10)
19     i = 0
20     while i < 200000:
21         try:
22             # 滑屏
23             poco.swipe([0.5, 0.8], [0.5, 0.2])
24             t = random.randint(5, 10)
25             time.sleep(t)
26         finally:
27             i = i + 1
28 
29 
30 adbs = ADB()
31 adb_list = [d[0] for d in adbs.devices(state="device")]
32 all_task = []
33 for i in adb_list:
34     t = threading.Thread(target=run, args=(i,))
35     t.setDaemon(True)
36     t.start()
37     all_task.append(t)
38 
40 for t in all_task:
41     t.join()  
42     print("in main: get page success")

没有判断关闭或领取弹出来的红包金币,需要自己写

posted @ 2021-12-08 15:51  野猫炫  阅读(905)  评论(0编辑  收藏  举报