I use the Cucumber framework, WebDriver and Java for auto testing. For parametrized tests I use table of parameters. And I don't know how to give whitespace as value of parameter. And I become to use keyword - WHITESPACE. My example bellow:
First method
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!|
then in step definition:
@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)
}
Second method for same scenatio
Also I try to use Transformer, but it did not work.
I created class
class MyTransformer extends Transformer<String> {
public String transform(String value) {
value.equals("WHITESPACE")?" ":value;
return value;
}
}
then in step definition:
@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)
}
How I can do it better for reusing with another steps or adding new keywords?
Thanks in advance.
You dont have to do anything at all. Consider this
Scenario Outline: Something
Given I have "<param>"
...
Examples:
|param|
| | #spaces
|| #empty
This happily prints "Empty..." when param is blank/empty
@Given("^I have \"(.*?)\"$")
public void i_have(String arg1) {
if (arg1.trim().equals("")) {
System.out.println("Empty...")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With