Content ITV PRO
This is Itvedant Content department
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 branchNameGit 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 Keyword Execution Class
4
Open login.feature.
Add Feature description:
Feature: Login Functionality
Create a new class named KeywordEngine.
This class will read keywords from Excel and execute corresponding methods.
Example:
public class KeywordEngine {
}Read Keywords from Excel
5
Use Apache POI to read keyword values row by row.
Example:
String keyword = sheet.getRow(i).getCell(1).getStringCellValue();Apply Conditional Mapping
6
Use if-else or switch statements to map keywords to methods.
Example:
if(keyword.equalsIgnoreCase("Click")) {
action.click(locator);
}
OR
switch(keyword) {
case "OpenBrowser":
action.openBrowser();
break;
case "Click":
action.click(locator);
break;
}Map EnterText Keyword
7
Connect the EnterText keyword with the corresponding Selenium method.
Example:
case "EnterText":
action.enterText(locator, value);
break;Map Validation Keyword
8
Connect validation keywords to assertion methods.
Example:
case "VerifyTitle":
action.verifyTitle(value);
break;Execute the Keyword Engine
9
Validate Execution
10
Run the KeywordEngine class.
Verify that keywords are executed sequentially from Excel.
Observe browser actions during execution.
Confirm that each keyword correctly triggers its mapped Selenium method
Task 3 : Execute Tests Using Keywords
Open the TravelTest Project
1
Launch Eclipse or IntelliJ IDEA.
Open the TravelTest automation project.
Prepare Keyword Excel File
2
Open the Keywords.xlsx file.
Verify all test steps and keywords are added properly.
Example:
Open the Keyword Engine Class
3
| TestCase | Keyword | Object | Value |
|---|---|---|---|
| LoginTest | OpenBrowser | Chrome | |
| LoginTest | Enter Text | Username | admin |
| LoginTest | Enter Text | Password | Passs123 |
| LoginTest | Click | LoginButton | |
| LoginTest | VerifyTitle | Dashboard |
Open the KeywordEngine class.
Ensure it reads keywords from Excel correctly.
Example:
String keyword = sheet.getRow(i).getCell(1).getStringCellValue();Initialize Keyword Actions
4
Create an object of the KeywordActions class.
Example:
Execute Keywords Sequentially
5
Map Keywords to Methods
6
Use loop statements to execute all keywords one by one.
Example:
KeywordActions action = new KeywordActions();for(int i=1; i<=rowCount; i++) {
}Execute methods based on keyword values.
Example:
Execute Browser Actions
7
Run the Keyword Engine
8
Run actions such as:
OpenBrowser
EnterText
Click
VerifyTitle
Observe browser execution during runtime.
if(keyword.equalsIgnoreCase("Click")) {
action.click(locator);
}Run As → Java Application
OR
Right-click the KeywordEngine class.
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.
Open the TravelTest Project
1
Launch Eclipse or IntelliJ IDEA.
Open the TravelTest automation project.
Task 4 : Improve Reusability
Identify Repeated Code
2
Review existing automation scripts.
Identify repeated Selenium actions such as:
Click
EnterText
OpenBrowser
VerifyTitle
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:
| Keyword | Action |
|---|---|
| Click | Click button |
| EnterText | Enter Data |
| VerifyTitle | Validate 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 branchNameBy Content ITV