/// <summary>
        /// Programmatically expand or collapse a menu item.
        /// https://msdn.microsoft.com/en-us/library/system.windows.automation.expandcollapsepattern.collapse%28v=vs.90%29.aspx
        /// </summary>
        /// <param name="menuItem">
        /// The target menu item.
        /// </param>
        ///--------------------------------------------------------------------
        private void ExpandCollapseMenuItem(AutomationElement menuItem)
        {
            if (menuItem == null)
            {
                throw new ArgumentNullException(
                          "AutomationElement argument cannot be null.");
            }

            ExpandCollapsePattern expandCollapsePattern =
                GetExpandCollapsePattern(menuItem);

            if (expandCollapsePattern == null)
            {
                return;
            }

            if (expandCollapsePattern.Current.ExpandCollapseState ==
                ExpandCollapseState.LeafNode)
            {
                return;
            }

            try
            {
                if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Expanded)
                {
                    // Collapse the menu item.
                    expandCollapsePattern.Collapse();
                }
                else if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed ||
                         expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.PartiallyExpanded)
                {
                    // Expand the menu item.
                    expandCollapsePattern.Expand();
                }
            }
            // Control is not enabled
            catch (ElementNotEnabledException)
            {
                // TO DO: error handling.
            }
            // Control is unable to perform operation.
            catch (InvalidOperationException)
            {
                // TO DO: error handling.
            }
        }
Пример #2
0
        /// <summary>
        /// Get Selected comboBox
        /// </summary>
        /// <param name="comboBox">comboBox element in which you want to select an item from</param>
        /// <param name="item">name of the item you want to select</param>
        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();
        }
Пример #3
0
        public void ClickDropDown(AutomationElement ExpandCollapseItem, bool Expand = true)
        {
            Thread.Sleep(1000);
            ExpandCollapsePattern expandCollapsePattern = ExpandCollapseItem.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            if (expandCollapsePattern != null)
            {
                if (Expand)
                {
                    expandCollapsePattern.Expand();
                }
                else
                {
                    expandCollapsePattern.Collapse();
                }
            }
        }
