Contents

Define and use a macro taking one argument

As a Cuke user I want to pass data to macro-steps So that I can use them in more varied situations.

Scenario: Defining a macro-step with one argument (userid)

The next step creates a macro(-step)

The syntax of the new macro-step to create is specified between the double quotes.

The steps to execute when the macro is used/invoked are listed in the multiline triple quotes arguments.

The macro argument is put between chevrons <...>.

  • Given I define the step "* I [log in as <userid>]" to mean:
    Given I landed in the homepage
    When I click "Sign in"
    # The next step uses the macro-step argument <userid>
    And I fill in "Username" with "<userid>"
    And I fill in "Password" with "unguessable"
    And I click "Submit"

Scenario: Use the macro created above pass it a user id

Here the macro is invoked. Actual value for the argument is put between double quotes.

  • When I [log in as "guest"]
  • Then I expect the following step trace:
    Given I landed in the homepage
    When I click "Sign in"
    And I fill in "Username" with "guest"
    And I fill in "Password" with "unguessable"
    And I click "Submit"

Scenario: Use the macro with another user id

  • When I [log in as "me-again"]
  • Then I expect the following step trace:
    Given I landed in the homepage
    When I click "Sign in"
    And I fill in "Username" with "me-again"
    And I fill in "Password" with "unguessable"
    And I click "Submit"

Source: features/2_Macros_with_arguments/demo02.feature at commit de435b20, Macros4cuke (MIT license).