CucumberJVM: 04 - Data Driven Cucumber

 

Data Driven BDD

Then user enters username and password

    @Then("^user enters username and password$")
    public void user_enters_username_and_password() {
        driver.findElement(By.xpath("//input[@name='username']")).sendKeys("naveenk");
        driver.findElement(By.name("password")).sendKeys("test@123");
    }

 

Then user enters "naveenk" and "test@123"

 

//    @Then("^user enters \"(.*)\" and \"(.*)\"$")
    @Then("^user enters \"([^\"]*)\" and \"([^\"]*)\"$")
    public void user_enters_username_and_password(String username, String password) {
        driver.findElement(By.xpath("//input[@name='username']")).sendKeys(username);
        driver.findElement(By.name("password")).sendKeys(password);
    }

@WithExamples

 

Without Examples Keyword

Scenario: Free CRM Login Test Scenario

Given user is already on Login Page
When title of login page is Free CRM
Then user enters "naveenk" and "test@123"
Then user clicks on login button
And user is on the home page

Then close the browser

 

#with Examples Keyword

Scenario Outline: Free CRM Login Test Scenario

Given user is already on Login Page
When title of login page is Free CRM
#Then user enters "naveenk" and "test@123"
Then user enters "<username>" and "<password>"
Then user clicks on login button
And user is on the home page

Then close the browser

Examples:
    | username | password |
    | naveenk  | test@123 |
    |  tom     | test456  |