【问题标题】:Cucumber Scenario Outline: Passing empty string " " as value in Examples tableCucumber 场景大纲:将空字符串“”作为示例表中的值传递
【发布时间】:2014-10-28 02:30:19
【问题描述】:

我有一个黄瓜场景大纲,我想在示例表中传递一个空字符串 (" ") 和换行符 (\n \n \n) 作为值。我想编辑一个文本字段,我正在删除字符串并想传入空字符串或换行符。我想发送这个值并按回车。这看起来像这样 .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 |

有什么想法吗?谢谢

【问题讨论】:

  • 嗨@julesmummdry!你最终使用了我的解决方案吗?如果是这样,如果有帮助,也许您可​​以将答案标记为已接受

标签: cucumber string cucumber-jvm


【解决方案1】:

您只需将&lt;columnName&gt; 放在您的特征定义中的“”之间。示例:

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

希望对你有帮助

【讨论】:

  • 谢谢,将尝试...同时发现不同的解决方案。所以我将 unicode 字符传递给 SPACE 并将其转义(\\u0020)。我有一个 Stringparser 将其取消转义并将其设置为名称 (name = StringParser.unescapeString(name);)。这对我有用,但会检查你的小费。谢谢
  • 好方法。但我认为我的解决方案更简单。此外,与 IDE(在我的例子中为 IntelliJ)的集成期望 "" 链接每一步功能文件 java 类。试试看,祝你好运
  • 谢谢!这可行,但更多的是解决黄瓜中缺少的功能..
猜你喜欢
  • 2020-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多