行为库与testrail api集成
behave-testrail-reporter的Python项目详细描述
按照TestRail Reporter的要求行事
此集成用于在执行行为测试时自动将测试结果添加到TestRail。
生成报告的示例:
3 testrail test cases passed, 0 failed, 19 skipped, 2 untested
Took 0m6.349s
安装
可以使用pipenv安装
$ pipenv install behave-testrail-reporter
或使用pip
$ pip install behave-testrail-reporter
设置
通过在before_all()
中添加此代码,添加TestrailReporter
以在/features/environment.py
中表现记者行为
frombehave_testrail_reporterimportTestrailReporterdefbefore_all(context):# ... all your other awesome code in herecurrent_branch=os.environ.get('CIRCLE_BRANCH')# Change this to get the current build branch of your CI systemtestrail_reporter=TestrailReporter(current_branch)context.config.reporters.append(testrail_reporter)
在项目根目录中创建一个testrail.yml
配置文件
示例结构:
projects:-name:'Testrun{branch}'id:123suite_id:456# note: this will allow any branch to push test case results to Testrail.allowed_branch_pattern:'.*'
只允许master分支和release1.111.1将测试结果推送到testrail:
projects:-name:'Testrun{branch}'id:123suite_id:456allowed_branch_pattern:'^(master|release\/\d+([\.\d]+)?)$'
yaml key | Description |
---|---|
name | Project name |
id | Testrail project id |
suite_id | Testrail Suite id |
allowed_branch_pattern | Regular expression to restrict when a test run is executed |
name-可以使用一些项目变量创建动态测试运行名
Variable | Example | Result |
---|---|---|
{project_id} | 'Test run {project_id}' | Test run 123 |
{suite_id} | 'Test run {suite_id}' | Test run 456 |
{branch} | 'Test run {branch}' | Test run master |
需要环境变量
Variable name | Description |
---|---|
TESTRAIL_KEY | TestRail user password |
TESTRAIL_USER | TestRail user email address |
如何使用
要在testrail上获得标记为成功或失败的测试用例,我们必须添加带有testrail测试用例id的标记 在每个场景中。
测试用例标签结构:
prefix
+test case id
@testrail-
+C1104
请参见下面的示例:
Feature: Log in and outBackground: Given I am logged out from HubAnd I navigate to the home page@testrail-C1104@testrail-C45933Scenario: Admin can login When I enter the username adminAnd I enter the password adminAnd I click the Login buttonThen I see the admin's landing page
注意:有些场景可以覆盖多个testrail案例,因为您只需要添加多个标记。
如何贡献
安装开发依赖项
pipenv install --dev
如何运行测试
激活虚拟环境,然后运行tox。
tox
如何分配
如果需要发布此软件包的新版本,可以使用以下命令:
python setup.py sdist bdist_wheel
twine upload dist/*
许可证
根据MIT license
授权。视图license。