Automate Ticket Booking in SpiceJet from Delhi to Bengaluru using Selenium and Cucumber.

Author: neptune | 08th-Aug-2023

In this article, we will guide you through the process of automating the ticket booking scenario on the SpiceJet website. We will use Cucumber and Selenium WebDriver for this automation project. By the end of this article, you will have a clear understanding of the steps involved in automating ticket booking on SpiceJet and be able to create an automation framework for similar scenarios.


Before we begin, make sure you have the following:

  1. Maven installed on your system.

  2. Eclipse or IntelliJ IDE set up.

  3. Basic knowledge of Java programming language.

Setting up the Project:

Follow the steps below to set up the project:

Step 1: Create a Maven Project

Create a new Maven project in Eclipse or IntelliJ IDE. This will serve as the base for our automation framework.
Check here to create a project.

Step 2: Add Dependencies

Open the pom.xml file and add the necessary dependencies for Cucumber, TestNG, and Selenium WebDriver. Make sure to include the appropriate versions for each dependency.
Check dependencies here.

<!-- Cucumber dependencies -->













<!-- Selenium WebDriver dependency -->






Make sure to save the pom.xml file to download the dependencies.

Step 3: Create Feature File

Create a new feature file named SpiceJetTicketBooking.feature. This file will contain the Gherkin syntax-based test scenarios.


Feature: Book Ticket

  I want to book a ticket in SpiceJet


  Scenario: Book Ticket from Delhi to Bengaluru

    Given I Open URL "" and launch driver

    When I search ticket from "Delhi" to "Bengaluru" Depart on "10-April-2021" return on "11-June-2021"

    Then I close driver

Step 4: Create Step Definitions

Create a new Java class named SpiceJetStepDef in the package TestAutomation.StepDef. This class will contain the step definitions for the scenarios defined in the feature file.

package TestAutomation.StepDef;

import java.util.List;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;





public class SpiceJetStepDef {

    public static WebDriver driver;

    @Given("^I Open URL \"([^\"]*)\" and launch driver$")

