当前位置: 首页 > news >正文

微信小程序自动化测试pytest版工具使用方法


-mini

https://github.com/zx490336534/pytest-mini

微信小程序自动化测试pytest插件/工具

基于MiniTest进行pytest改造

使用方法

准备测试小程序

根据miniprogram-demo项目介绍运行一次项目

成功运行后关闭

安装&更新

pip install pytest-mini --upgrade

引入插件

新建conftest.py文件

from pytest_mini import pluginspytest_plugins = plugins("待测试的小程序项目路径","微信开发者工具路径"
)

例如demo/cases/conftest.py

from pytest_mini import pluginspytest_plugins = plugins("/Users/zhongxin/github/miniprogram-demo",  # 待测试的小程序项目路径"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"  # 微信开发者工具路径
)

编写页面对象

在demo/pages/components_page.py编写元素定位

from pytest_mini import Mini, Locatorclass ComponentsPage(Mini):view_container = Locator('view', inner_text='视图容器', desc='组件页-视图容器')

在conftest.py中添加

import pytest
from pages.components_page import ComponentsPage@pytest.fixture(scope="session")
def components_page(mini):yield ComponentsPage(driver=mini.driver)

编写测试代码

demo/cases/test_home.py

import allurefrom pytest_mini import compose@compose(feature="小程序官方组件展示", story="组件", title='容器视图操作')
def test_view_container(components_page):with allure.step("点击容器视图"):components_page.click(components_page.view_container)assert False, "故意失败,查看报告截图"

编写执行&报告展示脚本

demo/cases/allure_debug.py

import os
import pytest
from pytest_mini.constant import Constanttest_cases = ["test_home.py"]  # 执行的脚本main_list = ['-s', '-v',*test_cases,'--durations=0', '--clean-alluredir','--alluredir', f'{Constant().REPORT_PATH}/allure_results'
]
pytest.main(main_list)
if not os.getenv("BUILD_URL"):os.system(f"{Constant.ALLURE_TOOL} serve {Constant().REPORT_PATH}/allure_results")  # 本地执行

执行测试

运行allure_debug.py文件

查看报告

图片

报告截图

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

在这里插入图片描述

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!   

http://www.lryc.cn/news/160562.html

相关文章:

  • React 与 TS 结合使用时的技巧总结
  • 【深入解析spring cloud gateway】07 自定义异常返回报文
  • 如何写一个sh脚本将一个本地文件通过 scp命令上传到远程的 centos服务器?
  • 【CMake工具】工具CMake编译轻度使用(C/C++)
  • 用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
  • 知识储备--基础算法篇-矩阵
  • Zabbix -- QQ邮箱报警
  • eclipse链接MySQL数据库
  • ansible 使用roles简单部署LAMP平台
  • 如何使用Web Storage对页面中数据进行监听?
  • GO语言网络编程(并发编程)runtime包
  • MR源码解析和join案例
  • ML+LLMs:利用LLMs大语言模型赋能或者结合ML机器学习算法进行具体应用的简介、具体案例之详细攻略
  • python GIL锁
  • git打tag和版本控制规范
  • php版 短信跳转微信小程序
  • leetcode127单词接龙刷题打卡
  • 基于SSM的物流管理系统
  • EagleSDR USB HAT FT600
  • Java多线程(四)锁策略(CAS,死锁)和多线程对集合类的使用
  • 基于spring boot+ vue+ mysql开发的UWB室内外定位系统源码
  • 第2章_瑞萨MCU零基础入门系列教程之面向过程与面向对象
  • 数字图像处理:亮度对比度-几何变换-噪声处理
  • maven报错:[ERROR] 不再支持源选项 7。请使用 8 或更高版本。
  • MySQL基础3-约束
  • OJ练习第166题——课程表(拓扑排序问题)
  • 单臂路由实现VLAN间路由
  • 【VSCode】文件模板创建及使用.md
  • 【漏洞复现】EnjoySCM存在文件上传漏洞
  • MaPLe: Multi-modal Prompt Learning