TravelTest BDD ImplementaCucumber

Business Scenario

Welcome to the QA Automation Team at TravelTest Pvt. Ltd.

The QA Manager has assigned you the task of implementing Behavior Driven Development (BDD) Automation using Cucumber for the TravelTest Web Application.

As part of this lab, you will configure Cucumber with Selenium WebDriver, create Feature Files using Gherkin Syntax, develop Step Definitions, and execute automated BDD Test Scenarios. You will automate major TravelTest Functionalities such as Login, Flight Search, and Booking Validation while improving Framework

Pre-Lab Preparation

  • Install Java, Maven, and Eclipse/IntelliJ

  • Verify Selenium WebDriver setup

  • Understand BDD and Cucumber basics

  • Learn Gherkin keywords (Given, When, Then)

  • Prepare project structure for feature files and step definitions

  • Add Cucumber dependencies in pom.xml

  • Verify browser and driver configuration

  • Ensure the TravelTest project builds and runs successfully

git pull origin branchName

Git Pull

Readability, Reusability, and Collaboration between Testers and Business Teams.

Task 1: Setup Cucumber

Open Eclipse or IntelliJ IDEA

1

  • Double-click Eclipse/IntelliJ icon.

  • Wait for IDE to open.

  • Select workspace and click Launch.

Create New Maven Project

2

  • Click File → New → Maven Project.

  • Check Create a simple project.

  • Click Next.

  • Enter:

    • Group Id: com.traveltest

    • Artifact Id: TravelTestBDD

  • Click Finish.

Open pom.xml

3

  • Expand the project folder.

  • Double-click on pom.xml.

  • Open it in editor mode.

 

Add Cucumber Java Dependency

4

<dependency>
   <groupId>io.cucumber</groupId>
   <artifactId>cucumber-java</artifactId>
   <version>7.14.0</version>
</dependency>

Inside <dependencies> tag add:

  • Below previous dependency add:

Add Cucumber TestNG Dependency

5

<dependency>
   <groupId>io.cucumber</groupId>
   <artifactId>cucumber-testng</artifactId>
   <version>7.14.0</version>
</dependency>

Define EnterText Keyword

6

  • Add Selenium dependency inside <dependencies>:

<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>4.18.1</version>
</dependency>

Save pom.xml

7

Update Maven Project

8

  • Press Ctrl + S to save the file.

  • Right-click project.

  • Select Maven → Update Project.

  • Click OK.

Verify Dependencies

9

  • Expand Maven Dependencies folder.

  • Check whether:

    • Cucumber libraries

    • Selenium libraries
      are added successfully.

Create Required Folders

10

Verify Cucumber Setup

11

  • Right-click src/test/resources → New → Folder → Create features.

  • Right-click src/test/java → New → Package → Create:

    • stepDefinitions

    • runner

  • Confirm project structure is created successfully.

  • Ensure no errors are displayed in the project.

Task 2 : Write Feature File

Open the TravelTestBDD Project

1

  • Launch Eclipse or IntelliJ IDEA.

  • Open the TravelTestBDD project.

Locate Features Folder

2

  • Expand src/test/resources.

  • Open the features folder.

Create New Feature File

3

  • Right-click on features.

  • Select New → File.

  • Enter file name: login.feature

  • Click Finish.

Write Feature Keyword

4

Create Scenario

5

  • Open login.feature.

  • Add Feature description:

Feature: Login Functionality

  • Add Scenario keyword below Feature:

Scenario: Valid Login

Add Given Step

6

Add When Step

7

Add Then Step

8

  • Define user action step:

When User enters valid username and password

  • Define application launch step:

Given User launches TravelTest application

  • Define expected result step:

  • Then User should login successfully

     

Save Feature File

9

Verify Feature File Syntax

10

  • Press Ctrl + S to save the file.

Complete Feature File Creation

11

  • Check that:

    • Keywords are highlighted properly

    • No syntax errors are displayed

    • File extension is .feature

  • Verify the feature file is ready for step definition mapping and execution.

Task 3 :  Map step definition

Open the TravelTestBDD Project

1

  • Launch Eclipse or IntelliJ IDEA.

  • Open the TravelTestBDD project.

Locate stepDefinitions Package

2

  • Expand src/test/java.

  • Open the stepDefinitions package.

  • Right-click stepDefinitions.

  • Select New → Class.

  • Enter class name: LoginSteps

  • Click Finish.

Create Step Definition Class

3

  • Add required imports in LoginSteps.java:

