Skip to main content

A plugin to test mp

Project description

pytest-mini

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

基于MiniTest进行pytest改造

使用方法

准备测试小程序

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

成功运行后关闭

安装&更新

pip install pytest-mini --upgrade

引入插件

新建conftest.py文件

from pytest_mini import plugins

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

例如demo/cases/conftest.py

from pytest_mini import plugins

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

编写页面对象

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

from pytest_mini import Mini, Locator


class 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 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

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

查看报告

报告截图

实际项目报告截图

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_mini-0.1.19.tar.gz (19.6 MB view details)

Uploaded Source

Built Distribution

pytest_mini-0.1.19-py3-none-any.whl (19.6 MB view details)

Uploaded Python 3

File details

Details for the file pytest_mini-0.1.19.tar.gz.

File metadata

  • Download URL: pytest_mini-0.1.19.tar.gz
  • Upload date:
  • Size: 19.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for pytest_mini-0.1.19.tar.gz
Algorithm Hash digest
SHA256 a91873b9bf57da8c8419f69ab83c9529b6ec7a03ade360317f33257dde9ac06e
MD5 171825a2269571fabf69ee7e6f491792
BLAKE2b-256 3b88edff2d4dfc61f9e900ad5b11bc8df7213bd5321be1f8cabfa992bcba45e3

See more details on using hashes here.

File details

Details for the file pytest_mini-0.1.19-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_mini-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 506ff4809ad185d09835ad343dbebc9cb7c6fa89c787587b6f10bdea8433cd1c
MD5 6370bfd9b4f22148b9aa307c8d308bbc
BLAKE2b-256 517e5dae1e0abd92c07ea61b6c64fd74b54487f29ff222a9ba0084e083e10366

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page