超详细干货:Appium+Pytest实现App并发测试

本文详细介绍了如何使用Appium结合Pytest进行App自动化测试的并发执行。通过目录结构展示了各文件源码,包括base_page.py、check_port.py等。文中提到启动时需注意模拟器或真机的端口设置,并强调需手动使用adb连接设备。最后展示了初步实现的效果,并指出项目可进一步完善的方向。
摘要由CSDN通过智能技术生成

一. 前言

Appium结合Pytest开展App自动化测试时,你知道如何实现用例并发执行吗?费话不多说,直接上代码, 毕竟想让每个人都能看明白也不容易,所以先放代码,有兴趣的先自行研究。

二、.目录结构

 

三、文件源码

3.1 base/base_page.py

"""
------------------------------------
@File : base_page.py
------------------------------------
"""
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()))
  
    @staticmethod
    def get_element_size_location(element):
        width = element.rect["width"]
        height = element.rect["height"]
        start_x = element.rect[
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值