    public void i_Open_URL_and_launch_driver(String url) throws Throwable {

        // Set ChromeDriver path

        System.setProperty("", "C:\\chromedriver_win32\\chromedriver.exe");

        // Initialize ChromeDriver

        driver = new ChromeDriver();


        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        // Open the URL



    @When("^I search ticket from \"([^\"]*)\" to \"([^\"]*)\" Depart on \"([^\"]*)\" return on \"([^\"]*)\"$")

    public void i_search_ticket_from_to_Depart_on_return_on(String depcity, String arricity, String depdate,

            String returndate) throws Throwable {

        // Select round trip


        // Enter Depart city and arrival city


        WebElement departcity = driver.findElement(By.xpath("(//a[@value='DEL'])"));;


        WebElement arrivalcity = driver.findElement(By.xpath("(//a[@value='BLR'])[2]"));;

        // Select Depart date

        String dep_bookdate = depdate.split("-")[0];

        String dep_bookmonth = depdate.split("-")[1];

        String dep_bookyear = depdate.split("-")[2];

        String currentmonth = driver.findElement(By.xpath("(//span[@class='ui-datepicker-month'])[1]")).getText()


        String currentyear = driver.findElement(By.xpath("(//span[@class='ui-datepicker-year'])[1]")).getText()


        while (!currentmonth.equals(dep_bookmonth) || (!currentyear.equals(dep_bookyear))) {


            currentmonth = driver.findElement(By.xpath("(//span[@class='ui-datepicker-month'])[1]")).getText().trim();

            currentyear = driver.findElement(By.xpath("(//span[@class='ui-datepicker-year'])[1]")).getText().trim();


        List<WebElement> dates = driver.findElements(By.xpath("//a[@class='ui-state-default']"));

        for (WebElement e : dates) {

            if (e.getText().trim().equals(dep_bookdate)) {





        // Select Return date

        WebElement returndatepicker = driver.findElement(By.xpath("(//button[@class='ui-datepicker-trigger'])[2]"));;

        String return_bookdate = returndate.split("-")[0];

        String return_bookmonth = returndate.split("-")[1];

        String return_bookyear = returndate.split("-")[2];

        String return_currentmonth = driver.findElement(By.xpath("(//span[@class='ui-datepicker-month'])[2]"))


        String return_currentyear = driver.findElement(By.xpath("(//span[@class='ui-datepicker-year'])[2]")).getText()


        while (!return_currentmonth.equals(return_bookmonth) || (!return_currentyear.equals(return_bookyear))) {


            return_currentmonth = driver.findElement(By.xpath("(//span[@class='ui-datepicker-month'])[2]")).getText()


            return_currentyear = driver.findElement(By.xpath("(//span[@class='ui-datepicker-year'])[2]")).getText()



        List<WebElement> return_dates = driver.findElements(By.xpath("//a[@class='ui-state-default']"));

        for (WebElement e : return_dates) {

            if (e.getText().trim().equals(return_bookdate)) {





        // Click on Find Flights button




    @Then("^I close driver$")

    public void i_close_driver() {

        // Close the driver




Running the Test:

To run the test, right-click on the TestRunner class and select "Run as" > "JUnit Test". This will execute the Cucumber scenarios defined in the feature file.


In this article, we have automated the ticket booking scenario on the SpiceJet website using Cucumber and Selenium WebDriver. We have covered the steps involved in setting up the project, creating feature files, step definitions, and the test runner class. By following these steps, you can automate other scenarios and expand the automation framework according to your requirements. Automation projects like this are a great way to enhance your skills and gain hands-on experience in test automation.

Happy testing !!!


anonymous | July 25, 2023, 11:27 p.m.

Nice selenium WebDriver coding👍

anonymous | June 23, 2022, 10:32 p.m.

Really helpful 👍

anonymous | April 15, 2022, 3:01 p.m.

Add more details

anonymous | Feb. 18, 2022, 12:33 p.m.

Nice Content

anonymous | Sept. 8, 2021, 11:41 a.m.

Try to check locator for date

anonymous | Aug. 31, 2021, 11:48 a.m.

Not able to select date

Related Blogs
Selenium, Cucumber, JUnit, TestNG dependencies for Selenium project.
Author: neptune | 02nd-Apr-2023
#Selenium #Testing
We guide you how to update the pom.xml file for Selenium Maven project...

5 Selenium Project Ideas & for Beginners in Automation Testing
Author: neptune | 30th-Mar-2023
#Selenium #Testing #Projects
In this article, we will discuss 5 interesting Selenium project ideas for beginners in automation testing...

How to use wait commands in Selenium WebDriver in Java ?
Author: neptune | 22nd-Feb-2022
#Selenium #Testing #Java
We are going to explore different types of waits in Selenium WebDriver. Implicit wait, Explicit wait, and Fluent wait with examples...

Top 50+ Selenium Interviews Questions 2023 based on Years of Experience
Author: neptune | 02nd-Apr-2023
#Selenium #Testing #Interview
Every interview difficulty is based on how many years of experience you have in that field. For the Selenium Automation Tester I have divided the question on the number of years of experience...

Top 10 Selenium Interview Questions with answers (2021).
Author: neptune | 02nd-Apr-2023
#Selenium #Interview
In this article I will cover top 10 Selenium interview questions...

How to create Selenium Cucumber Project in Eclipse.
Author: neptune | 25th-May-2022
First, divide the process into the various steps to understand working in brief of a project. Steps in brief: We’ll start with initializing the browser driver and then log in to the web page...

How to create a Selenium, Cucumber Automation project in Eclipse ?
Author: neptune | 02nd-Apr-2023
#Selenium #Testing
Problem Statement : Let’s consider this particular project where we will try automating the process of booking a flight ticket. Let’s get started and see how it’s done using Selenium...

Challenges faced in automating Web Applications using Selenium
Author: neptune | 02nd-Oct-2022
#Selenium #Testing
List of Challenges faced by testers using Selenium 1. Popup and Alert Handling, 2. Dynamic element Handling 3. Restricted to only Desktop Browsers Testing...

20 TestNG Interview Questions
Author: neptune | 17th-Dec-2022
#Selenium #Interview
There is always more than one test or method in the class. If we do not prioritize these tests or methods, then the methods are selected alphabetically and executed while execution...

Getting started with Selenium WebDriver.
Author: neptune | 02nd-Apr-2023
#Selenium #Testing
In this blog I will give you an overview of Selenium WebDriver and Also discuss about advantages and disadvantages of Selenium WebDriver...

Why we use Robot Class in Automation Testing?
Author: neptune | 23rd-Aug-2022
Robot class is used to generate native system input events for the purpose of automation testing. It is used to perform mouse and keyboard events on windows applications or popups...

Top 10 Selenium Interview Questions.
Author: neptune | 02nd-Apr-2023
#Selenium #Interview
Locator is a command that tells Selenium IDE which GUI elements (like Text Box, Buttons, Check Boxes etc) we are going to use or perform some automation task...

How to send POST request using Rest Assured framework in Java ?
Author: neptune | 26th-Mar-2023
#Selenium #API
Rest Assured is a popular Java-based framework that is used for testing RESTful web services. It provides a simple and intuitive API for sending HTTP requests and validating the responses...

View More