安卓设备进行自动化的最简单代码

import os
import time
import sys

serial = “FILF75Y9TWY99DMJ”

set1 = f"adb -s {serial} shell am start -n com.android.settings/.Settings "#打开设置

set2=f"adb -s {serial} shell input tap 160 565" #点击我的设备
set3=f"adb -s {serial} shell input tap 820 534" #点击检测新版本
set4=f"adb -s {serial} shell input tap 615 417 " #点击立即重启
set51=f"adb -s {serial} shell input swipe 437 510 352 145 " #滑动
set52=f"adb -s {serial} shell input swipe 437 510 352 145 " #再滑动
set6=f"adb -s {serial} shell input tap 252 487 " #点击恢复出厂
set7=f"adb -s {serial} shell input tap 338 469" #点击确定
set8=f"adb -s {serial} shell input tap 513 531" #点击开始使用
set9=f"adb -s {serial} shell input keyevent KEYCODE_F1" #禁止收音
set10=f"adb -s {serial} shell input tap 928 55 " #跳过新手引导视频
set11 = f’adb -s {serial} shell dumpsys activity activities’ # 检查是否已经进入桌面

def getActivityTop():
script = os.popen(set11)
info = script.readlines()
for line in info:
if ‘mResumedActivity’ in line:
time.sleep(1)
else:
if ‘com.alibaba.ailabs.genie.smartapp/com.alibaba.ailabs.genie.launcher.activity.HomeActivity’ in line:
return True

def kongzhi():
print(“测试开始”)
a=1
b=1
c=1
while a<2000:

if c != 5:
    os.popen(set9)
else:
    c=1

    
time.sleep(7)
os.popen(set1)
time.sleep(7)
os.popen(set2)
time.sleep(2)
os.popen(set2)
time.sleep(7)
os.popen(set3)
time.sleep(7)
while True:
    g=f"adb -s {serial} shell ls"
    #e = subprocess.Popen(g, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, encoding="utf-8")
    e=os.popen(g)
    f=e.read()
    if 'sdcard' in f:
        os.popen(set4)
        time.sleep(3)
    else:
        break
while True:
    if  getActivityTop() != True:
        time.sleep(1)
    else:
        break
time.sleep(2)



print("这是第%s次测试"%a)
    

if b==5:
    os.popen(set9)
    time.sleep(10)
    os.popen(set1)
    time.sleep(10)
    os.popen(set2)
    time.sleep(10)
    os.popen(set51)
    time.sleep(5)
    os.popen(set52)
    time.sleep(10)
    os.popen(set6)
    time.sleep(10)
    os.popen(set7)
    time.sleep(65)
    os.popen(set9)
    time.sleep(20)


    os.popen(set10)
    time.sleep(1)
    os.popen(set10)
    time.sleep(1)
    os.popen(set10)
    time.sleep(5)
    os.popen(set8)
    time.sleep(10)
    b=0
    c=4
b=b+1
a=a+1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
if name == ‘main’:
kongzhi()

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值