airtest封装的滑动

# -*- coding: utf-8 -*-
from airtest.core.api import *
from airtest.core.android import android
# from airtest.report.report import simple_report
# from airtest.report.report import LogToHtml
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
# from airtest.core.helper import G
from airtest.core.android.adb import ADB
import logging
from random import randint,uniform,choice
# from airtest.core.settings import Settings as ST
ST.CVSTRATEGY = ["tpl"]
logger=logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
auto_setup(__file__)
class Case(object):
    def __init__(self):

        size = poco.get_screen_size()
        self.width = size[0]
        self.height = size[1]
        self.start_pos = (0.2 * self.width, 0.5 * self.height)  #
        self.end_pos = (0.8 * self.width, 0.5 * self.height)
        self.huadong=(self.start_pos,self.end_pos)
        print("获取到设备分辨率大小:",size)
    def test1(self):
        #for i in range(100):
        # youhua=[self.start_pos,self.end_pos]
        # zuohua=[self.end_pos,self.start_pos]
        #huadong_list=[youhua,zuohua]
        for i in range(self.num):
            zuohua=swipe(self.start_pos, self.end_pos, duration=0.01)   #右滑
            youhua=swipe(self.end_pos, self.start_pos, duration=0.01)   #左滑
            s=(zuohua,youhua)
            choice(s)

    def test2(self):

        # for i in range(self.num):
        #     print(i)
        #     swipe(self.start_pos, self.end_pos, duration=0.01)
        # for i in range(self.num):
        #     swipe(self.end_pos, self.start_pos, duration=0.01)
        for i in range(self.num):
            swipe([self.width * 0.5, self.height * 0.8], [self.width * 0.8, self.height * 0.2])  # 下滑
            swipe([self.width * 0.8, self.height * 0.2], [self.width * 0.5, self.height * 0.8])  # 上滑

    def show_menu(self):
        ADB(G.DEVICE_LIST[0].serialno).wait_for_device(10)
        while True:
            try:
                ori,num=input("输入滑动的方向(1为左右2为上下)和次数 ,逗号隔开: ").split(",")
                self.ori=int(ori)
                self.num=int(num)
                #print(self.ori,type(self.ori),self.num,type(self.num))
                if self.ori==1:
                    self.test1()
                elif self.ori==2:
                    self.test2()
            except:
                print("检查是否输入正确,确保逗号为英文符号")
                continue
test=Case()
test.show_menu()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值