以前就做过Python做了点Ai和Sprider有点基础就学了学Airtest这个插件,没大规模应该自己玩一玩电音还可以,不用像AutoJs那样找不到了,我这个代码也算是我记录一下也算是给大家抛砖引玉。Airtest的核心是Python,Python就是个脚本语言和Js基本语法一样,所以老铁们学习基本没难度。不废话放代码
# -*- encoding=utf8 -*-
__author__ = "zhangyu"
from airtest.core.api import *
from airtest.core.android.android import Android
from poco.drivers.unity3d import UnityPoco
import random
keyevent("home")
auto_setup(__file__)
devs = device()
#print(devs.list_app(third_only=True))
poco = UnityPoco()
#start_app('com.zk.xiaogua.fzsg.smsg121lhbb',activity=None)
r = random.randint(6,8)
if(r>15):
print(r)
else:
print("No 9")
# sleep(4.0)
touch(Template(r"tpl1603867428962.png", record_pos=(-0.35, 0.768), resolution=(1080, 1920)))
sleep(r)
if(exists(Template(r"tpl1603867523632.png", record_pos=(0.36, -0.454), resolution=(1080, 1920)))):
touch(Template(r"tpl1603867563171.png", record_pos=(-0.399, 0.795), resolution=(1080, 1920)))
# 获取设备的高度和宽度
width, height = device().get_current_resolution()
# 校准滑动的起点和终点
start_pt = (width * 0.7, height *0.8)
end_pt = (width * 0.7, height *0.2)
# 滑动5次:
for i in range(35):
swipe(start_pt, end_pt,duration=1,fingers=2)
sleep(random.randint(3,5)) # 等待设备的响应
touch(Template(r"tpl1603873484823.png", record_pos=(-0.435, -0.766), resolution=(1080, 1920)))
sleep(random.randint(500,600))
for x in range(5):
swipe(start_pt, end_pt,duration=1,fingers=2)
sleep(random.randint(500,600))
keyevent("home")
纯脚本无UI。