Skip to main content

Maps in Data Tables Cucumber

We can use Maps along with Data Table. Consider below example where you have to check whether user is valid or invalid based on its user information.

Feature File

  Scenario: Verify Login with multiple users
    When I Logged in with users
      | UserName                    | Password |
      | | test1234 |
      | mahuja                      |   234567 |
      | ssharma                     |   975454 |

Step Definition

@When("I Logged in with users")
public void i_Logged_in_with_users(DataTable dataTable) 
    for (Map<String, String> data : dataTable.asMaps())
        WebElement userName = driver.findElement(By.cssSelector("input[id='email']"));
        WebElement password = driver.findElement(By.cssSelector("input[id='passwd']"));

            if(driver.findElement(By.xpath("//h1[text()='My account']")).isDisplayed())
                System.out.println(data.get("UserName")+" is valid User");
       catch(Exception e)
           System.out.println(data.get("UserName")+" is invalid User");

In above example, If the user is valid "My Account" page will be displayed and User is valid will displayed otherwise invalid user will display. 

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.