top of page
back.jpg

Write Testcase for Forgot Password

Updated: Feb 5

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;

public class ForgotPasswordTest {
	//private WebDriver driver;

	@Test
	public void testForgotPassword() throws InterruptedException {
		// Set up the WebDriver
		WebDriver driver = new ChromeDriver();
		WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); 
		// Navigate to the Forgot Password page
		driver.get("https://www.jootza.com/login");
		// Find the email input field and submit button
        WebElement forgotPasswordLink = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//p[@class='text-info font-15']")));
		forgotPasswordLink.click();
		WebElement emailInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login-username")));
		// Enter a valid email address
		emailInput.sendKeys("testuser@example.com");
		WebElement submitButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[type='submit']")));
		submitButton.click();
		WebElement confirmationMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='toast-message ng-star-inserted']")));
		System.out.println(confirmationMessage.getText());
		String message = "We will email you a password reset link if you provided a valid username or email. Please check your registered email.";
		Assert.assertTrue(confirmationMessage.isDisplayed(), message);
			// Close the browser after each test method
		if (driver != null) {
			driver.quit();
		}
	}

}

Invalid Email

package seleniumAdvanced;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;

public class InValidEmailForgotPassword {
	
	
	@Test
	public void invalidEmailForgotPword() {
		// Set up the WebDriver
		WebDriver driver = new ChromeDriver();
		WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); 
		// Navigate to the Forgot Password page
		driver.get("https://www.jootza.com/login");
		// Find the email input field and submit button
        WebElement forgotPasswordLink = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//p[@class='text-info font-15']")));
		forgotPasswordLink.click();
		WebElement emailInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login-username")));
		// Enter a valid email address
		emailInput.sendKeys("testuser@123.com");
		WebElement submitButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[type='submit']")));
		submitButton.click();
		WebElement confirmationMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='toast-message ng-star-inserted']")));
		System.out.println(confirmationMessage.getText());
		String message = "We will email you a password reset link if you provided a valid username or email. Please check your registered email.";
		Assert.assertTrue(confirmationMessage.isDisplayed(), message);
			// Close the browser after each test method
		if (driver != null) {
			driver.quit();
		}
	}

}


3 views0 comments

Recent Posts

See All

Test case for Valid Coupon Code

This test case checks whether a valid coupon code is successfully applied to a booking cart, the total is updated accordingly, and a success message is displayed. package com.seleniumExamples2024; pu

Keyboard shortcut keys for various operations

General Shortcuts: Ctrl + C: Copy Ctrl + X: Cut Ctrl + V: Paste Ctrl + Z: Undo Ctrl + Y: Redo Ctrl + A: Select All Ctrl + S: Save Ctrl + P: Print Ctrl + F: Find Windows Shortcuts: Windows Key: Open or

bottom of page