如何用Appium+Pytest实现app并发测试 ?

本文介绍了如何利用Appium和Pytest进行APP并发测试,分享了代码结构、启动说明及效果展示,强调在真机测试时需要修改部分代码,并提醒读者需手动连接手机或自行编写自动连接代码。项目目录结构、测试报告生成和日志记录也进行了简单说明。
摘要由CSDN通过智能技术生成

前言

今天呢想和大家来聊聊Appium+Pytest实现app并发测试,这个功能已经写完很长时间了,一直没有发出来,今天先把代码发出来吧,有一些代码是参考网上写的,具体的代码说明今天暂时先不发了,代码解释的太详细还得我花点时间^_^, 毕竟想让每个人都能看明白也不容易,所以先放代码,有兴趣的先研究吧,废话就不多说了,咱们直接进入正题哟。

一、目录结构

二、文件源码

    """
  import time
  from appium.webdriver import WebElement
  from appium.webdriver.webdriver import WebDriver
  from appium.webdriver.common.touch_action import TouchAction
  from selenium.webdriver.support.wait import WebDriverWait
  from selenium.common.exceptions import NoSuchElementException, TimeoutException
  
  
  class Base(object):
  
      def __init__(self, driver: WebDriver):
          self.driver = driver
  
      @property
      def get_phone_size(self):
          """获取屏幕的大小"""
          width = self.driver.get_window_size()['width']
          height = self.driver.get_window_size()['height']
          return width, height
  
      def swipe_left(self, duration=300):
          """左滑"""
          width, height = self.get_phone_size
          start = width * 0.9, height * 0.5
          end = width * 0.1, height * 0.5
          return self.driver.swipe(*start, *end, duration)
  
      def swipe_right(self, duration=300):
          """右滑"""
          width, height = self.get_phone_size
          start = width * 0.1, height * 0.5
          end = width * 0.9, height * 0.5
          return self.driver.swipe(*start, *end, duration)
  
      def swipe_up(self, duration):
          """上滑"""
          width, height = self.get_phone_size
          start = width * 0.5, height * 0.9
          end = width * 0.5, height * 0.1
          return self.driver.swipe(*start, *end, duration)
  
      def swipe_down(self, duration):
          """下滑"""
          width, height = self.get_phone_size
          start = width * 0.5, height * 0.1
          end = width * 0.5, height * 0.9
          return self.driver.swipe(*start, *end, duration)
  
      def skip_welcome_page(self, direction, num=3):
          """
          滑动页面跳过引导动画
         :param direction:  str 滑动方向,left, right, up, down
          :param num: 滑动次数
          :return:
          """
          direction_dic = {
              "left": "swipe_left",
              "right": "swipe_right",
              "up": "swipe_up",
              "down": "swipe_down"
          }
          time.sleep(3)
          if hasattr(self, direction_dic[direction]):
              for _ in range(num):
                  getattr(self, direction_dic[direction])()  # 使用反射执行不同的滑动方法
          else:
              raise ValueError("参数{}不存在, direction可以为{}任意一个字符串".
                               format(direction, direction_dic.keys()))
  
      @static
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值