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


    -mini

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

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

    基于MiniTest进行pytest改造

    使用方法

    准备测试小程序

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

    成功运行后关闭

    安装&更新

    pip install pytest-mini --upgrade
    

    引入插件

    新建conftest.py文件

    1. from pytest_mini import plugins
    2. pytest_plugins = plugins(
    3. "待测试的小程序项目路径",
    4. "微信开发者工具路径"
    5. )

    例如demo/cases/conftest.py

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

    编写页面对象

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

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

    在conftest.py中添加

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

    编写测试代码

    demo/cases/test_home.py

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

    编写执行&报告展示脚本

    demo/cases/allure_debug.py

    1. import os
    2. import pytest
    3. from pytest_mini.constant import Constant
    4. test_cases = ["test_home.py"] # 执行的脚本
    5. main_list = [
    6. '-s', '-v',
    7. *test_cases,
    8. '--durations=0', '--clean-alluredir',
    9. '--alluredir', f'{Constant().REPORT_PATH}/allure_results'
    10. ]
    11. pytest.main(main_list)
    12. if not os.getenv("BUILD_URL"):
    13. os.system(f"{Constant.ALLURE_TOOL} serve {Constant().REPORT_PATH}/allure_results") # 本地执行

    执行测试

    运行allure_debug.py文件

    查看报告

    图片

    报告截图

    最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

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

  • 相关阅读:
    Docker基础(简单易懂)
    推荐模型-上下文感知-2021:DCNv2
    OpenCV4 :并行计算cv::parallel_for_
    sqlalchemy expire_all 方法详解,强制刷新会话缓存
    A公司与B公司xx项目互通测试解决方案模板
    C++——IO流
    【又来摸鱼】如何用Python + baidu-aip 实现人脸识别?
    Python---upper()--转大写///与lower() --转小写
    ftrace和tracepoint简单使用
    Android 行情都这样了,面试问的还这么难?
  • 原文地址:https://blog.csdn.net/NHB456789/article/details/136712011