Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Maps in Data Tables

Category: BDD Cucumber
Data Tables in Cucumber,  we pass Username & Password without Header, due to which the test was not much readable.

Scenario: Successful Login with Valid Credentials
        Given User is on Home Page
        When User Navigate to LogIn Page
        And User enters Credentials to LogIn
        | Username   | Password |
        | testuser_1 | Test@153 |
        Then Message displayed Login Successfully
----------------------------------------------------------------------------------
@When(""^User enters Credentials to LogIn$"")
        public void user_enters_testuser_and_Test(DataTable usercredentials) throws Throwable {

                //Write the code to handle Data Table
                List<Map> data = usercredentials.asMaps(String.class,String.class);
                driver.findElement(By.id(""log"")).sendKeys(data.get(0).get(""Username"")); 
                driver.findElement(By.id(""pwd"")).sendKeys(data.get(0).get(""Password""));
                driver.findElement(By.id(""login"")).click();
           }
=================================================================================
@When(""^User enters Credentials to LogIn$"")
        public void user_enters_testuser_and_Test(DataTable usercredentials) throws Throwable {

                //Write the code to handle Data Table
                for (Map data : usercredentials.asMaps(String.class, String.class)) {
                        driver.findElement(By.id(""log"")).sendKeys(data.get(""Username"")); 
                    driver.findElement(By.id(""pwd"")).sendKeys(data.get(""Password""));
                    driver.findElement(By.id(""login"")).click();
                        }

        }

Leave a Reply

Your email address will not be published. Required fields are marked *