Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possbile to have a null value on Example table on Cucumber Scenario Outline? [duplicate]

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 |          |              |
like image 311
Sachi Avatar asked Jul 13 '17 12:07

Sachi


People also ask

How do you pass empty string in cucumber example?

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.

What is the purpose of a scenario outline and examples keyword in cucumber?

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.

How do you Paramize a scenario outline in cucumber?

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.


1 Answers

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.

like image 126
Daniel Fintinariu Avatar answered Oct 15 '22 05:10

Daniel Fintinariu