3
Feature:player
@all

  Scenario Outline:Where is the player

    Given I navigate to Google
    When I enter < player> in the search field
    Then the text < keyword1> should be present

    @current @football
    Examples:
      | player  | keyword1   |
      | Rooney  | Manchester |
      | Gerrard | Liverpool  |
      | Terry   | Chelsea    |
    @old @football
    Examples:
      | player          | keyword1   |
      | Eric Cantona    | Manchester |

If I write Cantona instead of Eric Cantona then it is working, but as soon as you run the program with white space inserted in a string it gives an error.

orde
  • 5,233
  • 6
  • 31
  • 33
user1304665
  • 31
  • 1
  • 2

2 Answers2

3

Try putting quotes around the Scenario Outline placeholders (and removing the leading space from the placeholder). For example:

Scenario Outline: Where is the player

  Given I navigate to Google
  When I enter "<player>" in the search field
  Then the text "<keyword1>" should be present
orde
  • 5,233
  • 6
  • 31
  • 33
  • Both the answers are saying the same thing, but adding quotes around example variable used in gherkin is always the best practice.. and that should be the direction followed. – Parva Thakkar Mar 30 '14 at 04:42
3

The problem is that your step definition is only looking for a single word:

When /^I enter (\w+) in the search field$/ do | player | 

Cucumber uses regular expressions to match steps to their definitions, and to capture the variables. Your step definition is looking for "I enter ", followed by a single word, followed by " in the search field".

You could change the "player" regex from (\w+) to something like ([\w\s]+). That would match words and white space and should match the multi word example.

When /^I enter ([\w\s]+) in the search field$/ do | player | 

Alternatively if you surround your variables with quotes (as suggested by orde) then Cucumber should generate step definitions which match anything inside the quotes using a (.*) group.

James McCalden
  • 3,696
  • 2
  • 16
  • 18