Пример #4
0
        public void SelectItemByPosition(int item)
        {
            if (_UIAElement != null)
            {
                //Now we need to find the right one
                //int matchingIndex = -1;
                //AutomationElement itemToSelect = null;
                object basePattern;
                if (_UIAElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out basePattern))
                {
                    ExpandCollapsePattern expand = (BasePattern)basePattern as ExpandCollapsePattern;
                    if (expand != null)
                    {
                        if (expand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                        {
                            expand.Expand();

                            availableOptions = _UIAElement.FindAll(TreeScope.Subtree,
                                                                   new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

                            if (item < availableOptions.Count && availableOptions[item - 1] != null)
                            {
                                SelectionItemPattern selectPattern =
                                    (SelectionItemPattern)availableOptions[item - 1].GetCurrentPattern(SelectionItemPattern.Pattern);
                                try
                                {
                                    selectPattern.Select();
                                }
                                catch (Exception e)
                                {
                                    //There is a timeout exception on the filter data panel
                                    TestBase.Log("An exception was handled by PurpleDropDown Class: " + e.Message);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (PurpleElement.Current.IsEnabled)
                {
                    SelectItemByPosition(item);
                }
            }
        }
Пример #5
0
        public AutomationElement[] GetAllSubMenus(AutomationElement MenuElement)
        {
            AutomationElement[] aeAll = null;
            Int32                 Cnt = 0;
            AutomationElement     aeX = MenuElement;
            ExpandCollapsePattern ee  = (ExpandCollapsePattern)MenuElement.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            ee.Expand();
            {
                TreeWalker X = TreeWalker.RawViewWalker;
                aeX = X.GetFirstChild(MenuElement);
                aeX = X.GetFirstChild(aeX);
                while (aeX != null)
                {
                    try
                    {
                        Cnt++;
                        aeX = X.GetNextSibling(aeX);
                    }
                    catch
                    {
                        break;
                    }
                }
            }
            aeAll = new AutomationElement[Cnt + 1];
            Cnt   = 0;
            {
                TreeWalker X = TreeWalker.RawViewWalker;
                aeX = X.GetFirstChild(MenuElement);
                aeX = X.GetFirstChild(aeX);
                while (aeX != null)
                {
                    try
                    {
                        aeAll[Cnt++] = aeX;
                        aeX          = X.GetNextSibling(aeX);
                    }
                    catch
                    {
                        break;
                    }
                }
            }
            return(aeAll);
        }
        public void SelectItem(string name)
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)Element.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            pat.Expand();
            try {
                var item = Element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, name));

                if (item == null)
                {
                    throw new ElementNotAvailableException(name + " is not in the combobox");
                }
                ((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();
            } finally {
                pat.Collapse();
            }
        }
Пример #7
0
        //#######################################################################################################################################
        // Will do a Left mouse Click on the XenCenter element
        //#######################################################################################################################################
        public AutomationElement ClickOnXenCenterNode(AutomationElement XenCenterObj, string LogFilePath, int TerminateStatus)
        {
            Logger NewLogObj = new Logger();

            NewLogObj.WriteLogFile(LogFilePath, "ClickOnXenCenterNode", "info");
            NewLogObj.WriteLogFile(LogFilePath, "=============================", "info");

            AutomationElementIdentity GuiObj = new AutomationElementIdentity();

            try
            {
                // AutomationElement SearchObj=TypeInXenCenterSearchBox(XenCenterObj, TextToSelect, 1, LogFilePath);
                PropertyCondition TreeReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "treeView", 1, LogFilePath);
                AutomationElement ServerPane          = GuiObj.FindAutomationElement(XenCenterObj, TreeReturnCondition, TreeScope.Descendants, "Server Paniewe V", 0, LogFilePath);

                PropertyCondition     XenCenterParentCondition = GuiObj.SetPropertyCondition("NameProperty", "XenCenter", 1, LogFilePath);
                AutomationElement     XenCenterParentElement   = GuiObj.FindAutomationElement(ServerPane, XenCenterParentCondition, TreeScope.Descendants, "XenCenterParentElement", 0, LogFilePath);
                ExpandCollapsePattern expPattern = XenCenterParentElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
                Thread.Sleep(1000);
                if (string.Compare(expPattern.Current.ExpandCollapseState.ToString(), "Collapsed") == 0)
                {
                    expPattern.Expand();
                }
                TestAPI TestApiObj = new TestAPI();
                TestApiObj.ClickLeftBtnOnAutomationElement(XenCenterParentElement, 1, LogFilePath);
                return(XenCenterParentElement);
            }
            catch (Exception Ex)
            {
                NewLogObj.WriteLogFile(LogFilePath, "Exception at ClickOnXenCenterNode" + Ex.ToString(), "fail");
                if (TerminateStatus == 1)
                {
                    NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 1.", "info");
                    NewLogObj.WriteLogFile(LogFilePath, "***Exiting application from ClickOnXenCenterNode as main menunot found**", "fail");
                    FileOperations FileObj = new FileOperations();
                    FileObj.ExitTestEnvironment();
                    return(null);
                }
                else
                {
                    NewLogObj.WriteLogFile(LogFilePath, TerminateStatus + "is 0.", "info");
                    return(null);
                }
            }
        }
 private void signalChange(String name)
 {
     try
     {
         System.Windows.Automation.Condition textConditionOne = new PropertyCondition(AutomationElement.AutomationIdProperty, "TXcombo");
         AutomationElement     textOne      = testWindow.FindFirst(TreeScope.Descendants, textConditionOne);
         ExpandCollapsePattern valuetextOne = textOne.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
         valuetextOne.Expand();
         AutomationElement    listItem = textOne.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, name));
         AutomationPattern    automationPatternFromElement = GetSpecifiedPattern(listItem, "SelectionItemPatternIdentifiers.Pattern");
         SelectionItemPattern selectionItemPattern         = listItem.GetCurrentPattern(automationPatternFromElement) as SelectionItemPattern;
         selectionItemPattern.Select();
         valuetextOne.Collapse();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Couldn't change signal to " + name);
     }
 }
Пример #9
0
        public void ExpandCollapsePatternTest()
        {
            using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL intl.cpl"))
            {
                // Find a well-known combo box
                AutomationElement combo = host.Element.FindFirst(TreeScope.Subtree,
                                                                 new PropertyCondition(AutomationElement.AutomationIdProperty, "1021"));
                Assert.IsNotNull(combo);

                ExpandCollapsePattern expando = (ExpandCollapsePattern)combo.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                Assert.AreEqual(expando.Current.ExpandCollapseState, ExpandCollapseState.Collapsed);
                expando.Expand();
                System.Threading.Thread.Sleep(100 /* ms */);
                Assert.AreEqual(expando.Current.ExpandCollapseState, ExpandCollapseState.Expanded);
                expando.Collapse();
                System.Threading.Thread.Sleep(100 /* ms */);
                Assert.AreEqual(expando.Current.ExpandCollapseState, ExpandCollapseState.Collapsed);
            }
        }
Пример #10
0
        public static bool expandTreeItem(AutomationElement ae)
        {
            object temp;

            if (ae.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out temp))
            {
                try
                {
                    ExpandCollapsePattern pattern = temp as ExpandCollapsePattern;
                    pattern.Expand();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
            return(false);
        }
        //public static void SetSelectedComboBoxItem(this 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 System.Windows.Automation.PropertyCondition(AutomationElement.NameProperty, item));

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

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

        //    selectionItemPattern.Select();
        //}
        #endregion
        #region 2nd Way to select combobox item
        public static void SetSelectedComboBoxItem(this AutomationElement comboBoxElement, string item)
        {
            if (comboBoxElement == null)
            {
                throw new Exception("Combo Box not found");
            }

            //Get the all the list items in the ComboBox


            //Expand the combobox
            ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)comboBoxElement.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            expandPattern.Expand();
            expandPattern.Collapse();
            AutomationElementCollection comboboxItem = comboBoxElement.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
            int i = 0;

            //try to get patterns
            //foreach(AutomationElement cbcItem in comboboxItem)
            //{
            //    foreach (AutomationPattern ap in cbcItem.GetSupportedPatterns())
            //    {
            //        MessageBox.Show(ap.ProgrammaticName);

            //    }
            //}
            foreach (AutomationElement cbxItem in comboboxItem)
            {
                if (cbxItem.FindFirst(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition).Current.Name == item)
                {
                    break;
                }
                i++;
            }
            //Index to set in combo box
            AutomationElement itemToSelect = comboboxItem[i];

            //Finding the pattern which need to select
            SelectionItemPattern selectPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);

            selectPattern.Select();
        }
