-
Book Overview & Buying
-
Table Of Contents
Cucumber Cookbook
By :
In the previous recipe, we learnt how we can send data in Steps, which can be used by the application for processing. The data that we have sent up to this point has been either Strings or integers. But what if we want to send data structures that are more complex and span across multiple lines?
Let's write a Scenario for this functionality—we want to verify whether various users exist or not:
Scenario: Existing user Verification
Given user is on Application landing page
Then we verify user "Shankar" with password "P@ssword123", phone "999" exists
Then we verify user "Ram" with password "P@ssword456", phone " 888" exists
Then we verify user "Sham" with password "P@ssword789", phone "666" existsThe problem with this approach of writing Feature files is that Feature files are not expressive enough and there is a lot of repetition.
We are going to add one more Scenario to the login.feature file, and we are going to use Data Table to send a large set of test data along a Step:
Scenario: Existing user Verification Given user is on Application landing page Then we verify following user exists | name | email | phone | | Shankar | [email protected] | 999 | | Ram | [email protected] | 888 | | Sham | [email protected] | 666 |
Here we have used Data Tables. Tables as arguments to Steps are handy for specifying larger datasets. Let's understand Data Tables in more detail:
@Then("^we verify following user exists$")
public void we_verify_following_user_exists(DataTable userDetails){
//Write the code to handle Data Table
List<List<String>> data = userdetails.raw();
System.out.println(data.get(1).get(1));
}In the preceding code sample, the Data Table has been converted into a List of String and can be handled very easily thereafter.
Data table transformation has been explained in detail in the Transforming Data Tables to parse test data recipe in Chapter 2, Creating Step Definitions.
Change the font size
Change margin width
Change background colour