黄瓜场景大纲:在示例表中将空字符串“”作为值传递

时间:2014-09-03 14:24:24

标签: cucumber string cucumber-jvm

我有一个黄瓜场景大纲,其中示例表我想传递一个空字符串(“”)和换行符(\ n \ n \ n)作为值。我想编辑一个文本字段,我正在删除字符串,并希望传入空字符串或换行符。我想发送此值并按Enter键。这看起来像这样.sendKeys(值+“\ n”)。在示例表中,将值保留为空并传递\ n \ n \ n不起作用。文本字段中的值不会更改。
这就是Scenario大纲的样子:

Scenario Outline: Do not accept erroneous input as group conversation name (only spaces and break lines)
Given I Sign in using login <Login> and password <Password>
And I see Contact list with name <Name>
And I create group chat with <Contact1> and <Contact2>
When I open conversation with <Contact1>, <Contact2>
And I open Conversation info
And I set name <NewName> for conversation
Then I do not see conversation <NewName> in contact list
And I see Contact list with name <Contact1>, <Contact2>

Examples: 
  | Login   | Password    | Name    | Contact1    | Contact2    | NewName       |
  | aqaUser | aqaPassword | aqaUser | aqaContact1 | aqaContact2 |               |
  | aqaUser | aqaPassword | aqaUser | aqaContact1 | aqaContact2 | \n\n\n\n      |

如何传递值?
当我只是将值传递为硬编码时,它可以工作。文本字段至少被替换为值,但我希望将其作为占位符 硬编码版本:

Scenario Outline: Do not accept erroneous input as group conversation name (only spaces)
Given I Sign in using login <Login> and password <Password>
And I see Contact list with name <Name>
And I create group chat with <Contact1> and <Contact2>
When I open conversation with <Contact1>, <Contact2>
And I open Conversation info
And I set name     for conversation
Then I do not see conversation     in contact list
And I see Contact list with name <Contact1>, <Contact2>

Examples: 
  | Login   | Password    | Name    | Contact1    | Contact2    |
  | aqaUser | aqaPassword | aqaUser | aqaContact1 | aqaContact2 |

Scenario Outline: Do not accept erroneous input as group conversation name (line breaks)
Given I Sign in using login <Login> and password <Password>
And I see Contact list with name <Name>
And I create group chat with <Contact1> and <Contact2>
When I open conversation with <Contact1>, <Contact2>
And I open Conversation info
And I set name \n\n\n\n\n for conversation
Then I do not see conversation \n\n\n\n\n in contact list
And I see Contact list with name <Contact1>, <Contact2>

Examples: 
  | Login   | Password    | Name    | Contact1    | Contact2    |
  | aqaUser | aqaPassword | aqaUser | aqaContact1 | aqaContact2 |

有什么想法吗?感谢

1 个答案:

答案 0 :(得分:8)

您只需将<columnName>放在&#34;&#34;之间。在您的功能定义中。例如:

And I set name "<NewName>" for conversation

在您的步骤定义中,该步骤可以注释如下:

   @And("^And I set name \"([^\"]*)\" for conversation$")
   public void And_I_set_name_for_conversation(String newName) throws Throwable {
      ...
   }

希望有所帮助