Пример #12
0
        public void SelectItem(string item)
        {
            if (_UIAElement != null)
            {
                //Now we need to find the right one
                int matchingIndex = -1;
                AutomationElement itemToSelect = null;

                object basePattern;
                if (_UIAElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out basePattern))
                {
                    ExpandCollapsePattern expand = (BasePattern)basePattern as ExpandCollapsePattern;
                    if (expand != null)
                    {
                        if (expand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                        {
                            expand.Expand();

                            availableOptions = _UIAElement.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
                            for (int x = 0; x < availableOptions.Count; x++)
                            {
                                if (item == availableOptions[x].Current.Name)
                                {
                                    itemToSelect = availableOptions[x];
                                }
                            }
                            if (itemToSelect != null)
                            {
                                SelectionItemPattern selectPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);
                                selectPattern.Select();
                            }
                        }
                    }
                }
            }
            else
            {
                if (PurpleElement.Current.IsEnabled)
                {
                    SelectItem(item);
                }
            }
        }
        /// <summary>
        /// Selects an item in the combo box by clicking on it.
        /// Only use this if SelectItem doesn't work!
        /// </summary
        /// <param name="name"></param>
        public void ClickItem(string name)
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)Element.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            pat.Expand();

            var item = Element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, name));

            if (item == null)
            {
                throw new ElementNotAvailableException(name + " is not in the combobox");
            }

            // On Win8, we need to move mouse onto the text, otherwise we cannot select the item
            AutomationElement innerText = item.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));

            Mouse.MoveTo(innerText.GetClickablePoint());
            Mouse.Click();
        }
