Book Image

Cucumber Cookbook

By : Shankar Garg
Book Image

Cucumber Cookbook

By: Shankar Garg

Overview of this book

Table of Contents (13 chapters)
Cucumber Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Transforming Data Tables to parse the test data


In the previous chapter, we covered how Data Tables can be used to send large sets of data to a single Step. Now let's understand how to handle Data Tables in Step Definitions in this recipe.

How to do it…

  1. Let's assume we are writing Step Definitions for the following Scenario:

    Scenario: Existing user Verification
        Given user is displayed login screen
        Then we verify following user exists
          | Name    | Email           |
          | Shankar | [email protected] |
          | Ram     | [email protected]   |
          | Sham    | [email protected]  |
  2. Now run the Feature file, and copy paste the Cucumber Step Definitions suggestions in the LoginSteps.java class. These are the additional Steps in LoginSteps.java:

    @Then("^we verify following user exists$")
    public void we_verify_following_user_exists(DataTable arg1) throws Throwable {
        /* Write code here that turns the phrase above into 
        concrete actions
        For automatic transformation, change DataTable to...