limetecbiotechnologies / behat-logger-extension
将behat执行日志记录到json结果中
Requires
- php: ^8.0
- ext-json: *
- behat/behat: ^3.3
- behat/mink-extension: ^2.2
- behat/mink-selenium2-driver: ^1.3
- limetecbiotechnologies/testrail-php-api: ^1.1
- stecman/symfony-console-completion: ^0.8.0
- symfony/finder: ^3.3|^4.2
- symfony/framework-bundle: ^3.3|^4.2
- symfony/http-kernel: ^3.3|^4.2
Requires (Dev)
- phpunit/phpunit: ^5.7|^6.0|^9.5
- dev-master
- v3.1.0
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.1.1
- v2.1.0
- v2.0.0
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.1
- v0.1.0
- v0.0.21
- v0.0.20
- v0.0.19
- v0.0.18
- v0.0.17
- v0.0.16
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- v0.0.0
- dev-path-fix
- dev-file_exists
- dev-check-exists
- dev-master_2
- dev-master_1.6
This package is auto-updated.
Last update: 2024-09-10 13:42:39 UTC
README
本包为behat提供扩展,用于将测试结果记录到json文件中。本包还提供命令来验证和合并这些json文件。
安装
信息:如果您想为项目使用behat日志扩展,请阅读“PHP集成”部分!安装部分仅安装作为独立应用的cli命令
对于用户,现在有一个可用的docker镜像。对于开发者,请参阅PHP集成
从1.x迁移到2.x
自2.0主要版本以来,测试同步的标识方式已更改。在版本1中,使用场景标题进行同步。在本版本中,将使用behat标签提供的id。每个测试都需要一个唯一的标识标签。例如“@testrail-case-1,@testrail-case-2等。”将依赖更新到最后一个1.x版本,并在您的.testrail.yml中添加以下属性
api: ... identifier_tag_field: yourNewIdentifierField
执行testrail:push:cases命令将所有id添加到testrail中的案例。现在您可以更新到2.x(但.testrail.yml的一些属性已更改!!)
docker镜像
docker run -v /path/to/project/:/behat/ seretos/behat-logger-cli behat-logger-cli list
将docker容器添加到您的docker-compose.yml中
version: '3.7' services: features-push: image: seretos/behat-logger-cli command: push volumes: - ./:/behat/ environment: TESTRAIL_SERVER: http://testrail:80 TESTRAIL_USER: yourTestrailLogin TESTRAIL_PASSWORD: yourTestrailPassword TESTRAIL_PROJECT: yourTestrailProject TESTRAIL_SUITE: yourTestrailSuite features-validate: image: seretos/behat-logger-cli command: validate volumes: - ./:/behat/
PHP集成
将包添加到您的项目中,如下所示
composer require seretos/behat-logger-extension --dev vendor/bin/behat-logger-cli --help
在您的behat.yml中激活日志记录器
default: formatters: logger: ~ extensions: seretos\BehatLoggerExtension\BehatLoggerExtension: output_path: '%paths.base%/build/behat'
可选:如果您使用symfony应用程序,可以将此扩展(seretos\BehatLoggerExtension\BehatLoggerExtensionBundle)添加到您的Symfony Kernel中,并将命令集成到您的cli中
命令行使用
将不同的结果json文件合并到一个文件和一个套件中
behat-logger-cli combine:logs [suite-name] --output=/output/path/ --regex=results/firefox*
如果不同的json文件包含一个具有相同环境的测试结果的测试结果,则此命令抛出异常
将所有找到的功能文件转换为不带结果的单个json文件
behat-logger-cli feature:to:log [suite-name] --output=/output/path/ --regex=features/
检查日志文件中的所有场景是否具有唯一的标题
此命令已弃用,请将来使用validate:scenario:id!
behat-logger-cli validate:scenario:title [log-file.json]
检查日志文件中的所有场景是否具有唯一的id标签
behat-logger-cli validate:scenario:id [log-file.json] --identifier_tag_regex="/^testrail-case-([0-9]*)$/"
检查所有测试是否在给定的环境中执行
# check that all browserless tests are executed behat-logger-cli validate:execution actual.json expected.json --tags=~javascript --environments=unknown # check that all browser tests are executed in firefox and chrome behat-logger-cli validate:execution actual.json expected.json --tags=javascript --environments=firefox --environments=chrome
将json结果发送到testrail并创建部分和案例
behat-logger-cli testrail:push:cases testRailSuiteName actual.json
将json结果发送到testrail并创建环境配置
behat-logger-cli testrail:push:configs actual.json
将json结果发送到testrail并创建结果
behat-logger-cli testrail:push:results testRailSuiteName actual.json testResultName --milestone=v2.8.0
命令testrail:push:cases和testrail:push:results需要一个包含以下信息的当前工作目录中的.testrail.yml
api: server: https://yourTestrail.testrail.io/ user: yourUser@mail.de password: yourPassword project: youtProject template: Test Case (Steps) type: Automated title_field: custom_preconds group_field: custom_automation_type identifier_field: custom_identifier identifier_regex: /^testrail-case-([0-9]*)$/ # set field an priorities on specific tags fields: /^.*$/: custom_automation_type: Behat priorities: /^priority_low$/: Low
日志格式
首先,json文件包含behat套件。如果日志写入器无法检测套件名称,则使用名为“default”的套件
{ "suites": [ { "name": "default", "features": { ... } } ] }
套件包含功能列表
"features": { "features\/featurefile.feature": { "title": "feature title", "filename": "features\/featurefile.feature", "description": null, "language": "en", "scenarios": { ... } }, ... }
功能包含带有步骤和结果的场景
"scenarios": { "scenariotitle": { "title": "scenariotitle", "tags": ["behattag1","behattag2"], "steps": [ { "line": 0, "text": "the user 'test' exists", "keyword": "Given", "arguments": [] }, { "line": 1, "text": "i logged in as 'test'", "keyword": "And", "arguments": [] } ], "results": [ ... ] }, ... }
最后但并非最不重要的是,包含功能结果。环境属性是浏览器名称。在guette中,环境名称设置为“unknown”
"results": [ "firefox": { "environment": "firefox", "duration": "1.00", "message": null, "stepResults": [ { "line": 0, "passed": true, "screenshot": null, "message": null }, { "line": 1, "passed": true, "screenshot": null, "message": null } ] } ]