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

What is Flaky test? Steps to resolve Test Flakiness

A flaky test An automated test in a software testing environment that may produce inconsistent results, sometimes passing and sometimes failing, even when applied to the same version of the software u

Retrieve data from a JSON file

To retrieve data from a JSON file using Java and Selenium, you can use a library like Gson or Jackson for handling JSON parsing. { "username": "Tester1", "password": "Test1234", "url": "https://demoqa

bottom of page