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

-mini

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

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

基于MiniTest进行pytest改造

使用方法

准备测试小程序

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

成功运行后关闭

安装&更新

复制代码
pip install pytest-mini --upgrade

引入插件

新建conftest.py文件

python 复制代码
from pytest_mini import plugins

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

例如demo/cases/conftest.py

python 复制代码
from pytest_mini import plugins

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

编写页面对象

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

python 复制代码
from pytest_mini import Mini, Locator


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

在conftest.py中添加

python 复制代码
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

python 复制代码
import allure

from 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

python 复制代码
import os
import pytest
from pytest_mini.constant import Constant

test_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文件

查看报告

报告截图

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

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

相关推荐
可爱系程序猿3 小时前
msvcp120.dll 加载失败排查:VC++ 2013、进程架构与插件私有目录如何对应
程序人生·电脑·c++20
Nil2089 小时前
leetcode 105从前序和中序遍历序列构造二叉树
算法·leetcode·职场和发展
破土士V10 小时前
【软件测试】测试用例&测试分类
软件测试·测试用例·测试方法·case·测试分类
郝学胜-神的一滴11 小时前
Effective Python 条款 1:确认你正在使用的 Python 版本
开发语言·数据结构·python·程序人生·算法
测试199812 小时前
接口自动化测试的全面解析与实战指南
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
可爱系程序猿12 小时前
mfc100.dll 加载失败排查:旧版 VC++ 2010 程序、位数与插件目录如何核对
程序人生·电脑·c++20
FPC工厂——皇榜科技14 小时前
【皇榜科技线路板质量课堂·第40篇】PPAP(生产件批准程序):批量生产前的“终极面试”
科技·面试·职场和发展·制造·pcb工艺
Forever Nore16 小时前
LeetCode 16 最接近的三数之和 - 双指针逼近
算法·leetcode·职场和发展
重生之后端学习17 小时前
438. 找到字符串中所有字母异位词[中等]✅
开发语言·数据结构·算法·leetcode·职场和发展