Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views4 pages

Assignment 1

The document outlines the steps to create a Maven project for user registration testing using Selenium and Cucumber in Eclipse. It includes instructions for setting up dependencies, folder structure, creating a feature file, defining step definitions, and implementing a test runner. Finally, it provides guidance on running the test and capturing the final output, including screenshots and reports.

Uploaded by

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

Assignment 1

The document outlines the steps to create a Maven project for user registration testing using Selenium and Cucumber in Eclipse. It includes instructions for setting up dependencies, folder structure, creating a feature file, defining step definitions, and implementing a test runner. Finally, it provides guidance on running the test and capturing the final output, including screenshots and reports.

Uploaded by

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

Assignment 1:

Step 1: Create a Maven Project

1.​ Open Eclipse → File → New → Maven Project → com.registration​

2.​ Add dependencies in pom.xml:​

<dependencies>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.12.0</version>
</dependency>

<!-- Cucumber Java -->


<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.14.0</version>
</dependency>

<!-- Cucumber JUnit -->


<dependency>
<groupId>io.cucumber</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>

Step 2: Folder Structure


src/test/java
|-- features/
| └── registration.feature
|
|-- stepdefinitions/
| └── RegistrationSteps.java
|
|-- testrunner/
| └── TestRunner.java

Step 3: Create Feature File - registration.feature


Feature: User Registration

Scenario: Successful Registration


Given the user is on the registration page
When the user enters valid details
And submits the form
Then the user should be registered successfully

Step 4: Step Definitions - RegistrationSteps.java


package stepdefinitions;

import io.cucumber.java.en.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;

public class RegistrationSteps {


WebDriver driver;

@Given("the user is on the registration page")


public void the_user_is_on_the_registration_page() {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
driver = new ChromeDriver();
driver.get("https://example.com/register");
}

@When("the user enters valid details")


public void the_user_enters_valid_details() {
driver.findElement(By.id("username")).sendKeys("testuser");
driver.findElement(By.id("email")).sendKeys("[email protected]");
driver.findElement(By.id("password")).sendKeys("password123");
}

@When("submits the form")


public void submits_the_form() {
driver.findElement(By.id("submit")).click();
}

@Then("the user should be registered successfully")


public void the_user_should_be_registered_successfully() {
String message = driver.findElement(By.id("success")).getText();
assert message.contains("Registration successful");
driver.quit();
}
}

Step 5: Create Test Runner - TestRunner.java


package testrunner;

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

@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/java/features",
glue = {"stepdefinitions"},
plugin = {"pretty", "html:target/cucumber-reports"},
monochrome = true
)
public class TestRunner {}

Step 6: Run the Test

●​ Right-click TestRunner.java → Run As → JUnit Test​


✅ Final Output
●​ Include screenshots of:​

○​ Browser showing successful registration​

○​ Eclipse console output with test pass​

○​ HTML Report (target/cucumber-reports/index.html)​

You might also like