public void PushPopTest() { CacheRequest defaultCR = CacheRequest.Current; CacheRequest target = new CacheRequest(); target.TreeScope = TreeScope.Children; target.Push(); CacheRequest target2 = new CacheRequest(); target2.TreeScope = TreeScope.Subtree; target2.Push(); // Try to change target2 - this should fail try { target2.TreeScope = TreeScope.Descendants; Assert.Fail("exception expected"); } catch (System.InvalidOperationException) { } target2.Pop(); target.Pop(); Assert.AreEqual(CacheRequest.Current, defaultCR); }
public void AutomationElementModeTest() { CacheRequest target = new CacheRequest(); target.AutomationElementMode = AutomationElementMode.Full; AutomationElementMode actual = target.AutomationElementMode; Assert.AreEqual(AutomationElementMode.Full, actual); }
public void GridPatternCachedTest() { CacheRequest req = new CacheRequest(); req.Add(GridItemPattern.Pattern); req.Add(GridPattern.Pattern); req.Add(GridPattern.RowCountProperty); req.Add(GridPattern.ColumnCountProperty); req.Add(GridItemPattern.RowProperty); req.Add(GridItemPattern.ColumnProperty); req.Add(GridItemPattern.ContainingGridProperty); using (req.Activate()) { AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView")); Assert.IsNotNull(itemsView); // Try out the Grid Pattern GridPattern grid = (GridPattern)itemsView.GetCachedPattern(GridPattern.Pattern); Assert.IsTrue(grid.Cached.ColumnCount > 0); Assert.IsTrue(grid.Cached.RowCount > 0); // GridItem AutomationElement gridItemElement = grid.GetItem(0, 0); Assert.IsNotNull(gridItemElement); GridItemPattern gridItem = (GridItemPattern)gridItemElement.GetCachedPattern(GridItemPattern.Pattern); Assert.AreEqual(gridItem.Cached.Row, 0); Assert.AreEqual(gridItem.Cached.Column, 0); Assert.AreEqual(gridItem.Cached.ContainingGrid, itemsView); } }
public static CacheRequest BuildCacheRequest(TreeScope treeScope, params AutomationProperty[] properties) { var cr = new CacheRequest { TreeScope = treeScope }; foreach (var property in properties) cr.Add(property); return cr; }
public IEnumerable<ITab> GetTabsOfWindow(IntPtr hWnd) { var notepadPlusPlusWindow = AutomationElement.FromHandle(hWnd); var cacheRequest = new CacheRequest(); cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.LocalizedControlTypeProperty); cacheRequest.Add(SelectionItemPattern.Pattern); cacheRequest.Add(SelectionItemPattern.SelectionContainerProperty); cacheRequest.TreeScope = TreeScope.Element; AutomationElement tabBarElement; using (cacheRequest.Activate()) { tabBarElement = notepadPlusPlusWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "tab")); } if(tabBarElement == null) yield break; var tabElements = tabBarElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "tab item")); for (var tabIndex = 0; tabIndex < tabElements.Count; tabIndex++) { yield return new NotepadPlusPlusTab(tabElements[tabIndex]); } }
public void TreeScopeTest() { CacheRequest target = new CacheRequest(); TreeScope expected = TreeScope.Subtree; TreeScope actual; target.TreeScope = expected; actual = target.TreeScope; Assert.AreEqual(expected, actual); }
public void TreeFilterTest() { CacheRequest target = new CacheRequest(); PropertyCondition expected = new PropertyCondition(AutomationElement.NameProperty, "foo"); PropertyCondition actual; target.TreeFilter = expected; actual = (PropertyCondition)target.TreeFilter; Assert.AreEqual(expected.Flags, actual.Flags); Assert.AreEqual(expected.Property, actual.Property); Assert.AreEqual(expected.Value, actual.Value); }
public void ActivateTest() { CacheRequest target = new CacheRequest(); Assert.AreNotEqual(CacheRequest.Current, target); using (target.Activate()) { Assert.AreEqual(CacheRequest.Current, target); CacheRequest target2 = new CacheRequest(); using (target2.Activate()) { Assert.AreNotEqual(CacheRequest.Current, target); } } }
public void MyTestInitialize() { // Get all children of the desktop for our target collection CacheRequest cacheReq = new CacheRequest(); cacheReq.Add(AutomationElement.NameProperty); cacheReq.Add(AutomationElement.NativeWindowHandleProperty); using (cacheReq.Activate()) { this.testColl = AutomationElement.RootElement.FindAll( TreeScope.Children, Condition.TrueCondition); Assert.IsNotNull(this.testColl); Assert.IsTrue(this.testColl.Count > 0); } }
public AutomationElement GetLastChild(AutomationElement element, CacheRequest request) { Utility.ValidateArgumentNonNull(element, "element"); Utility.ValidateArgumentNonNull(request, "request"); try { return AutomationElement.Wrap(this._obj.GetLastChildElementBuildCache( element.NativeElement, request.NativeCacheRequest)); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
public static UIA.CacheRequest ToNative(this CacheRequest cacheRequest) { var nativeCacheRequest = new UIA.CacheRequest(); nativeCacheRequest.AutomationElementMode = (UIA.AutomationElementMode)cacheRequest.AutomationElementMode; nativeCacheRequest.TreeFilter = ConditionConverter.ToNative(cacheRequest.TreeFilter); nativeCacheRequest.TreeScope = (UIA.TreeScope)cacheRequest.TreeScope; foreach (var pattern in cacheRequest.Patterns) { nativeCacheRequest.Add(UIA.AutomationPattern.LookupById(pattern.Id)); } foreach (var property in cacheRequest.Properties) { nativeCacheRequest.Add(UIA.AutomationProperty.LookupById(property.Id)); } return(nativeCacheRequest); }
public void CachedRelationshipTest() { CacheRequest req = new CacheRequest(); req.TreeScope = TreeScope.Element | TreeScope.Children; using (req.Activate()) { AutomationElement rootElement = AutomationElement.RootElement; AutomationElementCollection rootChildren = rootElement.CachedChildren; Assert.IsNotNull(rootChildren); Assert.IsTrue(rootChildren.Count > 0); AutomationElement firstChild = rootChildren[0]; AutomationElement cachedParent = firstChild.CachedParent; Assert.IsNotNull(cachedParent); Assert.AreEqual(cachedParent, rootElement); } }
public void ExpandCollapsePatternCachedTest() { using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL intl.cpl")) { CacheRequest req = new CacheRequest(); req.Add(ExpandCollapsePattern.Pattern); req.Add(ExpandCollapsePattern.ExpandCollapseStateProperty); using (req.Activate()) { // 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.GetCachedPattern(ExpandCollapsePattern.Pattern); Assert.AreEqual(expando.Cached.ExpandCollapseState, ExpandCollapseState.Collapsed); } } }
public void GetUpdatedCacheTest() { AutomationElement elem = AutomationElement.RootElement; try { string name = elem.Cached.Name; Assert.Fail("expected exception"); } catch (ArgumentException) { } CacheRequest req = new CacheRequest(); req.Add(AutomationElement.NameProperty); AutomationElement refreshed = elem.GetUpdatedCache(req); string name2 = refreshed.Cached.Name; }
public void FindFirstTest() { // Find a child CacheRequest cacheReq = new CacheRequest(); cacheReq.Add(AutomationElement.NativeWindowHandleProperty); using (cacheReq.Activate()) { Assert.AreSame(CacheRequest.Current, cacheReq); AutomationElement actualCached = AutomationElement.RootElement.FindFirst( TreeScope.Children, Condition.TrueCondition); Assert.IsNotNull(actualCached); int nativeHwnd = (int)actualCached.GetCachedPropertyValue(AutomationElement.NativeWindowHandleProperty); Assert.IsTrue(nativeHwnd != 0); } }
public void GetCachedPatternTest() { CacheRequest req = new CacheRequest(); req.Add(LegacyIAccessiblePattern.Pattern); using (req.Activate()) { LegacyIAccessiblePattern pattern = (LegacyIAccessiblePattern)GetTaskbar().GetCachedPattern(LegacyIAccessiblePattern.Pattern); Assert.IsNotNull(pattern); } }
public AutomationElement GetUpdatedAEWhenStructureChanged(AutomationElement mainWidow, AutomationPattern patternToCache = null, AutomationProperty propertyToCache = null) { CacheRequest cacheRequest = new CacheRequest(); cacheRequest.TreeScope = TreeScope.Element | TreeScope.Descendants | TreeScope.Children; cacheRequest.AutomationElementMode = AutomationElementMode.Full; cacheRequest.TreeFilter = System.Windows.Automation.Automation.RawViewCondition; if (patternToCache != null) { cacheRequest.Add(patternToCache); } else { cacheRequest.Add(SelectionPattern.Pattern); cacheRequest.Add(WindowPattern.Pattern); cacheRequest.Add(InvokePattern.Pattern); cacheRequest.Add(TogglePattern.Pattern); cacheRequest.Add(ExpandCollapsePattern.Pattern); cacheRequest.Add(ValuePattern.Pattern); cacheRequest.Add(SelectionItemPattern.Pattern); } if (propertyToCache != null) { cacheRequest.Add(propertyToCache); } else { cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.AutomationIdProperty); cacheRequest.Add(AutomationElement.ClassNameProperty); cacheRequest.Add(AutomationElement.ControlTypeProperty); } AutomationElement updatedElement; using (cacheRequest.Activate()) { updatedElement = mainWidow.GetUpdatedCache(cacheRequest); } return updatedElement; }
/// <summary> /// Get the last child of the specified element, in the current view, /// prefetching properties /// </summary> /// <param name="element">element to get the last child of</param> /// <param name="request">CacheRequest specifying information to be prefetched</param> /// <returns>The last child of the specified element - or null if /// the specified element has no children</returns> /// <remarks>The view used is determined by the condition passed to /// the constructor - elements that do not satisfy that condition /// are skipped over</remarks> public AutomationElement GetLastChild(AutomationElement element, CacheRequest request) { Misc.ValidateArgumentNonNull(element, "element"); Misc.ValidateArgumentNonNull(request, "request"); return(element.Navigate(NavigateDirection.LastChild, _condition, request)); }
internal CacheRequest(CacheRequest other) { this.IUIAutomationCacheRequest = other.IUIAutomationCacheRequest; }
public void TablePatternCachedTest() { CacheRequest req = new CacheRequest(); req.Add(TablePattern.Pattern); req.Add(TableItemPattern.Pattern); req.Add(GridPattern.Pattern); req.Add(GridItemPattern.Pattern); req.Add(GridPattern.RowCountProperty); req.Add(GridPattern.ColumnCountProperty); req.Add(GridItemPattern.RowProperty); req.Add(GridItemPattern.ColumnProperty); req.Add(GridItemPattern.ContainingGridProperty); req.Add(TablePattern.RowHeadersProperty); req.Add(TablePattern.ColumnHeadersProperty); req.Add(TableItemPattern.RowHeaderItemsProperty); req.Add(TableItemPattern.ColumnHeaderItemsProperty); using (req.Activate()) { AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView")); Assert.IsNotNull(itemsView); // TablePattern test TablePattern table = (TablePattern)itemsView.GetCachedPattern(TablePattern.Pattern); Assert.IsTrue(table.Cached.ColumnCount > 0); Assert.IsTrue(table.Cached.RowCount > 0); Assert.IsTrue(table.Cached.GetRowHeaders().Length == 0); Assert.IsTrue(table.Cached.GetColumnHeaders().Length > 0); AutomationElement tableItemElement = table.GetItem(0, 0); TableItemPattern tableItem = (TableItemPattern)tableItemElement.GetCachedPattern(TableItemPattern.Pattern); Assert.AreEqual(tableItem.Cached.Row, 0); Assert.AreEqual(tableItem.Cached.Column, 0); Assert.AreEqual(tableItem.Cached.ContainingGrid, itemsView); Assert.IsTrue(tableItem.Cached.GetColumnHeaderItems().Length == 1); Assert.IsTrue(tableItem.Cached.GetRowHeaderItems().Length == 0); } }
internal AutomationElement Normalize(Condition condition, CacheRequest request ) { CheckElement(); UiaCoreApi.UiaCacheRequest cacheRequest; if (request == null) cacheRequest = CacheRequest.DefaultUiaCacheRequest; else cacheRequest = request.GetUiaCacheRequest(); // Normalize against the treeview condition, not the one in the cache request... UiaCoreApi.UiaCacheResponse response = UiaCoreApi.UiaGetUpdatedCache(_hnode, cacheRequest, UiaCoreApi.NormalizeState.Custom, condition); return CacheHelper.BuildAutomationElementsFromResponse(cacheRequest, response); }
/// <summary> /// Get the previous sibling of the specified element, in the current view, /// prefetching properties /// </summary> /// <param name="element">element to get the previous sibling of</param> /// <param name="request">CacheRequest specifying information to be prefetched</param> /// <returns>The previous sibling of the specified element - or null if the /// specified element has no previous sibling</returns> /// <remarks>The view used is determined by the condition passed to /// the constructor - elements that do not satisfy that condition /// are skipped over</remarks> public AutomationElement GetPreviousSibling(AutomationElement element, CacheRequest request) { Misc.ValidateArgumentNonNull(element, "element"); Misc.ValidateArgumentNonNull(request, "request"); return(element.Navigate(NavigateDirection.PreviousSibling, _condition, request)); }
/// <summary> /// Return the element or the nearest ancestor which is present in /// the view of the tree used by this treewalker, prefetching properties /// for the returned node /// </summary> /// <param name="element">element to normalize</param> /// <param name="request">CacheRequest specifying information to be prefetched</param> /// <returns>The element or the nearest ancestor which satisfies the /// condition used by this TreeWalker</returns> /// <remarks> /// This method starts at the specified element and walks up the /// tree until it finds an element that satisfies the TreeWalker's /// condition. /// /// If the passed-in element itself satsifies the condition, it is /// returned as-is. /// /// If the process of walking up the tree hits the root node, then /// the root node is returned, regardless of whether it satisfies /// the condition or not. /// </remarks> public AutomationElement Normalize(AutomationElement element, CacheRequest request) { Misc.ValidateArgumentNonNull(element, "element"); Misc.ValidateArgumentNonNull(request, "request"); return(element.Normalize(_condition, request)); }
protected internal void SubscribeToEvents(HasControlInputCmdletBase cmdlet, AutomationElement inputObject, AutomationEvent eventType, AutomationProperty prop) { AutomationEventHandler uiaEventHandler; AutomationPropertyChangedEventHandler uiaPropertyChangedEventHandler; StructureChangedEventHandler uiaStructureChangedEventHandler; AutomationFocusChangedEventHandler uiaFocusChangedEventHandler; // 20130109 if (null == CurrentData.Events) { CurrentData.InitializeEventCollection(); } try { CacheRequest cacheRequest = new CacheRequest(); cacheRequest.AutomationElementMode = AutomationElementMode.Full; //.None; cacheRequest.TreeFilter = Automation.RawViewCondition; cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.AutomationIdProperty); cacheRequest.Add(AutomationElement.ClassNameProperty); cacheRequest.Add(AutomationElement.ControlTypeProperty); //cacheRequest.Add(AutomationElement.ProcessIdProperty); // cache patterns? // cacheRequest.Activate(); cacheRequest.Push(); switch (eventType.ProgrammaticName) { case "InvokePatternIdentifiers.InvokedEvent": this.WriteVerbose(cmdlet, "subscribing to the InvokedEvent handler"); Automation.AddAutomationEventHandler( InvokePattern.InvokedEvent, inputObject, TreeScope.Element, // TreeScope.Subtree, // TreeScope.Element, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "TextPatternIdentifiers.TextChangedEvent": this.WriteVerbose(cmdlet, "subscribing to the TextChangedEvent handler"); Automation.AddAutomationEventHandler( TextPattern.TextChangedEvent, inputObject, TreeScope.Element, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "TextPatternIdentifiers.TextSelectionChangedEvent": this.WriteVerbose(cmdlet, "subscribing to the TextSelectionChangedEvent handler"); Automation.AddAutomationEventHandler( TextPattern.TextSelectionChangedEvent, inputObject, TreeScope.Element, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "WindowPatternIdentifiers.WindowOpenedProperty": this.WriteVerbose(cmdlet, "subscribing to the WindowOpenedEvent handler"); Automation.AddAutomationEventHandler( WindowPattern.WindowOpenedEvent, inputObject, TreeScope.Subtree, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.AutomationPropertyChangedEvent": if (prop != null) { this.WriteVerbose(cmdlet, "subscribing to the AutomationPropertyChangedEvent handler"); Automation.AddAutomationPropertyChangedEventHandler( inputObject, TreeScope.Subtree, uiaPropertyChangedEventHandler = // new AutomationPropertyChangedEventHandler(OnUIAutomationPropertyChangedEvent), //new AutomationPropertyChangedEventHandler(handler), //new AutomationPropertyChangedEventHandler(((EventCmdletBase)cmdlet).AutomationPropertyChangedEventHandler), new AutomationPropertyChangedEventHandler(cmdlet.AutomationPropertyChangedEventHandler), prop); UIAHelper.WriteEventToCollection(cmdlet, uiaPropertyChangedEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaPropertyChangedEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaPropertyChangedEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } } break; case "AutomationElementIdentifiers.StructureChangedEvent": this.WriteVerbose(cmdlet, "subscribing to the StructureChangedEvent handler"); Automation.AddStructureChangedEventHandler( inputObject, TreeScope.Subtree, uiaStructureChangedEventHandler = // new StructureChangedEventHandler(OnUIStructureChangedEvent)); //new StructureChangedEventHandler(handler)); //new StructureChangedEventHandler(((EventCmdletBase)cmdlet).StructureChangedEventHandler)); new StructureChangedEventHandler(cmdlet.StructureChangedEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaStructureChangedEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaStructureChangedEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaStructureChangedEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "WindowPatternIdentifiers.WindowClosedProperty": this.WriteVerbose(cmdlet, "subscribing to the WindowClosedEvent handler"); Automation.AddAutomationEventHandler( WindowPattern.WindowClosedEvent, inputObject, TreeScope.Subtree, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.MenuClosedEvent": this.WriteVerbose(cmdlet, "subscribing to the MenuClosedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.MenuClosedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.MenuOpenedEvent": this.WriteVerbose(cmdlet, "subscribing to the MenuOpenedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.MenuOpenedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.ToolTipClosedEvent": this.WriteVerbose(cmdlet, "subscribing to the ToolTipClosedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.ToolTipClosedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.ToolTipOpenedEvent": this.WriteVerbose(cmdlet, "subscribing to the ToolTipOpenedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.ToolTipOpenedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.AutomationFocusChangedEvent": WriteVerbose(cmdlet, "subscribing to the AutomationFocusChangedEvent handler"); Automation.AddAutomationFocusChangedEventHandler( //AutomationElement.AutomationFocusChangedEvent, //inputObject, //System.Windows.Automation.AutomationElement.RootElement, //TreeScope.Subtree, uiaFocusChangedEventHandler = new AutomationFocusChangedEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaFocusChangedEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaFocusChangedEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaFocusChangedEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; default: this.WriteVerbose(cmdlet, "the following event has not been subscribed to: " + eventType.ProgrammaticName); break; } this.WriteVerbose(cmdlet, "on the object " + inputObject.Current.Name); cacheRequest.Pop(); } catch (Exception e) { // try { // ErrorRecord err = new ErrorRecord( // e, // "RegisteringEvent", // ErrorCategory.OperationStopped, // inputObject); // err.ErrorDetails = // new ErrorDetails("Unable to register event handler " + // // handler.ToString()); // eventType.ProgrammaticName + // " for " + // inputObject.Current.Name); // // this.OnSuccessAction.ToString()); // WriteError(this, err, false); // } // catch { // ErrorRecord err = new ErrorRecord( // e, // "RegisteringEvent", // ErrorCategory.OperationStopped, // inputObject); // err.ErrorDetails = // new ErrorDetails("Unable to register event handler " + // eventType.ProgrammaticName);; // WriteError(this, err, false); // } WriteVerbose(cmdlet, "Unable to register event handler " + eventType.ProgrammaticName + " for " + inputObject.Current.Name); WriteVerbose(cmdlet, e.Message); } }
public RequestToken(CacheRequest request) { this.request = request; }
// Called by the treewalker classes to navigate - we call through to the // provider wrapper, which gets the navigator code to do its stuff internal AutomationElement Navigate(NavigateDirection direction, Condition condition, CacheRequest request) { CheckElement(); UiaCoreApi.UiaCacheRequest cacheRequest; if (request == null) cacheRequest = CacheRequest.DefaultUiaCacheRequest; else cacheRequest = request.GetUiaCacheRequest(); UiaCoreApi.UiaCacheResponse response = UiaCoreApi.UiaNavigate(_hnode, direction, condition, cacheRequest); return CacheHelper.BuildAutomationElementsFromResponse(cacheRequest, response); }
public void MultipleViewPatternTest() { CacheRequest req = new CacheRequest(); req.Add(MultipleViewPattern.Pattern); req.Add(MultipleViewPattern.CurrentViewProperty); req.Add(MultipleViewPattern.SupportedViewsProperty); using (req.Activate()) { AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView")); Assert.IsNotNull(itemsView); MultipleViewPattern multiView = (MultipleViewPattern)itemsView.GetCachedPattern(MultipleViewPattern.Pattern); int[] supportedViews = multiView.Cached.GetSupportedViews(); Assert.IsNotNull(supportedViews.Length > 0); bool inSupportedViews = false; foreach (int view in supportedViews) { if (view == multiView.Cached.CurrentView) { inSupportedViews = true; break; } string viewName = multiView.GetViewName(view); Assert.IsTrue(viewName.Length > 0); } Assert.IsTrue(inSupportedViews); } }
/// <summary> /// Get an AutomationElement with updated cached values /// </summary> /// <param name="request">CacheRequest object describing the properties and other information to fetch</param> /// <returns>Returns a new AutomationElement, which refers to the same UI as this element, but which is /// populated with properties specified in the CacheRequest.</returns> /// <remarks> /// Unlike other methods, such as FromHandle, FromPoint, this method takes /// an explicit CacheRequest as a parameter, and ignores the currently /// active CacheRequest. /// </remarks> public AutomationElement GetUpdatedCache(CacheRequest request) { Misc.ValidateArgumentNonNull(request, "request"); CheckElement(); UiaCoreApi.UiaCacheRequest cacheRequest = request.GetUiaCacheRequest(); // Don't normalize when getting updated cache... UiaCoreApi.UiaCacheResponse response = UiaCoreApi.UiaGetUpdatedCache(_hnode, cacheRequest, UiaCoreApi.NormalizeState.None, null); return CacheHelper.BuildAutomationElementsFromResponse(cacheRequest, response); }
public AutomationElement GetUpdatedCache(CacheRequest request) { try { return AutomationElement.Wrap(this._obj.BuildUpdatedCache(request.NativeCacheRequest)); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
internal CacheRequestActivation(CacheRequest request) { this._request = request; }
internal CacheRequestMartyr(CacheRequest request) { this._request = request; }
public void Dispose() { if (this._request != null) { this._request.Pop(); this._request = null; } }
public void FindAllTest() { // Find all children CacheRequest cacheReq = new CacheRequest(); cacheReq.Add(AutomationElement.NameProperty); cacheReq.Add(AutomationElement.NativeWindowHandleProperty); using (cacheReq.Activate()) { AutomationElementCollection actual = AutomationElement.RootElement.FindAll( TreeScope.Children, Condition.TrueCondition); Assert.IsNotNull(actual); Assert.IsTrue(actual.Count > 0); foreach (AutomationElement elem in actual) { Assert.IsNotNull(elem); int nativeHwnd = (int)elem.GetCachedPropertyValue(AutomationElement.NativeWindowHandleProperty); Assert.IsTrue(nativeHwnd != 0); } } }
public UIA2CacheRequest(UIA2Automation automation) { Automation = automation; NativeCacheRequest = new UIA.CacheRequest(); }
/// ------------------------------------------------------------------- /// <summary>HELPER: Generates a random cache</summary> /// ------------------------------------------------------------------- static CacheRequest RandomCache() { Random rnd = new Random((int)DateTime.Now.Ticks); StringBuilder sb = new StringBuilder(); CacheRequest cache = new CacheRequest(); AutomationPattern p1; AutomationProperty p2; ArrayList propertyList = null; ArrayList patternList = null; PopulateAutomationElementProperties(ref propertyList, ref patternList); try { // Decide whether to add patterns if (rnd.Next(2) == 0) { // Add up to two patterns int maxIndex = rnd.Next(2); for (int index = 0; index < maxIndex; index++) { try { if (null != (p1 = (AutomationPattern)patternList[rnd.Next(patternList.Count)])) { sb.Append(p1.ProgrammaticName + ":"); cache.Add(p1); } } catch (Exception) { } } } // Decide whether to add properties if (rnd.Next(2) == 0) { // Add up to three AutomationProperty int maxIndex = rnd.Next(3); for (int index = 0; index < maxIndex; index++) { try { if (null != (p2 = (AutomationProperty)propertyList[(rnd.Next(propertyList.Count))])) { sb.Append(p2.ProgrammaticName + ":"); cache.Add(p2); } } catch (Exception) { } } } switch (rnd.Next(2)) { case 0: cache.AutomationElementMode = AutomationElementMode.Full; sb.Append(AutomationElementMode.Full + ":"); break; case 1: cache.AutomationElementMode = AutomationElementMode.None; sb.Append(AutomationElementMode.None + ":"); break; default: throw new Exception("Bad test code(AutomationElementMode)"); } switch (rnd.Next(6)) { case 0: cache.TreeScope = TreeScope.Ancestors; sb.Append(TreeScope.Ancestors + ":"); break; case 1: cache.TreeScope = TreeScope.Children; sb.Append(TreeScope.Children + ":"); break; case 2: cache.TreeScope = TreeScope.Descendants; sb.Append(TreeScope.Descendants + ":"); break; case 3: cache.TreeScope = TreeScope.Element; sb.Append(TreeScope.Element + ":"); break; case 4: cache.TreeScope = TreeScope.Parent; sb.Append(TreeScope.Parent + ":"); break; case 5: cache.TreeScope = TreeScope.Subtree; sb.Append(TreeScope.Subtree + ":"); break; default: throw new Exception("Bad test code(treescope)"); } //switch (rnd.Next(3)) //{ // case 0: // cache.TreeFilter = NotCondition.; // break; // case 1: // cache.TreeFilter = AndCondition; // break; // case 2: // cache.TreeFilter = OrCondition; // break; //} } catch (ArgumentException) { // Some TreeScopes are invalid } Dump(sb.ToString(), false, null); return cache; }
public void CloneTest() { CacheRequest target = new CacheRequest(); target.TreeScope = TreeScope.Subtree; CacheRequest actual; actual = target.Clone(); Assert.AreEqual(target.TreeScope, actual.TreeScope); }
public void AddTest() { CacheRequest target = new CacheRequest(); target.Add(AutomationElement.HelpTextProperty); target.Add(ExpandCollapsePatternIdentifiers.Pattern); }
public void Bug1() { application = new WinFormTestConfiguration(string.Empty).Launch(); Thread.Sleep(1000); var propertyCondition = new PropertyCondition(AutomationElement.NameProperty, "Form1"); AutomationElement element = AutomationElement.RootElement.FindFirst(TreeScope.Children, propertyCondition); AutomationElementCollection collection; var request = new CacheRequest(); using (request.Activate()) collection = element.FindAll(TreeScope.Subtree, Condition.TrueCondition); int cachedChildrenFoundFor = 0; foreach (AutomationElement automationElement in collection) { try { AutomationElementCollection children = automationElement.CachedChildren; cachedChildrenFoundFor++; } catch (InvalidOperationException) {} } Assert.AreNotEqual(0, cachedChildrenFoundFor, "Cached children not found for even one AutomationElement out of " + collection.Count + " elements"); }