我有一个 cucumber 方案纲要,其中我要向Examples表传递一个空字符串(“”)和换行符(\n\n\n)作为值。我想编辑一个文本字段,并且要删除该字符串,并希望传入空字符串或换行符。我要发送此值,然后按Enter。看起来像是.sendKeys(value +“\n”)。在“示例”表中,仅将值保留为空白并通过\n\n\n无效。文本字段中的值保持不变。
方案大纲如下所示:

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 |

有任何想法吗?谢谢

最佳答案

您只需要在功能定义中的“”之间放置<columnName>。例子:

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 {
      ...
   }

希望能帮助到你

关于 cucumber 方案大纲: Passing empty string "" as value in Examples table,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25646865/

10-13 04:56