0% found this document useful (0 votes)
2 views6 pages

assign 1

The document outlines the structure of a Maven project for user registration using BDD with Cucumber and Selenium. It includes the project directory layout, the POM file configuration with dependencies, feature file scenarios for registration, step definitions for test execution, and the page object model for the registration page. The document provides a comprehensive overview of the components necessary for implementing automated tests for user registration functionality.

Uploaded by

crazyglases
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)
2 views6 pages

assign 1

The document outlines the structure of a Maven project for user registration using BDD with Cucumber and Selenium. It includes the project directory layout, the POM file configuration with dependencies, feature file scenarios for registration, step definitions for test execution, and the page object model for the registration page. The document provides a comprehensive overview of the components necessary for implementing automated tests for user registration functionality.

Uploaded by

crazyglases
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/ 6

1.

Maven Project Structure


user-registration-bdd/
├── src/
│ ├── main/
│ └── test/
│ ├── java/
│ │ ├── runners/
│ │ │ └── TestRunner.java
│ │ ├── stepdefinitions/
│ │ │ └── RegistrationSteps.java
│ │ └── pages/
│ │ └── RegistrationPage.java
│ └── resources/
│ └── features/
│ └── registration.feature
├── pom.xml
└── target/
2. pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.bdd</groupId>
<artifactId>user-registration-bdd</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>7.15.0</cucumber.version>
<selenium.version>4.15.0</selenium.version>
</properties>

<dependencies>
<!-- Cucumber -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<!-- Selenium -->


<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>

<!-- JUnit -->


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

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
3. Feature File (registration.feature)
Feature: User Registration
As a new user
I want to register on the website
So that I can access member-only features

Scenario: Successful registration with valid credentials


Given I am on the registration page
When I enter valid registration details:
| First Name | John |
| Last Name | Doe |
| Email | [email protected] |
| Password | Test@1234 |
| Confirm Password | Test@1234 |
And I click the register button
Then I should see a registration success message

Scenario: Registration with mismatched passwords


Given I am on the registration page
When I enter registration details with mismatched passwords:
| First Name | John |
| Last Name | Doe |
| Email | [email protected] |
| Password | Test@1234 |
| Confirm Password | Test@123 |
And I click the register button
Then I should see an error message about password mismatch
4. Step Definitions (RegistrationSteps.java)
package stepdefinitions;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.RegistrationPage;

public class RegistrationSteps {


private WebDriver driver;
private RegistrationPage registrationPage;

@Given("I am on the registration page")


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

@When("I enter valid registration details:")


public void i_enter_valid_registration_details(io.cucumber.datatable.DataTable
dataTable) {
var data = dataTable.asMap(String.class, String.class);
registrationPage.enterFirstName(data.get("First Name"));
registrationPage.enterLastName(data.get("Last Name"));
registrationPage.enterEmail(data.get("Email"));
registrationPage.enterPassword(data.get("Password"));
registrationPage.enterConfirmPassword(data.get("Confirm Password"));
}

@When("I enter registration details with mismatched passwords:")


public void
i_enter_registration_details_with_mismatched_passwords(io.cucumber.datatable.DataTa
ble dataTable) {
var data = dataTable.asMap(String.class, String.class);
registrationPage.enterFirstName(data.get("First Name"));
registrationPage.enterLastName(data.get("Last Name"));
registrationPage.enterEmail(data.get("Email"));
registrationPage.enterPassword(data.get("Password"));
registrationPage.enterConfirmPassword(data.get("Confirm Password"));
}

@When("I click the register button")


public void i_click_the_register_button() {
registrationPage.clickRegisterButton();
}

@Then("I should see a registration success message")


public void i_should_see_a_registration_success_message() {
Assert.assertTrue(registrationPage.isSuccessMessageDisplayed());
driver.quit();
}

@Then("I should see an error message about password mismatch")


public void i_should_see_an_error_message_about_password_mismatch() {
Assert.assertTrue(registrationPage.isPasswordMismatchErrorDisplayed());
driver.quit();
}
}
6. Page Object (RegistrationPage.java)
package pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class RegistrationPage {


private WebDriver driver;

@FindBy(id = "firstName")
private WebElement firstNameField;

@FindBy(id = "lastName")
private WebElement lastNameField;

@FindBy(id = "email")
private WebElement emailField;

@FindBy(id = "password")
private WebElement passwordField;

@FindBy(id = "confirmPassword")
private WebElement confirmPasswordField;

@FindBy(id = "registerButton")
private WebElement registerButton;

@FindBy(className = "success-message")
private WebElement successMessage;

@FindBy(className = "error-message")
private WebElement errorMessage;

public RegistrationPage(WebDriver driver) {


this.driver = driver;
PageFactory.initElements(driver, this);
}

public void enterFirstName(String firstName) {


firstNameField.sendKeys(firstName);
}

public void enterLastName(String lastName) {


lastNameField.sendKeys(lastName);
}

public void enterEmail(String email) {


emailField.sendKeys(email);
}

public void enterPassword(String password) {


passwordField.sendKeys(password);
}

public void enterConfirmPassword(String confirmPassword) {


confirmPasswordField.sendKeys(confirmPassword);
}

public void clickRegisterButton() {


registerButton.click();
}

public boolean isSuccessMessageDisplayed() {


return successMessage.isDisplayed();
}

public boolean isPasswordMismatchErrorDisplayed() {


return errorMessage.isDisplayed() &&
errorMessage.getText().contains("password mismatch");
}
}

You might also like