zoukankan      html  css  js  c++  java
  • Air test 基于屏幕比例实现滑动的方法

    # -*- encoding=utf8 -*-
    __author__ = "chenshanju"
    __docs__ = "基于iOS类实现滑动"
    from airtest.core.api import *
    from airtest.core.ios import IOS
    auto_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启动用例失败")
    
  • 相关阅读:
    如何调试 VB 6 的安装源程序 Setup1.VBP?
    Linq和泛型,IEnumerable和IQueryable之间的区别,Lambda表达式,Linq to Sql停止开发转为 Entity Framework
    SQL Server中行列转换 Pivot UnPivot
    一个题目涉及到的50个Sql语句
    Entity Framework中IQueryable, IEnumerable, IList的差别
    [转]git使用指南系列
    一条SQL语句查询出成绩名次 排名 (转)
    MS SQL Server:排名函数详解
    MSSQL中删除所有外键约束的方法
    Model View Presenter Part I – Building it from Scratch
  • 原文地址:https://www.cnblogs.com/csj2018/p/9853232.html
Copyright © 2011-2022 走看看