# -*- encoding=utf8 -*-__author__ = "chenshanju"__docs__ = "基于iOS类实现滑动"from airtest.core.api import *from airtest.core.ios import IOSauto_setup(__file__)class Base(): def __init__(self): test1=IOS() self.width=test1.display_info['physical_width'] self.height=test1.display_info['physical_height'] self.left_point=(0.2*self.width,0.75*self.height) self.right_point=(0.8*self.width,0.75*self.height) self.up_point=(0.5*self.width,0.25*self.height) self.down_point=(0.5*self.width,0.75*self.height) self.back_point1=(0*self.width,0.5*self.height) self.back_point2=(0.5*self.width,0.5*self.height) def swipe_to_back(self): swipe(self.back_point1,self.back_point2) def swipe_to_left(self): swipe(self.right_point,self.left_point) sleep(2) def swipe_to_right(self): swipe(self.left_point,self.right_point) sleep(2) def swipe_to_up(self): swipe(self.down_point,self.up_point) sleep(2) def swipe_to_down(self): swipe(self.up_point,self.down_point) sleep(2) def exist_touch(self,p1,p2=0): if p2==0: p2=p1 if exists(p1): touch(p2) sleep(1) def new_touch(self,p,t=1): count=1 while not exists(p): sleep(5) count=count+1 if count>5: break touch(p) sleep(t) def back_key(self): count=0 back_list=[Template(file:///Users/chenshanju/Desktop/autoCase/feizhu/Base.air/tpl1536744539863.png, threshold=0.8, target_pos=5, rgb=False, record_pos=(-0.445, -0.901), resolution=(1125, 2436)),Template(file:///Users/chenshanju/Desktop/autoCase/feizhu/Base.air/tpl1536745663572.png, threshold=0.8, target_pos=5, rgb=False, record_pos=(0.4, -0.901), resolution=(1125, 2436)),Template(file:///Users/chenshanju/Desktop/autoCase/feizhu/Base.air/tpl1540368782186.png, threshold=0.8, target_pos=5, rgb=False, record_pos=(-0.433, -0.9), resolution=(1125, 2436)),Template(file:///Users/chenshanju/Desktop/autoCase/feizhu/Base.air/tpl1540372744293.png, record_pos=(-0.435, -0.902), resolution=(1125, 2436)),Template(file:///Users/chenshanju/Desktop/autoCase/feizhu/Base.air/tpl1536744539863.png, threshold=0.8, target_pos=5, rgb=False, record_pos=(-0.445, -0.901), resolution=(1125, 2436))] for back in back_list: count=count+1 if exists(back): self.new_touch(back) break if count >= len(back_list): self.swipe_to_back() def into_app(self): start_app("com.taobao.travel") sleep(5) self.exist_touch(Template(file:///Users/chenshanju/Desktop/autoCase/feizhu/Base.air/tpl1536743118383.png, record_pos=(0.001, 0.004), resolution=(1125, 2436)),Template(file:///Users/chenshanju/Desktop/autoCase/feizhu/Base.air/tpl1536743125640.png, record_pos=(0.181, 0.156), resolution=(1125, 2436))) def restart_app(self,p): if exists(p): self.new_touch(p) else: self.into_app() sleep(5) self.new_touch(p)# try:# base = Base()# base.into_app()# except:# print(" regression base启动用例失败")