edno/codeception-gherkin-param

此包已被废弃且不再维护。未建议替代包。

支持 Gherkin 功能中参数符号的 Codeception 模块

2.0.13 2023-02-18 13:46 UTC

README

Latest Version Build Status Coverage Status Mutation Score License FOSSA Status

支持 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!

68747470733a2f2f636f6e747269622e726f636b732f696d6167653f7265706f3d65646e6f2f636f646563657074696f6e2d676865726b696e2d706172616d

contributors-img制作。