0% found this document useful (0 votes)
5 views3 pages

BDD Framework

This document provides a step-by-step guide to create a Maven project in Eclipse and add Cucumber dependencies. It includes instructions for installing the Cucumber Eclipse plugin, creating a feature file, and implementing step definitions and a test runner. Finally, it explains how to run the Cucumber tests and view the results in the console.

Uploaded by

ramkumarlaksh74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

BDD Framework

This document provides a step-by-step guide to create a Maven project in Eclipse and add Cucumber dependencies. It includes instructions for installing the Cucumber Eclipse plugin, creating a feature file, and implementing step definitions and a test runner. Finally, it explains how to run the Cucumber tests and view the results in the console.

Uploaded by

ramkumarlaksh74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Create a Maven Project in Eclipse

Open Eclipse and go to File > New > Other.


Search for Maven Project, select it, and click Next.
Check the box Create a simple project (skip archetype selection) and click Next.
Fill in the Group Id and Artifact Id and click Finish.

Add Cucumber Dependencies to the Maven Project


Once your Maven project is created, open the pom.xml file.
Add the following Cucumber dependencies under the <dependencies> section in the
pom.xml

<dependencies>
<!-- Cucumber Java Dependency -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.11.0</version>
</dependency>

<!-- Cucumber JUnit Dependency -->


<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.11.0</version>
</dependency>

<!-- Selenium WebDriver Dependency -->


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

<!-- JUnit Dependency -->


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>

Install Cucumber Eclipse Plugin (Optional but Recommended)


The Cucumber Eclipse plugin helps in writing feature files with proper syntax
highlighting and step definition linking.

Open Eclipse and go to Help > Eclipse Marketplace.


In the search bar, type Cucumber and press Enter.
Look for Cucumber Eclipse Plugin and click on Install.
Follow the instructions to install the plugin and restart Eclipse when prompted.

src
├── main
│ └── java
└── test
├── java
│ └── stepDefinitions
└── resources
└── features

Create a Feature File


In the features folder, create a new file and name it login.feature (you can name
it anything).
Write a sample feature scenario in login.feature:

Feature: User Login

Scenario: Successful login with valid credentials


Given User is on Login page
When User enters valid username and password
Then User should be redirected to the Dashboard

LoginSteps.java

import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;

public class LoginSteps {

@Given("User is on Login page")


public void user_is_on_login_page() {
// Code to navigate to login page
System.out.println("User is on Login page");
}

@When("User enters valid username and password")


public void user_enters_valid_username_and_password() {
// Code to enter username and password
System.out.println("User enters valid username and password");
}

@Then("User should be redirected to the Dashboard")


public void user_should_be_redirected_to_the_dashboard() {
// Code to validate redirection to dashboard
System.out.println("User is redirected to the Dashboard");
}
}

TestRunner.java

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = {"stepDefinitions"},
plugin = {"pretty", "html:target/cucumber-reports"},
monochrome = true
)
public class TestRunner {
}
Run Cucumber Tests
Right-click on the TestRunner class and select Run As > JUnit Test.
This will execute your Cucumber feature file, and you will see the test output in
the console.

target/cucumber-reports

You might also like