Exemplo n.º 1
0
        public void Select(string item)
        {
            this.PrepareForReplay();
            int itemindex = -1;
            AutomationElementCollection alllabitem     = this._childs;
            SelectionItemPattern        labitempattern = null;

            if (item.IndexOf('#') == 0)
            {
                itemindex = Convert.ToInt16(item.Substring(1));
                if (alllabitem.Count - 1 < itemindex)
                {
                    ControlSearcher.ThrowError(ErrorType.OutRange);
                }
                else
                {
                    labitempattern = (SelectionItemPattern)alllabitem[itemindex].GetCurrentPattern(SelectionItemPattern.Pattern);
                    labitempattern.Select();
                    return;
                }
            }
            else
            {
                for (int i = 0; i < alllabitem.Count; i++)
                {
                    if (alllabitem[i].Current.Name.Trim() == item)
                    {
                        labitempattern = (SelectionItemPattern)alllabitem[i].GetCurrentPattern(SelectionItemPattern.Pattern);
                        labitempattern.Select();
                        return;
                    }
                }
            }
            ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist);
        }
        private static bool SelectComboboxItem(AutomationElement comboBox, string item)
        {
            if (comboBox == null)
            {
                return(false);
            }
            // Get the list box within the combobox
            AutomationElement listBox = comboBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List));

            if (listBox == null)
            {
                return(false);
            }
            // Search for item within the listbox
            AutomationElement listItem = listBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, item));

            if (listItem == null)
            {
                return(false);
            }
            // Check if listbox item has SelectionItemPattern
            object objPattern;

            if (true == listItem.TryGetCurrentPattern(SelectionItemPatternIdentifiers.Pattern, out objPattern))
            {
                SelectionItemPattern selectionItemPattern = objPattern as SelectionItemPattern;
                selectionItemPattern.Select(); // Invoke Selection
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public static void SetSelectedComboBoxItem(AutomationElement
                                                   comboBox, string item)
        {
            AutomationPattern automationPatternFromElement =
                GetSpecifiedPattern(comboBox,
                                    "ExpandCollapsePatternIdentifiers.Pattern");

            ExpandCollapsePattern expandCollapsePattern =
                comboBox.GetCurrentPattern(automationPatternFromElement) as
                ExpandCollapsePattern;

            expandCollapsePattern.Expand();
            expandCollapsePattern.Collapse();

            AutomationElement listItem =
                comboBox.FindFirst(TreeScope.Subtree, new
                                   PropertyCondition(AutomationElement.NameProperty, item));

            automationPatternFromElement = GetSpecifiedPattern(listItem,
                                                               "SelectionItemPatternIdentifiers.Pattern");

            SelectionItemPattern selectionItemPattern =
                listItem.GetCurrentPattern(automationPatternFromElement) as
                SelectionItemPattern;

            selectionItemPattern.Select();
        }
Exemplo n.º 4
0
        private void SetSelection(string option)
        {
            if ((comboBoxElement != null) &&
                (comboBoxElement.Current.IsEnabled))
            {
                AutomationElement sel = null;

                ExpandCollapsePattern expandPattern
                    = (ExpandCollapsePattern)comboBoxElement
                      .GetCurrentPattern(
                          ExpandCollapsePattern.Pattern);

                expandPattern.Expand();

                CacheRequest cacheRequest = new CacheRequest();
                cacheRequest.Add(AutomationElement.NameProperty);
                cacheRequest.TreeScope = TreeScope.Element
                                         | TreeScope.Children;

                AutomationElement comboboxItems
                    = comboBoxElement.GetUpdatedCache(
                          cacheRequest);

                foreach (AutomationElement item
                         in comboboxItems.CachedChildren)
                {
                    if (item.Current.Name == "")
                    {
                        CacheRequest cacheRequest2 = new CacheRequest();
                        cacheRequest2.Add(AutomationElement.NameProperty);
                        cacheRequest2.TreeScope = TreeScope.Element
                                                  | TreeScope.Children;

                        AutomationElement comboboxItems2
                            = item.GetUpdatedCache(cacheRequest);

                        foreach (AutomationElement item2
                                 in comboboxItems2.CachedChildren)
                        {
                            if (item2.Current.Name == option)
                            {
                                sel = item2;
                            }
                        }
                    }
                }

                if (sel != null)
                {
                    SelectionItemPattern select =
                        (SelectionItemPattern)sel.GetCurrentPattern(
                            SelectionItemPattern.Pattern);

                    select.Select();
                }
                expandPattern.Collapse();
            }
            SetForegroundWindow(this.Handle);
        }
        // RopModifyPermissions RopGetPermissionsTable
        public void ModifyFolderPermissions()
        {
            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = oApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder   = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName = folder.Parent.Name;

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Get Folder Tab and select it
            Condition            cd_RibbonTabs      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Folder"));
            AutomationElement    item_RibbonTabs    = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300);
            SelectionItemPattern Pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern);

            Pattern_RibbonTabs.Select();

            // Get "Folder Permissions" and select it
            Condition         cd_FolderPermissions           = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Folder Permissions"));
            AutomationElement item_FolderPermissions         = Utilities.WaitForElement(window_outlook, cd_FolderPermissions, TreeScope.Descendants, 10);
            InvokePattern     clickPattern_FolderPermissions = (InvokePattern)item_FolderPermissions.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPermissions.Invoke();

            // Get "Inbox Properties" window
            var condition_permission = new PropertyCondition(AutomationElement.NameProperty, "Inbox Properties");
            var window_FolderProp    = Utilities.WaitForElement(window_outlook, condition_permission, TreeScope.Children, 10);

            // Get and select "Create items"
            Condition         cd_write      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox), new PropertyCondition(AutomationElement.NameProperty, "Edit all"));
            AutomationElement item_write    = Utilities.WaitForElement(window_FolderProp, cd_write, TreeScope.Descendants, 10);
            TogglePattern     Pattern_write = (TogglePattern)item_write.GetCurrentPattern(TogglePattern.Pattern);

            Pattern_write.Toggle();

            // Click OK in Microsoft Outlook dialog box
            var           condition_Dailog      = new PropertyCondition(AutomationElement.NameProperty, "Microsoft Outlook");
            var           window_Dailog         = Utilities.WaitForElement(window_FolderProp, condition_Dailog, TreeScope.Children, 10);
            var           condition_DailogOK    = new PropertyCondition(AutomationElement.AutomationIdProperty, "6");
            var           item_DailogOK         = Utilities.WaitForElement(window_Dailog, condition_DailogOK, TreeScope.Children, 10);
            InvokePattern clickPattern_DailogOK = (InvokePattern)item_DailogOK.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_DailogOK.Invoke();

            // Click OK in "Inbox Properties" window
            var           condition_FolderPropOK        = new PropertyCondition(AutomationElement.AutomationIdProperty, "1");
            var           item_FolderPropertyOK         = Utilities.WaitForElement(window_FolderProp, condition_FolderPropOK, TreeScope.Children, 10);
            InvokePattern clickPattern_FolderPropertyOK = (InvokePattern)item_FolderPropertyOK.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPropertyOK.Invoke();

            bool result = MessageParser.ParseMessage();

            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
Exemplo n.º 6
0
        public static bool selectTreeItem(AutomationElement ae)
        {
            object temp;

            if (ae.TryGetCurrentPattern(SelectionItemPattern.Pattern, out temp))
            {
                SelectionItemPattern pattern = temp as SelectionItemPattern;
                pattern.Select();
                return(true);
            }
            return(false);
        }