Пример #14
0
        private void ShowHiddenElements(AutomationElement hiddenElem)
        {
            if (hiddenElem.Current.LocalizedControlType.ToLower() == ElementBase.TREE_ITEM)
            {
                Object tree;
                hiddenElem.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out tree);
                if (tree != null)
                {
                    ExpandCollapsePattern treeConvert = (ExpandCollapsePattern)tree;
                    if (treeConvert.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                    {
                        treeConvert.Expand();
                    }
                }
                hiddenElem.SetFocus();
            }
            else if (hiddenElem.Current.LocalizedControlType.ToLower() == ElementBase.TAB_ITEM)
            {
                Object tabSelection;
                hiddenElem.TryGetCurrentPattern(SelectionItemPattern.Pattern, out tabSelection);
                if (tabSelection != null)
                {
                    ((SelectionItemPattern)tabSelection).Select();
                }
            }
            else if (hiddenElem.Current.LocalizedControlType.ToLower() == ElementBase.COMBO_BOX)
            {
                //try
                //{
                //    ElementBase.Click(hiddenElem, ClickOptions.RightElement);
                //    ElementBase.Click(hiddenElem, ClickOptions.RightElement);
                //}
                //catch (Exception) { }

                Object combo_box_Pattern;
                hiddenElem.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out combo_box_Pattern);
                if (combo_box_Pattern != null)
                {
                    ((ExpandCollapsePattern)combo_box_Pattern).Expand();
                }
            }
        }
Пример #15
0
        public string GetSelectedItemName()
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)Element.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            pat.Expand();
            try {
                var items = Element.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "ListBoxItem"));

                foreach (AutomationElement item in items)
                {
                    if (((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Current.IsSelected)
                    {
                        return(item.Current.Name);
                    }
                }
                return(null);
            } finally {
                pat.Collapse();
            }
        }
Пример #16
0
        public static void executePattern(AutomationElement subject, AutomationPattern inPattern)
        {
            try
            {
                switch (inPattern.ProgrammaticName)
                {
                case "InvokePatternIdentifiers.Pattern":
                {
                    InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern);
                    invoke.Invoke();
                    break;
                }

                case "SelectionItemPatternIdentifiers.Pattern":
                {
                    SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern);
                    select.Select();
                    break;
                }

                case "TogglePatternIdentifiers.Pattern":
                {
                    TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern);
                    toggle.Toggle();
                    break;
                }

                case "ExpandCollapsePatternIdentifiers.Pattern":
                {
                    ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                    exColPat.Expand();
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                //ignore for now issue with infragistics elements not getting proper states
                //throw;
            }
        }
Пример #17
0
        public AutomationElement GetSubMenuByName(String SubMenuName, AutomationElement MainMenuElement)
        {
            if (MainMenuElement.Current.ControlType != ControlType.MenuItem)
            {
                return(null);
            }
            SubMenuName = SubMenuName.ToUpper();
            try
            {
                AutomationElement     aeElement = MainMenuElement;
                ExpandCollapsePattern ee        = (ExpandCollapsePattern)aeElement.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                ee.Expand();

                TreeWalker X = TreeWalker.RawViewWalker;
                aeElement = X.GetFirstChild(aeElement);
                aeElement = X.GetFirstChild(aeElement);
                while (aeElement != null)
                {
                    try
                    {
                        if (aeElement.Current.Name.ToString().ToUpper().IndexOf(SubMenuName) >= 0)
                        {
                            return(aeElement);
                        }
                        aeElement = X.GetNextSibling(aeElement);
                    }
                    catch
                    {
                        break;
                    }
                }

                return(null);
            }
            catch
            {
                return(null);
            }
        }
