edno / codeception-gherkin-param
此包已被废弃且不再维护。未建议替代包。
支持 Gherkin 功能中参数符号的 Codeception 模块
2.0.13
2023-02-18 13:46 UTC
Requires
- php: >=7.4 <9.0
- composer-runtime-api: ^2.0
- codeception/codeception: 3 - 5
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.8
- codeception/assert-throws: ^1.3
- codeception/mockery-module: ^0.4|^0.5
- codeception/module-asserts: ^2.0|^3.0
- infection/codeception-adapter: ^0.4
- infection/infection: ^0.26
- php-coveralls/php-coveralls: ^2.5
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.2
- squizlabs/php_codesniffer: ^3.7
README
支持 Gherkin 场景中参数符号的 Codeception 模块。
最低要求
- Codeception 3.x, 4.x, 5.x
- PHP 7.4 - 8.2 (旧版 PHP 版本请使用 2.0.6 版本)
安装
可以使用 Composer 安装此模块
composer require edno/codeception-gherkin-param --dev
请确保在下面的 codeception.yml
中启用该模块,如配置所示。
设置
在 codeception.yml
中启用 Gherkin Param。
modules: enabled: - Codeception\Extension\GherkinParam
配置
默认情况下,当无法找到参数的替换值时,GherkinParam 将保持参数字符串不变,即参数不存在或不可访问。
onErrorThrowException
如果设置为 true
,则在运行时找不到参数的替换值时,GherkinParam 将抛出 GherkinParam
异常。
modules: enabled: - Codeception\Extension\GherkinParam: onErrorThrowException: true
如果设置了
onErrorThrowException
,则将覆盖onErrorNullable
。
onErrorNullable
如果设置为 true
,则当无法找到替换值时,GherkinParam 将将参数设置为 null
。
modules: enabled: - Codeception\Extension\GherkinParam: onErrorNullable: true
使用方法
安装后,您将能够访问使用 Fixtures 存储的变量。
简单参数
在场景步骤中,可以使用语法 {{param}}
访问变量。在执行您的功能时,变量将自动替换为其值。
数组参数
可以使用语法 {{param[key]}}
引用数组中的元素。
测试套件配置参数
可以使用语法 {{config:param}}
引用测试套件配置参数。请注意,关键字 config: 是必需的。
示例
Feature: Parametrize Gherkin Feature In order to create a dynamic Gherkin scenario As a tester I need to be able to share data between scenario steps Scenario: Scenario using simple parameter Given I have a parameter "test" with value "42" Then I should see "{{test}}" equals "42" Scenario: Scenario using array parameter Given I have an array "test" with values [1, two, 3.14, IV, 101] Then I should see "{{test[1]}}" equals "two" Scenario: Scenario using config parameter Given I have a configuration file "acceptance.suite.yml" containing """ theResponse: 42 """ When I execute a scenario calling the parameter 'theResponse' Then I should see "{{config:theResponse}}" equals "42"
AcceptanceTester.php
中的步骤定义不需要任何更改
/** * @Given I have a parameter :param with value :value */ public function iHaveAParameterWithValue($param, $value) { Fixtures::add($param, $value); } /** * @Then I should see :arg1 equals :arg2 */ public function iSeeEqual($arg1, $arg2) { $this->assertEquals($arg1, $arg2); }
您可以在 测试文件夹 中找到更多示例。
贡献
欢迎贡献、问题和功能请求。如果您使用了这个包并为自己修复了一个错误,请考虑提交一个PR!
由contributors-img制作。