Assignment 2 -
✅ Prerequisites:
● Eclipse
● Java JDK
● Maven
● Cucumber Eclipse Plugin
● Selenium WebDriver
● Cucumber JUnit
✅ Project Structure:
src/test/java/
├── features/
│ └── [Link]
├── stepdefinitions/
│ └── [Link]
│ └── [Link]
├── testrunner/
│ └── [Link]
✅ Step-by-Step Implementation
1. [Link] Dependencies
<dependencies>
<!-- Selenium -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>selenium-java</artifactId>
<version>4.12.0</version>
</dependency>
<!-- Cucumber Java -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.14.0</version>
</dependency>
<!-- Cucumber JUnit -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.14.0</version>
<scope>test</scope>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
2. Feature File – [Link]
Feature: User Login
Scenario: Successful login with valid credentials
Given the user is on the login page
When the user enters valid username and password
And clicks the login button
Then the user should be redirected to the dashboard
3. Step Definitions – [Link]
package stepdefinitions;
import [Link].*;
import [Link].*;
import [Link];
public class LoginSteps {
WebDriver driver;
@Given("the user is on the login page")
public void the_user_is_on_the_login_page() {
[Link]("[Link]", "path/to/chromedriver");
driver = new ChromeDriver();
[Link]("[Link] // Replace with real login URL
}
@When("the user enters valid username and password")
public void the_user_enters_valid_credentials() {
[Link]([Link]("username")).sendKeys("testuser");
[Link]([Link]("password")).sendKeys("password123");
}
@When("clicks the login button")
public void clicks_the_login_button() {
[Link]([Link]("loginButton")).click();
}
@Then("the user should be redirected to the dashboard")
public void the_user_should_be_redirected_to_the_dashboard() {
String expectedUrl = "[Link]
boolean success = [Link]().equals(expectedUrl);
assert success : "User not redirected correctly.";
[Link]();
}
}
4. Hooks – [Link]
package stepdefinitions;
import [Link].*;
public class Hooks {
@Before
public void beforeScenario() {
[Link]("=== Script Start Execution ===");
}
@After
public void afterScenario() {
[Link]("=== Script End Execution ===");
}
}
5. Test Runner – [Link]
package testrunner;
import [Link];
import [Link];
import [Link];
@RunWith([Link])
@CucumberOptions(
features = "src/test/java/features",
glue = {"stepdefinitions"},
plugin = {"pretty", "html:target/cucumber-reports"},
monochrome = true
)
public class TestRunner {}
✅ How to Run:
1. Right-click [Link] → Run As → JUnit Test