Пример #18
0
        private Dictionary <string, SelectionItemPattern> GetElements(AutomationElement element)
        {
            var elements = new Dictionary <string, SelectionItemPattern>();

            try
            {
                ExpandCollapsePattern expandCollapsePattern = element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern
                                                              ?? throw new ApplicationException($"Couldn't get ExpandCollapse Pattern for combo {element.Current.AutomationId}");
                expandCollapsePattern.Expand();
                if (expandCollapsePattern.Current.ExpandCollapseState != ExpandCollapseState.Expanded)
                {
                    throw new ApplicationException($"Couldn't expand {element.Current.AutomationId}");
                }

                var treeWalker = TreeWalker.ControlViewWalker;
                Console.WriteLine("Children:");
                var child = treeWalker.GetFirstChild(element);
                while (child != null)
                {
                    Console.WriteLine($"{child.Current.ControlType.LocalizedControlType} - [{child.Current.Name}]");
                    AutomationPattern automationPatternFromElement =
                        GetSpecifiedPattern(child, "SelectionItemPatternIdentifiers.Pattern")
                        ?? throw new ApplicationException($"Couldn't get AutomationPattern for list item.");
                    SelectionItemPattern selectionItemPattern =
                        child.GetCurrentPattern(automationPatternFromElement) as SelectionItemPattern
                        ?? throw new ApplicationException($"Couldn't get SelectionItemPattern.");
                    elements[child.Current.Name] = selectionItemPattern;

                    child = treeWalker.GetNextSibling(child);
                }
                expandCollapsePattern.Collapse();
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Couldn't find descendants for {element.Current.AutomationId}. Reason: {ex.Message}");
            }

            return(elements);
        }
