Daniel
Daniel

Reputation: 35

My Behat Scenario Outline's step definition returns undefined

I'm creating tests for my code using Behat v3.0, but I have several steps in my features file's Scenario Outlines that remain undefined.

An example of my Scenario Outlines:

Scenario Outline: Send email validation messages
    Given I have the email <email>
    When I send the email
    Then the response status code should be "500"
    And I get a message from the <variable> variable that reads <message>

    Examples:
        | email | variable | message                                  |
        |       | email    | The email field is required.             |
        | -1    | email    | The email must be a valid email address. |
        | email | email    | The email must be a valid email address. |

I used the documentation at http://docs.behat.org/en/stable/guides/1.gherkin.html#scenario-outlines.

To define the steps, I have step definition methods in FeatureContext.php for the two problem steps: "I have the email < email >" and "I get a message from the variable that reads < message >":

/**
 * @Given I have the email :email
 */
public function iHaveTheEmail($email)
{
    // Save the email address
}

/**
 * @Then I get a message from the :variable variable that reads :message
 */
public function iGetAMessageFromTheVariableThatReads($variable, $message)
{
    // Check the response for the validation errors
}

I used the documentation at http://docs.behat.org/en/v3.0/guides/2.definitions.html

The output from running Behat insists that those step are still undefined. Only the steps with parameters associated with the examples lists have this problem. The step "the response status code should be '500'" works as intended.

I cannot find specific examples of defining steps in a Scenario Outline, and the documentation is generally sparse for Behat.

I may be able to define the steps with a regex comment like in Behat v2.5, but is that the only solution?

Upvotes: 0

Views: 919

Answers (1)

Bastian Br&#228;u
Bastian Br&#228;u

Reputation: 791

You should use quotes for your arguments:

Scenario Outline: Send email validation messages
    Given I have the email "<email>"
    When I send the email
    Then the response status code should be "500"
    And I get a message from the "<variable>" variable that reads "<message>"

Or you could use regular expressions, like Mink Extension does:

https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/Context/MinkContext.php#L38

Upvotes: 1

Related Questions