airtest环境搭建,将下面的图片和代码文件放在同一个目录下,
确保手机已开启usb调试,
将游戏调整到副本页面,
运行py文件,即可!
pic
#
#
#
#
code
from airtest.core.api import * import time import datetime import logging logging.basicConfig(level=None) init_device("Android") def gen(times,nstatus): duration=30 for i in range(0,times): print(i+1) print(duration,"*"*20) status=nstatus while(1): if(exists(Template(r"tpl1602912634311.png", record_pos=(0.331, 0.173), resolution=(1560, 720)))): touch(Template(r"tpl1602864978373.png", record_pos=(1.34, -0.201), resolution=(720, 1560))) status=False t1=time.time() time.sleep(duration) else: if(exists(Template(r"tpl1602912796157.png", record_pos=(0.005, 0.092), resolution=(1560, 720)))): t2=time.time() tmp=(datetime.datetime.fromtimestamp(t2)-datetime.datetime.fromtimestamp(t1)).seconds-6 if(duration==30): duration=tmp else: if(tmp>duration): pass else: duration=tmp status=True touch(Template(r"tpl1602912825170.png", record_pos=(0.001, 0.09), resolution=(1560, 720))) if(not status): #开始 time.sleep(3) else: #结束 time.sleep(3) break nstatus=False
#传入的数字代表刷副本的次数 gen(2,nstatus) time.sleep(5)
升级版2020-11-10
from airtest.core.api import * import time import datetime import logging logging.basicConfig(level=None) init_device("Android") #传入的数字代表刷副本的次数 times=17 duration=30 for i in range(0,times): print(i+1) print(duration,"*"*20) sleep(5) while(1): #点击挑战按钮 if(exists(Template(r"tpl1604980109297.png", record_pos=(0.331, 0.173), resolution=(1560, 720)))): touch(Template(r"tpl1604980109297.png", record_pos=(0.331, 0.173), resolution=(1560, 720))) t1=time.time() sleep(duration) #点击返回图片 if(exists(Template(r"tpl1604980219758.png", record_pos=(0.005, 0.092), resolution=(1560, 720)))): t2=time.time() tmp=(datetime.datetime.fromtimestamp(t2)-datetime.datetime.fromtimestamp(t1)).seconds-6 if(duration==30): duration=tmp else: if(tmp>duration): pass else: duration=tmp #确认已经返回到副本首页 while(1): if(exists(Template(r"tpl1604980109297.png", record_pos=(0.331, 0.173), resolution=(1560, 720)))): break else: if(exists(Template(r"tpl1604980219758.png", record_pos=(0.005, 0.092), resolution=(1560, 720)))): touch(Template(r"tpl1604980219758.png", record_pos=(0.005, 0.092), resolution=(1560, 720))) sleep(3) break sleep(3) sleep(5)