1.
Follow the previous setup of cucumber
2. Then to perform data driven testing we will define variable in .feature file and mention variable
values.
3. To define variables in gherkin language we use <>.
4. Write the following code in feature file.
Feature: test login functionality
Scenario Outline: check login is
succecful with credentials
Given user is on login page
When user enters <username> and
<password>
And click on the login button
Then user is on home page
Examples:
|username|password|
|sumeera|xyz|
|standard_user|secret_sauce|
|xyz|abc|
5.
6. Write the following in stepdefinition
package stepdefinition;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public class Stepdefclass {
ChromeDriver driver=new ChromeDriver();
@Given("user is on login page")
public void userlogin() {
[Link]("[Link]
[Link]("loginpage");}
@When("^user enters (.*) and (.*)$")
public void enterpassword(String un, String pw) {
[Link]("loginpage");
[Link](un);
WebElement textBox = [Link]([Link]("//*[@id=\"user-
name\"]"));
[Link](un);
WebElement textBox1 =
[Link]([Link]("//*[@id=\"password\"]"));
[Link](pw);
}
@And("click on the login button")
public void click_on_the_login_button() {
//[Link]([Link]("btn btn-secondary-gray col-center
oauth-btn google-logo-btn")).click();
[Link]("click login");
[Link]([Link]("login-button")).click();
}
@Then("user is on home page")
public void user_is_on_home_page() {
[Link]("on home page");
}
7. As written in highlighted code we use regular expression to catch variables.
8. Run the feature file first it will run with wrong values and then with correct values. As
mentioned in feature file.