Пример #19
0
        public void SelectItemByPosition(int item)
        {
            if (_UIAElement != null)
            {
                //Now we need to find the right one
                //int matchingIndex = -1;
                //AutomationElement itemToSelect = null;
                object basePattern;
                if (_UIAElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out basePattern))
                {
                    ExpandCollapsePattern expand = (BasePattern)basePattern as ExpandCollapsePattern;
                    if (expand != null)
                    {
                        if (expand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                        {
                            expand.Expand();

                            availableOptions = _UIAElement.FindAll(TreeScope.Subtree,
                                                                   new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

                            if (item < availableOptions.Count && availableOptions[item - 1] != null)
                            {
                                SelectionItemPattern selectPattern =
                                    (SelectionItemPattern)availableOptions[item - 1].GetCurrentPattern(SelectionItemPattern.Pattern);
                                selectPattern.Select();
                            }
                        }
                    }
                }
            }
            else
            {
                if (PurpleElement.Current.IsEnabled)
                {
                    SelectItemByPosition(item);
                }
            }
        }
Пример #20
0
        public AutomationElement VerifyIfAnElementExistUnderXenCenterTree(AutomationElement XenCenterObj, string ElementName, int TerminateStatus)
        {
            Logger NewLogObj   = new Logger();
            string LogFilePath = NewLogObj.GetLogFilePath();

            NewLogObj.WriteLogFile(LogFilePath, "VerifyIfAnElementExistUnderXenCenterTree", "info");
            NewLogObj.WriteLogFile(LogFilePath, "=============================", "info");
            NewLogObj.WriteLogFile(LogFilePath, "ElementName to be checked " + ElementName, "info");
            AutomationElementIdentity GuiObj = new AutomationElementIdentity();

            NewLogObj.WriteLogFile(LogFilePath, "Checking in Xencenter tree for element " + ElementName, "info");
            //Verify if pool is added from Xencenter tree, by checking if a object with that name exists
            //Xencenter treeview
            PropertyCondition TreeReturnCondition = GuiObj.SetPropertyCondition("AutomationIdProperty", "treeView", 1, LogFilePath);
            AutomationElement ServerPane          = GuiObj.FindAutomationElement(XenCenterObj, TreeReturnCondition, TreeScope.Descendants, "Server Paniewe V", 0, LogFilePath);

            PropertyCondition XenCenterParentCondition = GuiObj.SetPropertyCondition("NameProperty", "XenCenter", 1, LogFilePath);
            AutomationElement XenCenterParentElement   = GuiObj.FindAutomationElement(ServerPane, XenCenterParentCondition, TreeScope.Descendants, "XenCenterParentElement", 0, LogFilePath);


            ExpandCollapsePattern expPattern = XenCenterParentElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            expPattern.Expand();

            PropertyCondition AddedEleReturnCondition = GuiObj.SetPropertyCondition("NameProperty", ElementName, 1, LogFilePath);
            AutomationElement XenCenterAddedeElement  = GuiObj.FindAutomationElement(ServerPane, AddedEleReturnCondition, TreeScope.Descendants, "XenCenterParentElement", 0, LogFilePath);

            if (XenCenterAddedeElement != null)
            {
                NewLogObj.WriteLogFile(LogFilePath, ElementName + "Exist in Xencenter tree", "info");
                return(XenCenterAddedeElement);
            }
            else
            {
                NewLogObj.WriteLogFile(LogFilePath, ElementName + "does not exist in Xencenter tree", "info");
                return(null);
            }
        }
Пример #21
0
        public void ExpandCollapseTest()
        {
            AutomationElement parentElement, childElement;

            parentElement = treeView1Element.FindFirst(TreeScope.Children,
                                                       new PropertyCondition(AEIds.ControlTypeProperty,
                                                                             ControlType.TreeItem));
            ExpandCollapsePattern pattern = (ExpandCollapsePattern)parentElement.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern);

            ExpandCollapsePattern.ExpandCollapsePatternInformation current = pattern.Current;
            Assert.AreEqual(ExpandCollapseState.Collapsed, current.ExpandCollapseState, "ExpandCollapseState before Expand");
            pattern.Expand();
            Thread.Sleep(500);
            Assert.AreEqual(ExpandCollapseState.Expanded, current.ExpandCollapseState, "ExpandCollapseState after Expand");
            childElement = parentElement.FindFirst(TreeScope.Children,
                                                   new PropertyCondition(AEIds.ControlTypeProperty,
                                                                         ControlType.TreeItem));
            Assert.IsNotNull(childElement, "Should have a TreeItem after expand");

            pattern.Collapse();
            Thread.Sleep(500);
            Assert.AreEqual(ExpandCollapseState.Collapsed, current.ExpandCollapseState, "ExpandCollapseState after Collapse");
        }
        public void TraverseElement(AutomationElement window, int level)
        {
            //print info
            //LogDebug(window, level);

            if (window.Current.LocalizedControlType == ElementBase.TREE_ITEM)
            {
                Object tree;
                window.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out tree);
                if (tree != null)
                {
                    ExpandCollapsePattern treeConvert = (ExpandCollapsePattern)tree;
                    if (treeConvert.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                    {
                        treeConvert.Expand();
                    }
                }
            }
            else if (window.Current.LocalizedControlType == ElementBase.TAB_ITEM)
            {
                Object tabSelection;
                window.TryGetCurrentPattern(SelectionItemPattern.Pattern, out tabSelection);
                if (tabSelection != null)
                {
                    ((SelectionItemPattern)tabSelection).Select();
                }
            }

            //found item element in window
            AutomationElementCollection itemCollection = window.FindAll(TreeScope.Children, Condition.TrueCondition);

            //resurcive transfer all children
            foreach (AutomationElement item in itemCollection)
            {
                TraverseElement(item, level + 1);
            }
        }
        public override void DoExecute()
        {
            AutomationElement a = UiElement.AutomationElement;

            Console.WriteLine(a.Current.AutomationId);

            ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            expandCollapsePattern.Expand();
            var comboBoxEditItemCondition = new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "ListBoxItem");
            var listItems = a.FindAll(TreeScope.Subtree, comboBoxEditItemCondition);//It can only get one item in the list (the first one).
            var testItem  = listItems[listItems.Count - 1];

            foreach (AutomationElement item in listItems)
            {
                if (item.Current.Name == Control.text)
                {
                    testItem = item;
                    break;
                }
            }
            (testItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern).Select();
            expandCollapsePattern.Collapse();
        }
        public static void ActionSelectComboBoxItem(this AutomationElement comboBoxElement, int indexToSelect)
        {
            if (comboBoxElement == null)
            {
                throw new Exception("Combo Box not found");
            }

            //Get the all the list items in the ComboBox


            //Expand the combobox
            ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)comboBoxElement.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            expandPattern.Expand();
            AutomationElementCollection comboboxItem = comboBoxElement.FindAll(TreeScope.Children, new System.Windows.Automation.PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

            //Index to set in combo box
            AutomationElement itemToSelect = comboboxItem[indexToSelect];

            //Finding the pattern which need to select
            SelectionItemPattern selectPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);

            selectPattern.Select();
        }