Import Cucumber Annotation Packages

4

import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
  • Map the Given step from feature file:

Create Given Step Method

5

@Given("User launches TravelTest application")
public void launchApplication() {
   System.out.println("Application Launched");
}
  • Map the When step from feature file:

Create When Step Method

6

Create Then Step Method

7

  • Map the Then step from feature file:

@When("User enters valid username and password")
public void enterCredentials() {
   System.out.println("Credentials Entered");
}
@Then("User should login successfully")
public void validateLogin() {
   System.out.println("Login Successful");
}

Save Step Definition File

8

Verify Step Mapping

9

  • Press Ctrl + S to save LoginSteps.java.

  • Ensure feature file steps exactly match annotation text.

  • Verify no syntax errors are shown.

 

Complete Step Definition Mapping

10

  • Confirm all feature file steps are successfully linked with Java methods.

Open the TravelTestBDD Project

1

  • Launch Eclipse or IntelliJ IDEA.

  • Open the TravelTestBDD project.

Task 4 : Execute BDD scenarios

Locate Runner Package

2

  • Expand src/test/java.

  • Open the runner package.

Create Runner Class

3

  • Right-click runner.

  • Select New → Class.

  • Enter class name: TestRunner

  • Click Finish.

Import Cucumber Packages

4

Configure Cucumber Options

5

  • Add required imports in TestRunner.java:

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
  • Add feature file and step definition paths:

@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions",
plugin = {"pretty"}
)

Extend Cucumber Runner Class

6

Save Runner File

7

Observe Test Execution

9

Execute BDD Scenario

8

  • Create runner class for execution:

public class TestRunner extends AbstractTestNGCucumberTests {
}
  • Press Ctrl + S to save TestRunner.java.

  • Right-click TestRunner.java.

  • Select Run As → TestNG Test.

  • Browser execution starts if Selenium code is added.

  • Feature file steps execute one by one.

Verify Test Execution

9

  • Check whether all keywords execute successfully.

  • Verify application behavior for each test step.

Validate Results

10

  • Confirm expected outputs are displayed.

  • Verify assertions and validations pass successfully.

Check Execution Report

11

  • Open the test-output folder.

  • Review execution status and results in the TestNG report.

Update Keywords When Required

12

  • Add new keywords or test steps in Excel.

  • Re-run the framework without changing the core automation code.

Create Reusable Keyword Methods

3

  • Open the KeywordActions class.

  • Move common Selenium actions into reusable methods.

Example:

public void click(By locator) {

   driver.findElement(locator).click();

}

Create Reusable EnterText Method

4

  • Create a common method for text input actions.

Example:

public void enterText(By locator, String value) {
   driver.findElement(locator).sendKeys(value);
}

Centralize Browser Initialization

5

  • Create a reusable browser setup method.

Example:

 

 

public void openBrowser() {

   driver = new ChromeDriver();

}

Store Keywords in Excel

6

  • Open Keywords.xlsx.

  • Maintain reusable keywords instead of hardcoded test steps.

Example:

KeywordAction
ClickClick button
EnterTextEnter Data
VerifyTitleValidate page

Reuse Methods Across Test Cases

7

  • Call the same reusable methods for multiple test scenarios.

  • Avoid writing duplicate Selenium code.

Create Generic Validation Methods

8

  • Create reusable assertion methods.

Example:

 

public void verifyTitle(String expectedTitle) {

   Assert.assertEquals(driver.getTitle(), expectedTitle);

}

Execute Multiple Test Cases

9

  • Call the same reusable methods for multiple test scenarios.

  • Avoid writing duplicate Selenium code.

Validate Framework Reusability

10

  • Add new test cases in Excel without modifying automation code.

  • Confirm the framework handles new scenarios using existing reusable methods.

Maintain Framework Structure

11

  • Organize:

    • Keywords

    • Methods

    • Test data

    • Utility classes

  • Ensure the framework remains clean and maintainable.

 

Good Job!!

You have successfully completed your lab on TravelTest Keyword Driven Framework (KDF), where you learned how to define Reusable Keywords, map them to Selenium Methods, and execute Test Cases using Keyword-Driven Logic.

You also understood how the Keyword Driven Framework improves Reusability, Maintainability, reduces Code Duplication, and simplifies Automation Test Management.

Checkpoint

   Git Push

Next-Lab Preparation

git push origin branchName
  • Setup Cucumber
  • Write feature files
  • Map step definitions
  • Execute BDD scenarios