예제 #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();
                }
            }
        }
        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
        }