Write the Cucumber BDD Test for the registration form using Data Tables

  • Estimate Completion Time
    not found 30 minutes
  • Difficulty Level:

Create a feature file for the registration form using Data Tables in Cucumber to input multiple fields: name, email, password, and confirmation password. Implement step definitions to read data from the Data Table and interact with the web page.

Solution

Registration.feature
Feature: User Registration
  Scenario: Register a new user
    Given I am on the registration page
      When I register with the following details
      | Field                   |   Value            |
      | Name                    |   John Doe         |
      | Email                   |   john@gmail.com   |
      | Password                |   Pass1234         |
      | ConfirmPassword         |   Pass1234         |
     Then I should be registered successfully
CucumberEx4.java
package cucumber;

import java.util.List;
import java.util.Map;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

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

public class CucumberEx4{
	WebDriver driver = new ChromeDriver();




	@Given("I am on the registration page")
	public void i_am_on_the_registration_page() {
		driver.navigate().to("https://www.example.com/registration");
	}


	@When("I register with the following details")
	public void i_register_with_the_following_details(DataTable dataTable) {
		List> list = dataTable.asMaps(String.class, String.class);
		driver.findElement(By.name("name")).sendKeys(list.get(0).get("Name"));
		driver.findElement(By.name("email")).sendKeys(list.get(0).get("Email"));
		driver.findElement(By.name("password")).sendKeys(list.get(0).get("Password"));
		driver.findElement(By.name("confirmPassword")).sendKeys(list.get(0).get("ConfirmPassword"));
		driver.findElement(By.name("submit")).click();
	}



	@Then("I should be registered successfully")
	public void i_should_be_registered_successfully() {
		// assertion to confirm successful registration, e.g., by checking a success
		// message
	}
}
Cucumber Practice Exercises - QA Ads Banner

Proleed Academy

Proleed serves / offers professionally designed IT training courses
globally.

Copyright © 2023 - Proleed Academy | All Rights Reserved.