【问题标题】:giving whitespace as value of table of parameters in scenarios of Cucumber在 Cucumber 场景中将空格作为参数表的值
【发布时间】:2014-08-20 19:10:16
【问题描述】:

我使用 Cucumber 框架、WebDriver 和 Java 进行自动测试。对于参数化测试,我使用参数表。而且我不知道如何将空格作为参数值。而我变成了使用关键字——WHITESPACE。我的例子如下:

第一种方法

Scenario Outline: checking of sending feedback
Given User wants send feedback
When User enters to the feedback field the following text:
"""
<suggestion>
"""
And User presses on the 'Send' button
Then User should see message <message>

Examples:
|suggestion|message|
|| Suggestion's field is empty!|
|\n| Suggestion's field is empty!|
|\n text text text| Successfuly send!|
|WHITESPACE| Successfuly send!|

然后在步骤定义中:

@When("^User enters to the feedback field the following text:$")
public void user_enters_feedback(String textOfSuggestion) {
      textOfSuggestion.equals("WHITESPACE")?" ":textOfSuggestion;
      new pageSuggestion().inpSuggestion.sendKeys(textOfSuggestion)
}

相同场景的第二种方法

我也尝试使用Transformer,但它不起作用。

我创建了类

class MyTransformer extends Transformer<String> {
    public String transform(String value) {
         value.equals("WHITESPACE")?" ":value;
         return value;
     }
}

然后在步骤定义中:

@When("^User enters to the feedback field the following text:$")
public void user_enters_feedback(@Transform(MyTransformer.class) String textOfSuggestion) {
      new pageSuggestion().inpSuggestion.sendKeys(textOfSuggestion)
}

如何才能更好地重复使用其他步骤或添加新关键字?

提前致谢。

【问题讨论】:

    标签: cucumber cucumber-jvm gherkin


    【解决方案1】:

    你根本不需要做任何事情。考虑一下这个

    Scenario Outline: Something
      Given I have "<param>"
      ...    
      Examples:
      |param|
      |     | #spaces
      ||      #empty
    

    当参数为空白/空时,这会愉快地打印“Empty...”

    @Given("^I have \"(.*?)\"$")
    public void i_have(String arg1) {
      if (arg1.trim().equals("")) {
        System.out.println("Empty...")
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-06
      • 2014-10-28
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多