pytest+allure生成测试报告Parameters操作

问题:

表格中的测试用例参数化后通过allure生成报告的Parameters内容显示太多,不美观

在网上找到一个方法是在 Lib->site-packages->allure-pytest->listener.py,修改以下代码

# 修改前
test_result.parameters.extend(
    [Parameter(name=name, value=represent(value)) for name, value in params.items()
     if name not in current_param_names])
     
# 修改后 (将列表内容去除即可)     
test_result.parameters.extend([])

但是在新版allure中不适用,会导致用例丢失,去看了社区中的描述得到下面的解决方案

解决方案:

Parameters重写

allure.dynamic.parameter("testcases", "123")

没有研究出来如何隐藏Patameters,

  • allure.dynamic.parameter(name, value, excluded=None, mode=None)

Specify a name and value of a parameter that was used during this test.

This can be used for adding the parameters even to those function that do not use the pytest's parametrization features. In the second example below, there are no test parameters as far as pytest is concerned, however, the test report will display the “login” parameter.

You can also override display values for the existing parameters. In the third example below, the test report will use the short value for the parameter instead of the full path. Note that changing the display value does not affect the unique identifier for the tests history.

The parameters can be used in the test's title, see Title.

If the excluded argument is set to True, Allure will not use the parameter when comparing the current test result with previous one in the history. This argument is only used by Allure TestOps.

The mode argument affects how the parameter will be displayed in the report. Available options are defined in the allure.parameter_mode enumeration:

  • allure.parameter_mode.DEFAULT (same as not specifying any mode) — the parameter and its value will be shown in a table along with other parameters.
  • allure.parameter_mode.MASKED — the parameter will be shown in the table, but its value will be hidden. Use this mode for passwords, tokens and other sensitive parameters.
  • allure.parameter_mode.HIDDEN — the parameter and its value will not be shown in the test report. Note, however, that it is still possible to extract the value from the allure_results directory if you publish it.

mode好像没有用一样,用allure.parameter_mode.HIDDEN隐藏不了,不知道是不是理解上有问题

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当使用 Appium、PytestAllure生成测试淘宝 App 的完整框架时,可以按照以下步骤进行: 1. 安装必要的软件和库: - 安装 Python:访问 Python 官方网站(https://www.python.org/),下载并安装最新版本的 Python。 - 安装 Pytest:在命令行中运行 `pip install pytest`。 - 安装 Appium-Python-Client:在命令行中运行 `pip install Appium-Python-Client`。 - 安装 Allure-Pytest:在命令行中运行 `pip install allure-pytest`。 2. 配置 Appium 环境: - 下载并安装 Appium Desktop(https://github.com/appium/appium-desktop)。 - 启动 Appium Desktop,并设置 Appium 服务器的相关配置,如设备连接信息、应用程序路径等。 3. 创建测试文件和目录结构: - 创建一个新的目录来保存你的测试代码和相关文件。 - 在该目录下创建一个名为 `conftest.py` 的文件,用于配置测试环境和共享的方法。 - 创建一个名为 `test_taobao.py` 的文件,用于编写测试用例和测试步骤。 4. 编写测试用例: - 在 `test_taobao.py` 文件中导入所需的库和模块,如 `pytest`、`Appium-Python-Client`、`allure` 等。 - 编写测试用例,可以使用 `pytest` 提供的装饰器来标记测试用例,如 `@pytest.mark.parametrize`、`@pytest.fixture` 等。 - 在测试用例中,使用 `Appium-Python-Client` 提供的方法来控制 Appium 服务器和执行 App 操作,如启动 App、查找元素、点击按钮等。 - 可以使用 `allure` 提供的装饰器和方法来添加测试步骤、生成测试报告、添加截图等。 5. 运行测试用例: - 在命令行中进入到测试代码所在的目录。 - 运行命令 `pytest --alluredir=./allure-results` 来执行测试用例,并生成 Allure 报告所需的数据。 6. 生成测试报告: - 在命令行中运行 `allure serve ./allure-results` 来生成并打开 Allure 报告。 以下是一个简单的示例代码,用于演示如何使用 Appium、PytestAllure 进行淘宝 App 的自动化测试: ```python import allure import pytest from appium import webdriver @pytest.fixture(scope='session') def driver(): desired_caps = { 'platformName': 'Android', 'deviceName': 'YourDeviceName', 'appPackage': 'com.taobao.taobao', 'appActivity': 'com.taobao.tao.homepage.MainActivity3', 'noReset': True } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) yield driver driver.quit() @allure.feature('淘宝 App 测试') class TestTaobaoApp: @allure.story('搜索商品') def test_search_product(self, driver): with allure.step('启动淘宝 App'): # 启动淘宝 App with allure.step('搜索商品'): # 在搜索框中输入关键词 with allure.step('点击搜索按钮'): # 点击搜索按钮 with allure.step('验证搜索结果'): # 验证搜索结果是否符合预期 with allure.step('添加截图'): # 添加当前页面的截图到报告中 allure.attach(driver.get_screenshot_as_png(), name='搜索结果截图', attachment_type=allure.attachment_type.PNG) ``` 请根据你的具体测试需求和环境配置,修改和扩展上述示例代码。这只是一个简单的框架示例,具体的实现方式可能因项目要求和测试需求而有所不同。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值