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 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; } }