Пример #25
0
        private AutomationElement _openitem(AutomationElement parentitem, string treepath, bool openlastone = false)
        {
            string[] path = treepath.Split(';');
            if (parentitem == null)
            {
                ControlSearcher.ThrowError(ErrorType.ObjectIsOutOfScreen, treepath);
                return(null);
            }
            AutomationElementCollection allitems           = this._items(parentitem);
            AutomationElement           treeNodeItemObject = null;

            if (path.Length != 0)
            {
                if (path[0].IndexOf('#') == 0)
                {
                    int treenodeindex = -1;
                    treenodeindex = Convert.ToInt16(path[0].Substring(1));
                    if (allitems.Count - 1 < treenodeindex)
                    {
                        ControlSearcher.ThrowError(ErrorType.OutRange, "Value: " + treenodeindex.ToString());
                    }
                    else
                    {
                        treeNodeItemObject = allitems[treenodeindex];
                    }
                }
                else
                {
                    for (int i = 0; i < allitems.Count; i++)
                    {
                        if (allitems[i].Current.Name.Trim() == path[0].Trim())
                        {
                            treeNodeItemObject = allitems[i];
                        }
                    }
                }
                if (treeNodeItemObject == null)
                {
                    ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist, "Value: " + path[0].ToString());
                }
                else
                {
                    if ((openlastone && path.Length == 1) || (path.Length > 1))
                    {
                        try
                        {
                            ExpandCollapsePattern mexpand = (ExpandCollapsePattern)treeNodeItemObject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                            mexpand.Expand();
                        }
                        catch
                        {
                            try
                            {
                                Point p = new Point((int)treeNodeItemObject.Current.BoundingRectangle.Left, (int)treeNodeItemObject.Current.BoundingRectangle.Top);
                                KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                            }
                            catch
                            {
                                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation, "Value: " + path[0].ToString());
                            }
                        }

                        if (path.Length > 1)
                        {
                            treepath = treepath.Substring(path[0].Length + 1);
                            return(_openitem(treeNodeItemObject, treepath, openlastone));
                        }
                        else
                        {
                            return(treeNodeItemObject);
                        }
                    }
                    else
                    {
                        return(treeNodeItemObject);
                    }
                }
            }
            return(null);
        }
Пример #26
0
        public void Expand()
        {
            ExpandCollapsePattern expandPattern = Ae.GetPattern <ExpandCollapsePattern>();

            expandPattern.Expand();
        }
Пример #27
0
 /// <summary>
 /// Expand the element
 /// </summary>
 /// <returns>The current helper</returns>
 public ExpandableElement Expand()
 {
     pattern.Expand();
     return(this);
 }
