private bool VerifyAndAssignRoleToUser(SnowTicket ticket, bool needsVerifyRoleExists)
        {
            //Check if role exists already, if so return directly
            driver.FindElement(By.CssSelector("#nav-tab-SecurityUsers-UserGroups > div > a")).Click();
            Sleep(3);

            if (needsVerifyRoleExists)
            {
                if (!IsRoleAssigned(ticket))
                {
                    //User has No this role but exists exchange role, i.e: use request Assistant manager, but he already has mananger role.
                    if (bool.Parse(ConfigurationManager.AppSettings["EnableResolveRoleConflicts"]))
                    {
                        var rolesConflicted = RolesConflictsDict[ticket.RoleName].Split('|');
                        foreach (string roleToRemove in rolesConflicted)
                        {
                            SnowTicket exchangableRole = new SnowTicket("", "", roleToRemove, "", "");
                            if (IsRoleAssigned(exchangableRole))
                            {
                                RemoveRole(exchangableRole);
                            }
                        }
                    }
                    return(AssignNewRole(ticket));
                }
                else
                {
                    //User has this role
                    WriteLog("Role was assigned before");
                    return(true);
                }
            }
            //Assign role to new user
            return(AssignNewRole(ticket));
        }
 private static void LogTicketDetails(SnowTicket ticket)
 {
     Logger.WriteLine("--------------------------------------------");
     Logger.WriteLine(ticket.TicketNumber);
     Logger.WriteLine(ticket.TicketUrl);
     Logger.WriteLine(String.Join(",", ticket.Hub, ticket.RoleName, ticket.UserId));
     Logger.Flush();
 }
        private bool IsRoleAssigned(SnowTicket ticket)
        {
            var         rolesAssignedList = driver.FindElements(By.XPath("//*[@id='item-assigned-list']/div"));
            IWebElement roleToVerify      = null;

            foreach (IWebElement role in rolesAssignedList)
            {
                IWebElement tempAssignedRole = role.FindElement(By.TagName("span"));
                if (tempAssignedRole.Text == ticket.RoleName)
                {
                    roleToVerify = tempAssignedRole;
                    break;
                }
            }
            return(roleToVerify != null);
        }
        private bool UpdateUser(SnowTicket ticket)
        {
            bool isSuccess = false;

            UserStatus userStatus = GetCurrentUserStatus();

            isSuccess = ActivateUser(ticket, userStatus);

            if (!isSuccess)
            {
                return(false);
            }

            isSuccess = VerifyAndAssignRoleToUser(ticket, true);

            return(isSuccess);
        }
        private bool RemoveRole(SnowTicket ticket)
        {
            try
            {
                Actions builder = new Actions(driver);

                var         rolesList    = driver.FindElements(By.XPath("//*[@id='item-assigned-list']/div"));
                IWebElement roleToRemove = null;
                foreach (IWebElement role in rolesList)
                {
                    IWebElement tempRoleControl = role.FindElement(By.TagName("span"));
                    if (tempRoleControl.Text == ticket.RoleName)
                    {
                        roleToRemove = tempRoleControl;
                        break;
                    }
                }
                IWebElement unAssignedList = driver.FindElement(By.Id("item-unassigned-list"));

                builder.ClickAndHold(roleToRemove)
                .MoveToElement(unAssignedList)
                .Release(unAssignedList)
                .Build()
                .Perform();
                Sleep(1);

                driver.FindElement(By.Id("btn-header-Save-7117")).Click();
                Sleep(10);                //sometimes performance is not good

                WriteLog(ticket.RoleName + " : role has been removed due to conflicts with latest role.");

                //Error message pops up.
                if (driver.FindElement(By.Id("custom-modal-window")) != null)
                {
                    WriteLog("WARNING: possbile error occured when removing role");
                }
            }
            catch (Exception ex)
            {
            }

            return(true);
        }
        private bool AssignNewRole(SnowTicket ticket)
        {
            try
            {
                Actions builder = new Actions(driver);

                var         rolesList = driver.FindElements(By.XPath("//*[@id='item-unassigned-list']/div"));
                IWebElement roleToAdd = null;
                foreach (IWebElement role in rolesList)
                {
                    IWebElement tempRoleControl = role.FindElement(By.TagName("span"));
                    if (tempRoleControl.Text == ticket.RoleName)
                    {
                        roleToAdd = tempRoleControl;
                        break;
                    }
                }
                if (roleToAdd == null)
                {
                    WriteLog(roleToAdd.Text + " : this role already exists.");
                }

                IWebElement assignedList = driver.FindElement(By.Id("item-assigned-list"));

                builder.ClickAndHold(roleToAdd)
                .MoveToElement(assignedList)
                .Release(assignedList)
                .Build()
                .Perform();
                Sleep(1);

                driver.FindElement(By.Id("btn-header-Save-7117")).Click();
                Sleep(3);

                WriteLog(ticket.RoleName + " : has been added to user.");
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
        private bool ActivateUser(SnowTicket ticket, UserStatus userStatus)
        {
            try
            {
                WriteLog(ticket.UserId + " : user status was " + Enum.GetName(typeof(UserStatus), userStatus));

                IWebElement userDescTextBox = driver.FindElement(By.Id("Description-7065"));
                userDescTextBox.SendKeys(ticket.TicketNumber);

                if (userStatus == UserStatus.INACTIVE)
                {
                    IWebElement selectControl = driver.FindElement(By.CssSelector("#inner-content-wrapper > azur-webapp > azur-split-panel > div > azur-split-panel-section:nth-child(2) > div > azur-webapp-tabs > div > azur-users-tab > azur-one-to-one > div > div > azur-default-form > azur-form > div > div > div > form > azur-form-row:nth-child(2) > div > azur-form-column:nth-child(1) > div > azur-form-attribute:nth-child(3) > div > div > div > div > azur-form-field > div > azur-ref-field > div > div > div > azur-select-field > div > div"));
                    selectControl.Click();
                    Sleep(1);

                    Actions action = new Actions(driver);
                    action.SendKeys(Keys.ArrowUp).Build().Perform();

                    //Move 2 steps up to select ACTIVE status
                    if (userStatus == UserStatus.LOCKEDTEMPLY)
                    {
                        action.SendKeys(Keys.ArrowUp).Build().Perform();
                    }
                    action.SendKeys(Keys.Enter).Build().Perform();
                    Sleep(1);

                    WriteLog(ticket.UserId + " : user status is updated to ACTIVE.");
                }

                IWebElement saveUserButton = driver.FindElement(By.Id("btn-header-Save-7065"));
                saveUserButton.Click();

                Sleep(2);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool CreateNewUserInIRIS(SnowTicket ticket)
        {
            try
            {
                IWebElement newUserButton = driver.FindElement(By.Id("btn-header-New-7065"));
                newUserButton.Click();
                Sleep(1);

                IWebElement userIdTextBox = driver.FindElement(By.Id("Username-7065"));
                Sleep(1);
                userIdTextBox.SendKeys(ticket.UserId);

                IWebElement userEmailTextBox = driver.FindElement(By.Id("Email-7065"));
                Sleep(1);
                userEmailTextBox.SendKeys(ticket.UserId + "@iata.org");

                IWebElement userDescTextBox = driver.FindElement(By.Id("Description-7065"));
                Sleep(1);
                userDescTextBox.SendKeys(">" + ticket.TicketNumber);

                IWebElement saveUserButton = driver.FindElement(By.Id("btn-header-Save-7065"));
                saveUserButton.Click();

                WriteLog("User has been ADDED in IRIS.");
                Sleep(3);

                int retryTimes = int.Parse(ConfigurationManager.AppSettings["DismissModalDialgoRetryTimes"]);
                DismissModalDiaglosIfExists(retryTimes);

                //Assign role to new user
                VerifyAndAssignRoleToUser(ticket, false);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        private void CompleteUserRequestTask(SnowTicket ticket)
        {
            GoToUrlWithWait(ticket.TicketUrl, 2);

            IWebElement assignedToTextBox = driver.FindElement(By.Id("sys_display.sc_task.assigned_to"));

            Sleep(1);
            assignedToTextBox.Click();
            assignedToTextBox.SendKeys(ConfigurationManager.AppSettings["AdminUserEmail"] + Keys.Tab);

            SelectElement caseStatusSelect = new SelectElement(driver.FindElement(By.Id("sc_task.state")));

            Sleep(1);
            caseStatusSelect.SelectByText("Closed Complete");

            IWebElement saveButton = driver.FindElement(By.Id("sysverb_update_and_stay"));

            Sleep(1);
            saveButton.Click();
            Sleep(3);

            WriteLog(ticket.TicketNumber + " has been completed in SNOW.");
        }
Ejemplo n.º 10
0
        private void GoToIrisUserModule(SnowTicket ticket)
        {
            GoToUrlWithWait(AppDict[ticket.Hub], 3);

            IWebElement userNameInput = driver.FindElement(By.Id("txtUserName"));
            IWebElement passwordInput = driver.FindElement(By.Id("txtPassword"));

            userNameInput.SendKeys(ConfigurationManager.AppSettings["AdminUserName"]);
            passwordInput.SendKeys(ConfigurationManager.AppSettings["AdminUserPassword"]);

            IWebElement loginButton = driver.FindElement(By.Id("btnSubmit"));

            driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);
            loginButton.Click();
            Sleep(3);

            //Go to security -> user module
            IWebElement sideBarSecurityManagerment = driver.FindElement(By.Id("sidebar-bp-SecurityManagement"));

            sideBarSecurityManagerment.Click();
            IWebElement sideBarUsers = driver.FindElement(By.Id("sidebar-wa-SECURITYUSERSAPP"));

            sideBarUsers.Click();
        }
Ejemplo n.º 11
0
        public void ProcessIrisUserTickets(string UserRequestPageUrl)
        {
            try
            {
                while (true)
                {
                    string ticketNumber = string.Empty;
                    string ticketUrl    = string.Empty;

                    //Open tickets pool page
                    GoToUrlWithWait(UserRequestPageUrl, 5);

                    ticketUrl = FetchOneTicketUrl(out ticketNumber);

                    if (string.IsNullOrWhiteSpace(ticketUrl) || string.IsNullOrWhiteSpace(ticketNumber))
                    {
                        break;
                    }

                    //Open ticket page
                    GoToUrlWithWait(BaseURL + ticketUrl, 3);

                    string hub, roleName, searchUserUrl, userName;
                    GetUserRequestDetails(out hub, out roleName, out searchUserUrl, out userName);

                    string userID = GetUserID(searchUserUrl, userName);

                    if (!VerifyUserID(userID, userName))
                    {
                        WriteLog(string.Format("Found UserID '{0}' does NOT match with the given UserName '{1}'.", userID, userName));
                    }
                    //Log user's details
                    SnowTicket ticket = new SnowTicket(ticketNumber, hub, RoleMappingDict[roleName], userID, BaseURL + ticketUrl);

                    LogTicketDetails(ticket);

                    //Login to IRIS
                    GoToIrisUserModule(ticket);

                    //Search the user by userID in IRIS
                    string userNameValue = LoadUserDetails(userID);

                    bool _isSuccess = false;
                    if (String.IsNullOrWhiteSpace(userNameValue))
                    {
                        _isSuccess = CreateNewUserInIRIS(ticket);
                    }
                    else
                    {
                        _isSuccess = UpdateUser(ticket);
                    }

                    //Close SNOW case
                    if (_isSuccess)
                    {
                        CompleteUserRequestTask(ticket);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex.InnerException.Message);
                throw ex;
            }
            finally {
                //save user names and IDs in Dictionary to file on the disk.
                SaveUserCacheDictToXmlFile();
            }
        }