要在Allure报告中生成testCaseId,可以按照以下步骤进行操作:
pip install allure-behave
Feature: My Feature
Scenario: My Scenario
Given I have a precondition
When I perform some action
Then I should see the expected result
@testcaseid
Examples:
| param1 | param2 |
| value1 | value2 |
allure.dynamic.description
装饰器来动态添加testCaseId:import allure
@allure.dynamic.description("TestCaseId: {testCaseId}")
@given('I have a precondition')
def step_given_precondition(context):
context.testCaseId = 'TC001'
# Perform some action
@allure.dynamic.description("TestCaseId: {testCaseId}")
@when('I perform some action')
def step_when_perform_action(context):
context.testCaseId = 'TC001'
# Perform some action
@allure.dynamic.description("TestCaseId: {testCaseId}")
@then('I should see the expected result')
def step_then_expected_result(context):
context.testCaseId = 'TC001'
# Perform some action
allure_behave.hooks
模块,并在其中添加一个allure_behave.tag_marker
钩子函数:from allure_commons._allure import attach
from allure_commons.types import AttachmentType
def tag_marker(tag, step):
if tag.startswith('testcaseid'):
if hasattr(step, 'testCaseId'):
attach(step.testCaseId, 'TestCaseId', AttachmentType.TEXT)
environment.py
文件中,导入allure_behave.hooks
模块,并在before_tag
钩子函数中添加tag_marker
:from allure_behave.hooks import tag_marker
def before_tag(context, tag):
tag_marker(tag, context._runner.step)
behave --format allure_behave.formatter:AllureFormatter -o allure-results
通过以上步骤,可以将testCaseId
添加到Allure报告中,并根据需要进行其他定制化。