What is Cucumber Framework?

  

Cucumber is one of the most popular tools used for Behavior Driven Development (BDD). It allows developers, testers, and business analysts to write test cases in a natural, human-readable language that bridges the gap between technical and non-technical stakeholders.


What is Cucumber ?

Cucumber is an open-source BDD testing tool written in Ruby, but it supports many languages like Java, JavaScript, Python, and others. It enables you to write executable specifications for software behavior using a plain text language called Gherkin.

These Gherkin scenarios are then mapped to step definitions, which are actual automation code written in a programming language like Java or Python.


Why Use Cucumber?

  • Encourages collaboration between developers, testers, and business users.

  • Helps in defining clear acceptance criteria.

  • Makes test cases more understandable to non-technical stakeholders.

  • Acts as documentation of the system’s behavior.

  • Supports automation and manual readability together.


Example of Cucumber in BDD

Gherkin Feature File - login.feature

Feature: Login Functionality

  Scenario: Successful login with valid credentials
    Given the user is on the login page
    When the user enters a valid username and password
    And clicks on the login button
    Then the user should be redirected to the homepage



Step Definition file - Java class

@Given("the user is on the login page")
public void user_on_login_page() {
    // Code to open login page
}

@When("the user enters a valid username and password")
public void enter_credentials() {
    // Code to enter username and password
}

@When("clicks on the login button")
public void click_login_button() {
    // Code to click login button
}

@Then("the user should be redirected to the homepage")
public void redirect_to_homepage() {
    // Code to verify homepage
}




Features of Cucumber

FeatureDescription
Gherkin LanguageUses plain English-like syntax (Given-When-Then) to write scenarios.
Supports Multiple LanguagesWorks with Java, Ruby, Python, JavaScript, etc.
Readable by Non-Technical UsersDesigned to be easily understood by business stakeholders.
Integration with Selenium and Other ToolsWorks well with automation tools like Selenium, Appium.
ReusabilityStep definitions can be reused across multiple scenarios.
TagsHelps in grouping and selectively running scenarios.
HooksAllows setting up @Before and @After actions for scenarios.
ReportsSupports various report formats like HTML, JSON, etc.
Parallel ExecutionAllows running scenarios or features in parallel for faster testing.
Live DocumentationFeature files serve as live documentation of the system.


Advantages of Cucumber

  • Readable and easy to write test scenarios.

  • Encourages collaboration among teams.

  • Facilitates automated acceptance testing.

  • Promotes test-first approach in Agile and BDD.


Disadvantages of Cucumber

  • May add overhead for small projects.

  • Requires learning curve for writing Gherkin properly.

  • May lead to duplicate steps if not managed well.

  • Execution is slower compared to unit test frameworks.

Maven Build Automation

  


What is Build Automation in Maven ?

Build Automation in Maven refers to the automatic handling of the build lifecycle—compiling code, running tests, packaging, installing, and deployingespecially when multiple projects depend on one another.


Maven and Project Dependencies

In many real-world applications, software is split into modules or multiple Maven projects, where one project (child) depends on another (parent or dependency).


For example:

Project A (Core Library)
Project B (Depends on A)


When you change and build Project AProject B should automatically be rebuilt using the updated version of A. Maven handles this automation.


How Maven Automates Builds for Dependent Projects

1. Using mvn install to Install Artifacts

  • When you run mvn install in Project A, Maven:

    • Compiles the source code.

    • Packages it (JAR/WAR).

    • Installs it into the local repository (~/.m2/repository).

  • Now, any project like Project B, which depends on A, can fetch this artifact from the local repository.



2. Declaring Dependencies in pom.xml

Project B’s pom.xml declares:


<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>project-a</artifactId>
    <version>1.0-SNAPSHOT</version>
  </dependency>
</dependencies>



Maven will now:

  • Automatically fetch and include Project A’s build.

  • Recompile Project B if Project A is updated and reinstalled.



Multi-Module Project Automation (Advanced)

If Projects A and B are part of a multi-module Maven project, Maven will:

  • Automatically build modules in the correct order based on dependencies.

  • Avoid needing manual builds/install for each module.


Parent pom.xml:

<modules>
  <module>project-a</module>
  <module>project-b</module>
</modules>


Maven will:

  • Build project-a first.

  • Then build project-b after project-a is available.




Benefits of Maven Build Automation for Dependencies


BenefitDescription
EfficiencyRebuilds only what's changed.
Dependency ManagementAutomatically pulls dependent artifacts.
ConsistencyEnsures consistent versioning across builds.
Local/Remote Repo UseBuilds can pull from local/remote repositories.
Tool IntegrationWorks with Jenkins, CI/CD, IDEs, etc.



Example Workflow

  • Modify code in Project A.
  • Run mvn install in Project A → Installs updated JAR in local repo.
  • Run mvn clean install in Project B → Maven automatically picks updated A.
  • All dependent builds are consistent and automated.