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 }
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; } } } }