0% found this document useful (0 votes)
23 views2 pages

CUCUMBER With Variable

The document outlines the setup for data-driven testing using Cucumber with a focus on defining variables in a .feature file using Gherkin syntax. It includes a sample feature file for testing login functionality with examples of usernames and passwords, as well as corresponding step definitions in Java. The process involves running the feature file to test both incorrect and correct login credentials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

CUCUMBER With Variable

The document outlines the setup for data-driven testing using Cucumber with a focus on defining variables in a .feature file using Gherkin syntax. It includes a sample feature file for testing login functionality with examples of usernames and passwords, as well as corresponding step definitions in Java. The process involves running the feature file to test both incorrect and correct login credentials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like