using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; namespace Prevu { public class ForgotPasswordPage : BasePage { By txtUsernameLocator = By.Id("username_id"); By lblSignupTextLocator = By.ClassName("signup-text"); By btnSendLocator = By.Id("btnSubmit"); By divValidationErrors = By.ClassName("validation-summary-errors"); By spanFieldValidationError = By.ClassName("field-validation-error"); By txtPasswordLocator = By.Id("Password"); By txtConfirmPasswordLocator = By.Id("ConfirmPassword"); WebDriver _driver; public ForgotPasswordPage(WebDriver driver) { _driver = driver; } public bool OpenForgotPassword() { _driver.OpenPage("Account/Login"); _driver.ClickLink("Forgot password?"); _driver.WaitElement(txtUsernameLocator); return _driver.GetElement(lblSignupTextLocator).Text == "Enter your email address"; } public bool InputEmail(string email, string error = "") { _driver.SendKeys(txtUsernameLocator, email); _driver.ClickElement(btnSendLocator); _driver.WaitAjax(); if (string.IsNullOrEmpty(error)) { _driver.WaitElement(lblSignupTextLocator); return _driver.GetElement(lblSignupTextLocator).Text == string.Format("An email was sent to {0} address - use the link in the email to access the reset password form.", email); } else { IWebElement validationErrors = _driver.GetElement(divValidationErrors, "ul", "li", error); if (validationErrors != null) { return true; } else { IWebElement fieldValidationError = _driver.GetElement(spanFieldValidationError, error); return fieldValidationError != null; } } } public bool InputEmail() { _driver.OpenPage("Account/Login"); _driver.ClickLink("Forgot password?"); _driver.WaitElement(txtUsernameLocator); return _driver.GetElement(lblSignupTextLocator).Text == "Enter your email address"; } public bool OpenResetPassword(string token, string message) { _driver.OpenPage(string.Format("Account/RestorePassword/?token={0}", token)); return _driver.GetElement(lblSignupTextLocator).Text == message; } public bool ResetPassword(string password) { _driver.SendKeys(txtPasswordLocator, password); _driver.SendKeys(txtConfirmPasswordLocator, password); _driver.ClickElement(btnSendLocator); return _driver.GetElement(lblSignupTextLocator).Text == "Password has been successfully changed."; } } }