A link would be send via email. When click on that link we can get the change psssword option. On that page asking for current password, change password, confirm password. at last we can change the password How to the forgot password link text ? how to verify this email is getting or not using selenium webdriver with java ?
If you want to test it end-2-end you can use a service like https://mailtrap.io/
Here you can use an API to retrieve the email and extract the link and open the link with Selenium.
Still I am wondering if you want to test this workflow end-2-end, maybe some integration tests would suffice.
- Checking emails sending gets triggered, not actual testing the email content.
- Email content could be checked by the class it-self with unit-test.
- Setting up a state that you can verify with the same link everytime
- Setup database state
- Follow known link
- Login with new password
You could try fetching the emails from the email server by establishing a connection to it.
You can use the JavaMail API for this. Here's a tutorial to fetch the emails from a GMail account https://www.tutorialspoint.com/javamail_api/javamail_api_checking_emails.htm
Here are few scenarios you can implement.Depending on the implementation you can add more or remove some.
Forgot password - check display (click on the forgot password link and check that you have title, email field, and submit button)
Forgot password - valid email (click on the forgot password link, enter a valid email and check the email is received and contains a the link for reset password)
Forgot password - valid email, change password, logout and login with changed password
Forgot password - invalid email format (validate the email field for invalid email like test@com gives an error)
Forgot password - valid email, use the reset password link and have a password for current password and a different password for confirm password
Forgot password - valid email, use the reset password link twice and see that second time you are using it will give you an error
Forgot password - valid email, use the reset password link and check display (that you have password/confirm password fields etc)
Forgot password - submit email that is not registered and check the result (it may be an error, or a general success message - this depends if how security is implemented)
Forgot password - valid email, use the reset password link and check validation on password/confirm password link (like weak/medium/strong password or minimum length - depending of what validations you have)
As email you can use a dispostable email server like Mailinator. Investigate what other options you would have since you might need the email for some other tests also.
Please note that some of the free email services have usually public inboxes, meaning anyone can see it, you can opt in for a payed plan with private inbox.