private string UserLogin(ProgressLogger logger, string userName, string userServerName, bool changeServerOnly = false) { try { string defaultSelectedServer; username = data.UserPortal.Users[userName].UserName; password = data.UserPortal.Users[userName].Password; IWebElement serverWebElement = driver.FindElement(selectServer); SelectElement selectObj = new SelectElement(serverWebElement); defaultSelectedServer = selectObj.SelectedOption.Text; Thread.Sleep(1000); if (!(userServerName.Equals(defaultSelectedServer))) { UserSetFunctions.SelectDropdown(serverWebElement, userServerName); } Thread.Sleep(1000); if (changeServerOnly) { return(null); } UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, userLoginName, 15), username); UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, userLoginPassword, 15), password); UserSetFunctions.Click(GenericUtils.WaitForElementPresence(driver, userLoginButton, 15)); Assert.Equal(driver.Title.ToLower(), apexWebTitle.ToLower()); logger.LogCheckPoint(string.Format(LogMessage.UserLoggedInSuccessfully, username)); Thread.Sleep(2000); return(username); } catch (Exception) { throw; } }
// This method is used to login using the credentials captured from UI after assigning the account public bool LogInUsingCredsAfterAssignAccount(ProgressLogger logger, string userName, string userPassword) { bool flag = false; try { UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, userLoginName, 15), userName); UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, userLoginPassword, 15), userPassword); UserSetFunctions.Click(GenericUtils.WaitForElementPresence(driver, userLoginButton, 15)); if (driver.Title.ToLower().Equals(apexWebTitle.ToLower())) { flag = true; } if (flag) { logger.LogCheckPoint(String.Format(LogMessage.VerifyLoginAfterAssignAccountPassed, userName)); Thread.Sleep(2000); LogOut(); } else { logger.LogCheckPoint(String.Format(LogMessage.VerifyLoginAfterAssignAccountFailed, userName)); } } catch (Exception) { throw; } return(flag); }
// This method is used to login using the credentials captured from UI after unassigning the account public bool LogInUsingCredsAfterUnassignAccount(ProgressLogger logger, string userName, string userPassword) { bool flag = false; try { UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, userLoginName, 15), userName); UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, userLoginPassword, 15), userPassword); UserSetFunctions.Click(GenericUtils.WaitForElementPresence(driver, userLoginButton, 15)); //When trying to login using credential after unassigining the account then page is showing blank //So in case we have used below condition to check login. //Once login failed error messges shows then use below comment code in if condition //LoginErrorMsg().Text.Equals(Const.LoginErrroMsg) if (driver.Title.ToLower().Equals(apexWebTitle.ToLower())) { flag = true; } if (flag) { logger.LogCheckPoint(String.Format(LogMessage.VerifyLoginAfterUnassignAccountPassed, userName)); } else { logger.LogCheckPoint(String.Format(LogMessage.VerifyLoginAfterUnassignAccountFailed, userName)); } } catch (Exception) { throw; } return(flag); }
//This method is used for User Login public void LogIn(ILog logger = null) { try { username = data.UserPortal.Users["User1"].UserName; password = data.UserPortal.Users["User1"].Password; string userUrl = data.UserPortal.PortalUrl; string userServerName = data.UserPortal.PortalServerUrl; driver.Navigate().GoToUrl(userUrl); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20); driver.Manage().Window.Size = new Size(1366, 768); IWebElement serverWebElement = driver.FindElement(selectServer); UserSetFunctions.SelectDropdown(serverWebElement, userServerName); UserSetFunctions.EnterText(driver.FindElement(userLoginName), username); UserSetFunctions.EnterText(driver.FindElement(userLoginPassword), password); UserSetFunctions.Click(driver.FindElement(userLoginButton)); Assert.Equal(driver.Title.ToLower(), "APEX Web".ToLower()); // logger.Info("User "+ username +" logged in successfully"); } catch (Exception e) { logger.Error("Login failed"); logger.Error(e.StackTrace); throw e; } }
//This method will login to admin portal public void AdminLogIn(ProgressLogger logger, string userName = Const.ADMIN1) { try { username = data.AdminPortal.Users[userName].UserName; password = data.AdminPortal.Users[userName].Password; string userUrl = data.AdminPortal.PortalUrl; string userServerName = data.AdminPortal.PortalServerUrl; driver.Navigate().GoToUrl(userUrl); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20); driver.Manage().Window.Size = new Size(1366, 768); UserSetFunctions.EnterText(AdminUserName(), username); UserSetFunctions.EnterText(AdminUserPassword(), password); UserSetFunctions.Click(AdminSignIn()); Assert.Equal(driver.Title.ToLower(), Const.AdminLoginTitle.ToLower()); logger.LogCheckPoint(String.Format(LogMessage.AdminLoginSuccessfullMsg, userName)); Thread.Sleep(2000); } catch (Exception) { throw; } }
// This method is used to register a new user public string RegisterNewUser(IWebDriver driver) { try { string randomString; string email; string randomUserName; string userUrl = data.UserPortal.PortalUrl; string userName = TestData.GetData("TC45_UserName"); string emailDomain = Const.EmailDomain; string password = TestData.GetData("TC45_Password"); string retypePassword = TestData.GetData("TC45_Password"); randomString = GenericUtils.RandomString(Const.RandomStringLength); email = randomString + emailDomain; randomUserName = userName + randomString; logger.LogCheckPoint(String.Format(LogMessage.UserSignUpStarted, randomUserName, email)); UserSetFunctions.Click(GenericUtils.WaitForElementPresence(driver, signUpLink, 15)); UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, signUpUserName, 15), randomUserName); UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, signUpEmail, 15), email); UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, signUpPassword, 15), password); UserSetFunctions.EnterText(GenericUtils.WaitForElementPresence(driver, signUpRetypePassword, 15), retypePassword); UserSetFunctions.Click(GenericUtils.WaitForElementPresence(driver, signUpButton, 15)); GenericUtils.WaitForElementPresence(driver, signUpSuccess, 15); logger.LogCheckPoint(String.Format(LogMessage.UserSignUpSuccess, randomUserName, email)); Thread.Sleep(2000); return(randomUserName); } catch (NoSuchElementException ex) { logger.TakeScreenshot(); logger.LogError(LogMessage.UserSignUpFailure, ex); throw; } catch (Exception e) { logger.TakeScreenshot(); logger.LogError(LogMessage.UserSignUpFailure, e); throw; } }