Here is my example table on my scenario outline, some does not have value, is this possible?
Examples:
|ID | UserName | Password | Contact1 | Number |
|ID1 | username1 | password1 | Phone | 111 222 4444 |
|ID2 | username2 | password2 | | |
|ID3 | username3 | password3 | Email | [email protected] |
|ID4 | username4 | password4 | | |
By using replaceWithEmptyString = "[blank]" on a datatable type an empty string can be explicitly inserted. Show activity on this post. The thing is that sometimes you want to pass null as value to the test.
That's where the importance of scenario outline comes into picture. When we define any scenario with scenario outline, we can specify one test scenario and at the bottom of it we can provide a number of inputs. The scenario will get executed as many times as the number of inputs provided.
Parametrization in Cucumber Cucumber supports Data Driven Testing using Scenario Outline and Examples keywords. Creating a feature file with Scenario Outline and Example keywords will help to reduce the code and testing multiple scenarios with different values.
The empty value will be considered a String if the feature step looks something like this:
Given ...
When I enter my "<Username>" and "<Password>"
And I enter my "<Contact>"
And I enter my "<Number>"
Then ...
You can manage the empty string inside the step definition:
@When("^I enter my \"([^\"]*)\"$")
public void I_enter_my(String contact) throws Throwable {
// Handle empty string as null
throw new PendingException();
}
Just an exmple, not sure if the code will work. Hope it helps.
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