top of page
back.jpg
crystgandhi

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

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page