Exemple #1
0
        public static AutomationElement GetAddInRibbonTabElement(AutomationElement excelElement, ExcelAppWrapper app)
        {
            const string TheAddInTabControlName = "The AddIn";

            var ribbonTabs = UIAUtility.FindElementByNameWithTimeout(excelElement, "Ribbon Tabs", AddinTestUtility.RibbonButtonsBecomeActivatedTimeout,
                                                                     TreeScope.Descendants);

            var deTab = UIAUtility.FindElementByNameWithTimeout(ribbonTabs, TheAddInTabControlName, TimeSpan.FromSeconds(5),
                                                                TreeScope.Descendants); //Note Descendants needed here only for excel 2007

            if (app.IsVersion2010OrAbove())
            {
                UIAUtility.SelectMenu(deTab);
            }
            else
            {
                UIAUtility.PressButton(deTab);
            }

            var lowerRibbon = UIAUtility.FindElementByNameWithTimeout(excelElement, "Lower Ribbon", AddinTestUtility.RibbonButtonsBecomeActivatedTimeout,
                                                                      TreeScope.Descendants);

            return(UIAUtility.FindElementByNameWithTimeout(lowerRibbon, TheAddInTabControlName, AddinTestUtility.RibbonButtonsBecomeActivatedTimeout,
                                                           TreeScope.Descendants)); //Note Descendants needed here only for excel 2007
        }
        public void InvokeButton(AddinRibbonButton button)
        {
            if ((button == AddinRibbonButton.Create && !_app.IsVersion2010OrAbove()) || //2007 create button does not support invoke pattern
                !WindowsUtility.WindowsVerSupportsModalInvokeWithoutHang())
            {
                //Special-cases which lead to blocking modal dialog when using InvokePattern - must instead use mouse click
                UIAUtility.FindElementByNameFilteredByControlTypeAndMouseClick(_addinRibbonCtl,
                                                                               _buttonNameLookup[button], ControlType.Button, ControlType.Custom, AddinTestUtility.RibbonMouseMoveToClickDelayAllowForTooltip,
                                                                               TreeScope.Descendants);
            }
            else
            {
                var el = UIAUtility.FindElementByControlTypeAndNameWithTimeout(_addinRibbonCtl, ControlType.Button, ControlType.Custom,
                                                                               _buttonNameLookup[button],
                                                                               AddinTestUtility.FindRibbonButtonsTimeout, TreeScope.Descendants);

                UIAUtility.WaitForElementEnabledWithTimeout(el, AddinTestUtility.RibbonButtonsBecomeActivatedTimeout);

                UIAUtility.PressButton(el);

                if (button == AddinRibbonButton.Logout)
                {
                    //Special case force ribbon refresh when logout button invoked
                    ForceRibbonRefresh();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Select datagrid row and ensure visible after select
        /// </summary>
        /// <param name="el"></param>
        /// <param name="gridValueName"></param>
        /// <param name="nameCol"></param>
        /// <exception cref="ApplicationException">Element does not support GridPattern</exception>
        /// <exception cref="ApplicationException">Specified row not found</exception>
        /// <returns>Selected row element</returns>
        public static AutomationElement SelectGridRow(AutomationElement el, string gridValueName, int nameCol)
        {
            //TODO: Improve current brittleness here when used with custom control SortedListView
            //Doesn't always find item depending on where it is in the list
            //Using a backward search for now since that works with the current [email protected] / DemoUrl data set

            object gridPatternObj;

            if (!el.TryGetCurrentPattern(GridPattern.Pattern, out gridPatternObj))
            {
                throw new ApplicationException("Specified element '" + UIAUtility.GetIdOrName(el) + "' does not support GridPattern");
            }

            var gridPattern = (GridPattern)gridPatternObj;

            AutomationElement matchRow = null;

            for (int i = gridPattern.Current.RowCount - 1; i >= 0; i--)
            {
                var elem = gridPattern.GetItem(i, nameCol);
                if (elem == null)
                {
                    elem = gridPattern.GetItem(i, nameCol);
                }
                if (elem != null)
                {
                    if (elem.Current.Name == gridValueName)
                    {
                        var tw = TreeWalker.ContentViewWalker;
                        matchRow = tw.GetParent(elem);
                        break;
                    }
                }
            }

            if (matchRow == null)
            {
                throw new ApplicationException("Did not find specified row '" + gridValueName + "'");
            }

            WaitForElementEnabledWithTimeout(matchRow, AddinTestUtility.DialogControlEventStateUpdateTimeout);

            //Select grid row
            object selectionPattern;

            if (!matchRow.TryGetCurrentPattern(SelectionItemPattern.Pattern, out selectionPattern))
            {
                throw new ApplicationException("Specified element '" + UIAUtility.GetIdOrName(matchRow) + "' does not support SelectionItemPattern");
            }
            ((SelectionItemPattern)selectionPattern).Select();

            return(matchRow);
        }
Exemple #4
0
        /// <summary>
        /// Get automationelement by name, filtered by controltype - mouse click if found
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="automationName">case-insensitive automation name</param>
        /// <param name="controlType"></param>
        /// <param name="controlType2"></param>
        /// <param name="findDelay"></param>
        /// <param name="mouseClickDelay"></param>
        /// <param name="treeScope"></param>
        /// <exception cref="ApplicationException">if matching element not found</exception>
        public static void FindElementByNameFilteredByControlTypeWithTimeoutAndMouseClick(AutomationElement parent, string automationName, ControlType controlType, ControlType controlType2, TimeSpan findDelay, TimeSpan mouseClickDelay, TreeScope treeScope)
        {
            var  sw = Stopwatch.StartNew();
            bool foundButIsDisabled   = false;
            bool foundButIsNotVisible = false;

            do
            {
                foreach (AutomationElement foundEl in parent.FindAll(treeScope, new PropertyCondition(AutomationElement.NameProperty,
                                                                                                      automationName, PropertyConditionFlags.IgnoreCase)))
                {
                    if ((ControlType)foundEl.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) == controlType ||
                        ((ControlType)foundEl.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) == controlType2))
                    {
                        if (!foundEl.Current.IsEnabled)
                        {
                            foundButIsDisabled = true;
                        }
                        else if (foundEl.Current.IsOffscreen)
                        {
                            foundButIsNotVisible = true;
                        }
                        else
                        {
                            UIAUtility.MouseClickInferPoint(foundEl, mouseClickDelay);

                            return;
                        }
                    }
                }

                Thread.Sleep(TimeSpan.FromMilliseconds(100)); //be cpu-friendly
            }while (sw.Elapsed < findDelay);

            if (foundButIsDisabled)
            {
                throw new ApplicationException("Specified element named '" + automationName + "' with controltype '" + controlType + "': IsEnabled=false");
            }

            if (foundButIsNotVisible)
            {
                throw new ApplicationException("Specified element named '" + automationName + "' with controltype '" + controlType + "': IsOffscreen=true");
            }

            throw new ApplicationException("Could not find element named '" + automationName + "' with controltype '" + controlType + "'");
        }
Exemple #5
0
        public static void FindModalDialogIfAnyAndClose(AutomationElement parent, TreeScope treeScope)
        {
            foreach (AutomationElement foundEl in parent.FindAll(treeScope, new PropertyCondition(AutomationElement.IsEnabledProperty, true)))
            {
                object windowPattern;
                if (foundEl.TryGetCurrentPattern(WindowPattern.Pattern, out windowPattern))
                {
                    if (((WindowPattern)windowPattern).Current.IsModal)
                    {
                        var closeIconCtl = foundEl.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty,
                                                                                                          "Close"));
                        if (closeIconCtl == null)
                        {
                            throw new ApplicationException("Modal dialog '" + foundEl.Current.Name + "' does not implement close icon having automation id 'Close'");
                        }

                        UIAUtility.PressButton(closeIconCtl);

                        //Done since there can be only one modal dialog
                        return;
                    }
                }
            }
        }