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 |

如果我写 Cantona 而不是 Eric Cantona,那么它可以工作,但是一旦你运行程序并在字符串中插入空格,它就会出错。

4

2 回答 2

3

尝试在 Scenario Outline 占位符周围加上引号(并从占位符中删除前导空格)。例如:

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
于 2013-10-25T00:54:24.953 回答
2

问题是您的步骤定义只寻找一个单词:

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

Cucumber 使用正则表达式将步骤与其定义相匹配,并捕获变量。您的步骤定义是寻找"I enter ",后跟一个单词,然后是" in the search field"

(\w+)您可以将“播放器”正则表达式从更改为([\w\s]+). 这将匹配单词和空格,并且应该匹配多单词示例。

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

或者,如果您用引号将变量括起来(如 orde 所建议的那样),那么 Cucumber 应该使用 (.*) 组生成与引号内的任何内容匹配的步骤定义。

于 2013-11-05T13:41:36.193 回答