Пример #28
0
        /// <summary>
        /// Opens the context menu and returns the AutomationElement for the Menu.
        /// </summary>
        /// <param name="e">Automation element to right-click</param>
        public AutomationElement Open(bool throwIfNotOpened)
        {
            if (!isPopupMenu)
            {
                return(null);
            }
            isOpened = false;
            AutomationElement openMenu = null;

            // see if this is a SubMenuItem already
            object pattern;

            if (control.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern))
            {
                ExpandCollapsePattern expandCollapse = (ExpandCollapsePattern)pattern;
                expandCollapse.Expand();
                Thread.Sleep(250);

                for (int retries = 5; retries > 0; retries--)
                {
                    AutomationElement firstChild = control.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem));
                    if (firstChild != null)
                    {
                        openMenu = control;
                    }
                    else
                    {
                        Thread.Sleep(250);
                    }
                }
            }
            else
            {
                for (int outerRetries = 5; outerRetries > 0; outerRetries--)
                {
                    if (control == null)
                    {
                        // use the context menu key
                        Input.TapKey(Key.Apps);
                    }
                    else
                    {
                        Rect  bounds        = (Rect)control.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
                        Point clickLocation = new Point(bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2));

                        if (control.Current.ControlType == ControlType.Menu)
                        {
                            Input.MoveToAndLeftClick(clickLocation);
                        }
                        else
                        {
                            Input.MoveToAndRightClick(clickLocation);
                        }
                    }

                    if (!isPopupMenu)
                    {
                        openMenu = root.Element.FindChildMenuPopup(5);
                    }
                    else
                    {
                        openMenu = root.Element.FindChildContextMenu(5);
                    }
                }
            }

            if (openMenu == null)
            {
                if (throwIfNotOpened)
                {
                    string message = "Error: context menu is not appearing!";
                    throw new ApplicationException(message);
                }
            }

            return(openMenu);
        }
Пример #29
0
        private AutomationElement _getmenuitembypath(AutomationElement parentitem, string menupath, bool openlastone = false)
        {
            string[] path = menupath.Split(';');
            if (parentitem == null)
            {
                ControlSearcher.ThrowError(ErrorType.ObjectIsOutOfScreen, menupath);
                return(null);
            }
            AutomationElementCollection allItems       = this._getchilds(parentitem);
            AutomationElement           curentMenuItem = null;

            if (path.Length != 0)
            {
                if (path[0].IndexOf('#') == 0)
                {
                    int menuindex = -1;
                    menuindex = Convert.ToInt16(path[0].Substring(1));
                    if (allItems.Count - 1 < menuindex)
                    {
                        ControlSearcher.ThrowError(ErrorType.OutRange, "Value: " + menuindex.ToString());
                    }
                    else
                    {
                        curentMenuItem = allItems[menuindex];
                    }
                }
                else
                {
                    for (int i = 0; i < allItems.Count; i++)
                    {
                        if (allItems[i].Current.Name.Trim() == path[0].Trim())
                        {
                            curentMenuItem = allItems[i];
                        }
                    }
                }
                if (curentMenuItem == null)
                {
                    ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist, "Value: " + path[0].ToString());
                }
                else
                {
                    if ((openlastone && path.Length == 1) || (path.Length > 1))
                    {
                        try
                        {
                            ExpandCollapsePattern mexpand = (ExpandCollapsePattern)curentMenuItem.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                            mexpand.Expand();
                            Thread.Sleep(300);
                            mexpand.Expand();
                            Thread.Sleep(300);

                            if (mexpand.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
                            {
                                try
                                {
                                    Point p = new Point((int)curentMenuItem.Current.BoundingRectangle.Left, (int)curentMenuItem.Current.BoundingRectangle.Top);
                                    KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                                }
                                catch
                                {
                                    ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation, "Value: " + path[0].ToString());
                                }
                            }
                        }
                        catch
                        {
                            try
                            {
                                Point p = new Point((int)curentMenuItem.Current.BoundingRectangle.Left, (int)curentMenuItem.Current.BoundingRectangle.Top);
                                KeyInput.Click(KeyInput.MouseClickType.LClick, p);
                            }
                            catch
                            {
                                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation, "Value: " + path[0].ToString());
                            }
                        }

                        if (path.Length > 1)
                        {
                            menupath = menupath.Substring(path[0].Length + 1);
                            return(_getmenuitembypath(curentMenuItem, menupath, openlastone));
                        }
                        else
                        {
                            return(curentMenuItem);
                        }
                    }
                    else
                    {
                        return(curentMenuItem);
                    }
                }
            }
            return(null);
        }
Пример #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pattern"></param>
 public void Expand(ExpandCollapsePattern pattern)
 {
     pattern.Expand();
 }