Skip to content
main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

Gherkin Param

Packagist Latest Version Build Status Coverage Status Infection MSI GitHub license FOSSA Status

The Codeception module for supporting parameter notation in Gherkin scenario.

Minimum Requirements

  • Codeception 3.x, 4.x
  • PHP 7.2 - 8.0

Installation

The module can be installed using Composer

composer require edno/codeception-gherkin-param --dev

Be sure to enable the module in codeception.yml as shown in configuration below.

Setup

Enabling Gherkin Param is done in codeception.yml.

modules:
    enabled:
        - Codeception\Extension\GherkinParam

From version 2.0, GherkinParam is now a module. If you are upgrading from 1.x to 2.x, then you'll have to update your Codeception configuration.

Configuration

The version 2 introduces two new configuration parameters for customizing runtime behaviour when the scenario parameters are invalid or not initialized (see PR#23 and PR#26).

By default GherkinParam behaviour is to keep the parameter string unchanged when the replacement value for a parameter cannot be found, ie the parameter does not exist or is not accessible.

onErrorThrowException

If true then GherkinParam will throw a exception GherkinParam at runtime when a replacement value cannot be found for a parameter:

modules:
    enabled:
        - Codeception\Extension\GherkinParam:
            onErrorThrowException: true

If onErrorThrowException is set then it will override onErrorNullable.

onErrorNullable

If true then GherkinParam will set to null parameters for which a replacement value cannot be found:

modules:
    enabled:
        - Codeception\Extension\GherkinParam:
            onErrorNullable: true

Usage

Once installed you will be able to access variables stored using Fixtures.

Simple parameters

In scenario steps, the variables can be accessed using the syntax {{param}}.
While executing your features the variables will be automatically replaced by their value.

Array parameters

You can refer to an element in an array using the syntax {{param[key]}}.

Test Suite Config parameters

You can refer to a test suite configuration parameter using the syntax {{config:param}}.
Note that the keyword config: is mandatory.

Example

Feature: Parametrize Gherkin Feature
  In order to create 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"

The steps definition in AcceptanceTester.php do not require any change

/**
 * @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);
 }

You can find more examples in the test folder.

License

FOSSA Status