//The "Z_" prefix ensures this test runs last, since it will change the column/row count of the data grid //todo Currently This test case fails, see #bug 549112 public void Z_DynamicTest() { var automationEventsArray = new [] { new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null } }; var automationEvents = automationEventsArray.ToList(); automationEvents.Clear(); AutomationPropertyChangedEventHandler handler = (o, e) => automationEvents.Add(new { Sender = o, Args = e }); At.AddAutomationPropertyChangedEventHandler(table1Element, TreeScope.Element, handler, GridPattern.RowCountProperty, GridPattern.ColumnCountProperty); RunCommand("add table row"); Assert.AreEqual(1, automationEvents.Count, "event count"); Assert.AreEqual(table1Element, automationEvents [0].Sender, "event sender"); Assert.AreEqual(GridPattern.RowCountProperty, automationEvents [0].Args.Property, "property"); int oldValue = (Atspi? 2: 3); Assert.AreEqual(oldValue, automationEvents [0].Args.OldValue, "old value"); Assert.AreEqual(oldValue + 1, automationEvents [0].Args.NewValue, "new value"); automationEvents.Clear(); RunCommand("add table column"); Assert.AreEqual(1, automationEvents.Count, "event count"); Assert.AreEqual(table1Element, automationEvents [0].Sender, "event sender"); Assert.AreEqual(GridPattern.ColumnCountProperty, automationEvents [0].Args.Property, "property"); Assert.AreEqual(3, automationEvents [0].Args.OldValue, "old value"); Assert.AreEqual(4, automationEvents [0].Args.NewValue, "new value"); }
public void RemoveAutomationPropertyChangedEventHandler(IElement element, AutomationPropertyChangedEventHandler eventHandler) { int handlerId = eventHandlerManager.GetPropertyEventIdByHandler(eventHandler); if (handlerId == -1) { return; } if (element == null) { //the element is the RootElement RootElementEventsManager.RemovePropertyEventRequest(handlerId); foreach (var entry in GetUiaApplications()) { entry.Value.RemoveRootElementAutomationPropertyChangedEventHandler(handlerId); } } else { UiaDbusElement uiaDbusElement = element as UiaDbusElement; if (uiaDbusElement == null) { Log.Error("[RemoveAutomationPropertyChangedEventHandler] " + "The element sent to UiaDbusSource is not UiaDbusElement"); return; } string busName = uiaDbusElement.BusName; DCI.IApplication app = Bus.Session.GetObject <DCI.IApplication> (busName, new ObjectPath(DC.Constants.ApplicationPath)); int [] runtimeId = uiaDbusElement.RuntimeId; app.RemoveAutomationPropertyChangedEventHandler(runtimeId, handlerId); } }
public static void AddAutomationPropertyChangedEventHandler(AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, params AutomationProperty[] properties) { Utility.ValidateArgumentNonNull(element, "element"); Utility.ValidateArgumentNonNull(eventHandler, "eventHandler"); Utility.ValidateArgumentNonNull(properties, "properties"); if (properties.Length == 0) { throw new ArgumentException("AtLeastOnePropertyMustBeSpecified"); } int[] propertyIdArray = new int[properties.Length]; for (int i = 0; i < properties.Length; ++i) { Utility.ValidateArgumentNonNull(properties[i], "properties"); propertyIdArray[i] = properties[i].Id; } try { PropertyEventListener listener = new PropertyEventListener(AutomationElement.StructureChangedEvent, element, eventHandler); Factory.AddPropertyChangedEventHandler( element.NativeElement, (UIAutomationClient.TreeScope)scope, CacheRequest.CurrentNativeCacheRequest, listener, propertyIdArray); ClientEventList.Add(listener); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
/// <summary> /// Adds a property changed automation event handler /// </summary> /// <param name="hWnd">window handle</param> /// <param name="property">the property to track</param> /// <param name="element">the element in the window to track</param> /// <param name="eventHandler">the event handler</param> static public void AddAutomationPropertyChangedEventHandler(IntPtr hWnd, AutomationProperty property, AutomationElement element, AutomationPropertyChangedEventHandler eventHandler) { lock (WindowTable) { var windowElement = (WindowElement)WindowTable[hWnd]; if (windowElement == null) { windowElement = new WindowElement(hWnd); WindowTable.Add(hWnd, windowElement); windowElement.EvtOnWindowClosed += windowElement_EvtOnWindowClosed; } var item = new AddAutomationPropertyChangedItem { Property = property, AutoElement = element, EventHandler = eventHandler, WinElement = windowElement }; AddAutomationPropertyChanged(item); } }
public static void RemoveAutomationPropertyChangedEventHandler (IRawElementProviderSimple provider, AutomationPropertyChangedEventHandler eventHandler) { lock (propertyChangedEventEntries) propertyChangedEventEntries.RemoveAll (e => e.Provider == provider && e.Handler == eventHandler); }
///-------------------------------------------------------------------- /// <summary> /// Register for events of interest. /// </summary> ///-------------------------------------------------------------------- private void RegisterForEvents() { // Focus changes are global; we'll get cached properties for // all elements that receive focus. focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange); Automation.AddAutomationFocusChangedEventHandler(focusHandler); // Register for events from descendants of the root element. // Only the events supported by a control will be registered. invokeHandler = new AutomationEventHandler(OnInvoke); Automation.AddAutomationEventHandler( InvokePattern.InvokedEvent, targetApp, TreeScope.Children, invokeHandler); rangevalueHandler = new AutomationPropertyChangedEventHandler(OnRangeValueChange); Automation.AddAutomationPropertyChangedEventHandler( targetApp, TreeScope.Children, rangevalueHandler, RangeValuePattern.ValueProperty); selectionHandler = new AutomationEventHandler(OnSelectionItemSelected); Automation.AddAutomationEventHandler( SelectionItemPattern.ElementSelectedEvent, targetApp, TreeScope.Descendants, selectionHandler); }
/// <summary> /// Removes a previously added property changed event handler /// </summary> /// <param name="hWnd">window handle</param> /// <param name="property">the property to remove</param> /// <param name="element">the control in the window</param> /// <param name="eventHandler">the eveht handler to remove</param> static public void RemoveAutomationPropertyChangedEventHandler(IntPtr hWnd, AutomationProperty property, AutomationElement element, AutomationPropertyChangedEventHandler eventHandler) { Log.Debug(); if (hWnd == IntPtr.Zero) { return; } lock (WindowTable) { var windowElement = (WindowElement)WindowTable[hWnd]; if (windowElement != null) { var item = new RemoveAutomationPropertyChangedItem { Property = property, AutoElement = element, EventHandler = eventHandler, WinElement = windowElement }; RemoveAutomationPropertyChanged(item); //windowElement.RemoveAutomationPropertyChangedEventHandler(element, property, eventHandler); } } }
/// <summary> /// Adds a handler for property-changed event; in particular, a change in the enabled state. /// </summary> /// <param name="element">The UI Automation element whose state is being monitored.</param> public void SubscribePropertyChange(AutomationElement element) { Automation.AddAutomationPropertyChangedEventHandler(element, TreeScope.Element, propChangeHandler = new AutomationPropertyChangedEventHandler(OnPropertyChange), AutomationElement.IsEnabledProperty); }
//The "Z1_" prefix ensures the test case's execution sequence public void Z1_DynamicTest() { var automationEventsArray = new [] { new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null } }; var automationEvents = automationEventsArray.ToList(); automationEvents.Clear(); AutomationPropertyChangedEventHandler handler = (o, e) => automationEvents.Add(new { Sender = o, Args = e }); At.AddAutomationPropertyChangedEventHandler(listView1Element, TreeScope.Element, handler, MultipleViewPattern.CurrentViewProperty, MultipleViewPattern.SupportedViewsProperty); RunCommand("change list view mode list"); //var currentView = pattern.Current.CurrentView; // We should expect an AutomationPropertyChangedEvent here, // But since on Windows Winforms didn't fire such a event, then we also assert no event fired. Assert.AreEqual(0, automationEvents.Count, "event count"); /* * Assert.AreEqual (1, automationEvents.Count, "event count"); * Assert.AreEqual (listView1Element, automationEvents [0].Sender, "event sender"); * Assert.AreEqual (MultipleViewPattern.CurrentViewProperty, automationEvents [0].Args.Property, "property"); * Assert.AreEqual (3, automationEvents [0].Args.NewValue, "new value"); * Assert.AreEqual (1, automationEvents [0].Args.OldValue, "old value"); * Assert.AreEqual ("List", pattern.GetViewName (currentView), "Current view name" );*/ }
/// <summary> /// Called by a client to add a listener for property changed events. /// </summary> /// <param name="element">Element on which to listen for property changed events.</param> /// <param name="scope">Specifies whether to listen to property changes events on the specified element, and/or its ancestors and children.</param> /// <param name="eventHandler">Callback object to call when a specified property change occurs.</param> /// <param name="properties">Params array of properties to listen for changes in.</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void AddAutomationPropertyChangedEventHandler( AutomationElement element, // reference element for listening to the event TreeScope scope, // scope to listen to AutomationPropertyChangedEventHandler eventHandler, // callback object params AutomationProperty [] properties // listen for changes to these properties ) { Misc.ValidateArgumentNonNull(element, "element"); Misc.ValidateArgumentNonNull(eventHandler, "eventHandler"); Misc.ValidateArgumentNonNull(properties, "properties"); if (properties.Length == 0) { throw new ArgumentException(SR.Get(SRID.AtLeastOnePropertyMustBeSpecified)); } // Check that no properties are interpreted properties // If more interpreted properties are identified add a mapping of // on interpreted properties to the real property that raises events. foreach (AutomationProperty property in properties) { Misc.ValidateArgumentNonNull(property, "properties"); } // Add a client-side listener for for this event request EventListener l = new EventListener(AutomationElement.AutomationPropertyChangedEvent, scope, properties, CacheRequest.CurrentUiaCacheRequest); ClientEventManager.AddListener(element, eventHandler, l); }
public void PropertyEventTest() { int eventCount = 0; AutomationProperty changedProperty = null; object newValue = null; object sender = null; AutomationPropertyChangedEventHandler handler = (o, e) => { eventCount++; changedProperty = e.Property; newValue = e.NewValue; sender = o; }; At.AddAutomationPropertyChangedEventHandler( AutomationElement.RootElement, TreeScope.Children, handler, AutomationElement.NameProperty); RunCommand("change title:title 1"); Assert.AreEqual(1, eventCount, "count of AutomationPropertyChangedEvent"); Assert.AreEqual(AutomationElement.NameProperty, changedProperty); Assert.AreEqual("title 1", newValue); Assert.AreEqual(testFormElement, sender); At.RemoveAutomationPropertyChangedEventHandler( AutomationElement.RootElement, handler); RunCommand("change title:title 2"); Assert.AreEqual(1, eventCount); }
AutomationPropertyChangedEventHandlerImpl( IUIAutomationElement uiAutomationElement, AutomationPropertyChangedEventHandler handlingDelegate) { this._uiAutomationElement = uiAutomationElement; this._handlingDelegate = handlingDelegate; }
public static void AddAutomationPropertyChangedEventHandler( AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, params AutomationProperty[] properties) { AutomationPropertyChangedEventHandlerImpl.Add(element: element, scope: scope, handlingDelegate: eventHandler, properties: properties); }
//TODO While recording you get exception when clicking at the corner of the cell public override void HookEvents(UIItemEventListener eventListener) { var safeAutomationEventHandler = new SafeAutomationEventHandler(this, eventListener, objs => ListViewEvent.Create(this, (AutomationPropertyChangedEventArgs)objs[0])); handler = safeAutomationEventHandler.PropertyChange; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Descendants, handler, SelectionItemPattern.IsSelectedProperty); }
protected void SubscribePropertyChange() { Automation.AddAutomationPropertyChangedEventHandler(AddressBar, TreeScope.Element, _propChangeHandler = new AutomationPropertyChangedEventHandler(OnPropertyChange), AutomationProperty.LookupById(ValuePattern.ValueProperty.Id)); Console.WriteLine($"SubscribePropertyChange. Address: {GetCurrentUrl()}"); }
/// <summary> /// Initializes UI automation by finding the target form, adding event handlers, /// and displaying the current automation element structure. /// </summary> /// <returns>true on success; otherwise, false.</returns> public bool StartListening() { bool returnCode = false; AutomationElement rootElement = AutomationElement.RootElement; // Set a property condition that will be used to find the main form of the // target application. myTestForm is the name of the Form and in the case // of a WinForms control, it is also the AutomationId of the element representing the control. Condition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "myTestForm"); // Find the main window of the target application. AutomationElement mainWindowElement = rootElement.FindFirst(TreeScope.Element | TreeScope.Children, cond); if (mainWindowElement == null) { MessageBox.Show("Could not find the main form for the target application."); returnCode = false; } else { // Find the "Show supported patterns" checkbox and add an event handler for when // the toggle state changes. AutomationElement elementCheckBox = FindByAutomationId(mainWindowElement, "chkbxShowPatterns"); AutomationProperty[] propsWanted = { TogglePattern.ToggleStateProperty }; if (elementCheckBox != null) { if ((bool)elementCheckBox.GetCurrentPropertyValue(AutomationElement.IsTogglePatternAvailableProperty) == true) { IsElementToggledOn(elementCheckBox); AutomationPropertyChangedEventHandler _onToggleStateChanged = new AutomationPropertyChangedEventHandler(OnToggleStateChanged); Automation.AddAutomationPropertyChangedEventHandler(elementCheckBox, TreeScope.Element, _onToggleStateChanged, propsWanted); } } // Find the "UIAutomation is listening" textbox. listenElement = FindByAutomationId(mainWindowElement, "tbListen"); // Find the tab control and add an event handler for when the automation tree structure changes. // This event will be raised whenever the user selects a tab. tabElement = FindByAutomationId(mainWindowElement, "tabControl1"); if (tabElement != null) { StructureChangedEventHandler _onStructureChanged = new StructureChangedEventHandler(onStructureChanged); Automation.AddStructureChangedEventHandler(tabElement, TreeScope.Descendants, _onStructureChanged); } string StructureDescription = GetAutomationStructure(tabElement); ShowStructure(StructureDescription); // Check the "UIAutomation is listening" checkbox in the target application. InformTarget(true); returnCode = true; } return(returnCode); }
public static void AddAutomationPropertyChangedEventHandler ( IRawElementProviderSimple provider, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, int [] properties) { var entry = new PropertyChangedEventEntry (provider, scope, properties, eventHandler); lock (propertyChangedEventEntries) propertyChangedEventEntries.Add (entry); }
public PropertyChangedEventEntry(IRawElementProviderSimple provider, TreeScope scope, int [] properties, AutomationPropertyChangedEventHandler handler) : base(provider, scope) { this.Properties = properties; this.Handler = handler; }
public override void HookEvents(UIItemEventListener eventListener) { handler = delegate(object sender, AutomationPropertyChangedEventArgs e) { if (e.NewValue.Equals(1)) return; eventListener.EventOccured(new ListBoxEvent(this, SelectedItemText)); }; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Descendants, handler, SelectionItemPattern.IsSelectedProperty); }
public static void AddAutomationPropertyChangedEventHandler( IRawElementProviderSimple provider, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, int [] properties) { var entry = new PropertyChangedEventEntry(provider, scope, properties, eventHandler); lock (propertyChangedEventEntries) propertyChangedEventEntries.Add(entry); }
public override void HookEvents(UIItemEventListener eventListener) { handler = delegate { ActionPerformed(); eventListener.EventOccured(new CheckBoxEvent(this)); }; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Element, handler, TogglePattern.ToggleStateProperty); }
internal PropertyChangedEventHandlerData(IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty [] properties) { this.Element = element; this.Scope = scope; this.EventHandler = eventHandler; this.Properties = properties; }
public void AddAutomationPropertyChangedEventHandler(IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty [] properties) { PropertyChangedEventHandlerData data = new PropertyChangedEventHandlerData( element, scope, eventHandler, properties); propertyEventHandlers.Add(data); }
public override void Start(IEventSink sink) { Validate.ArgumentNotNull(parameter: sink, parameterName: nameof(sink)); Stop(); this._sinkReference = new WeakReference(target: sink); this._sinkReference.Target = sink; this._handlingDelegate = Handler; Automation.AddAutomationPropertyChangedEventHandler(element: this._root.AutomationElement, scope: (TreeScope)this._scope, eventHandler: this._handlingDelegate, properties: this._properties); Log.Out(msg: "{0} Started", (object)ToString()); }
/// <summary> /// Called by a client to remove a listener for property changed events. /// </summary> /// <param name="element">Element to remove listener for</param> /// <param name="eventHandler">The handler object that was passed to AutomationPropertyChangedEventHandler</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void RemoveAutomationPropertyChangedEventHandler( AutomationElement element, // reference element being listened to AutomationPropertyChangedEventHandler eventHandler // callback object (used as cookie here) ) { Misc.ValidateArgumentNonNull(element, "element"); Misc.ValidateArgumentNonNull(eventHandler, "eventHandler"); // Remove the client-side listener for for this event ClientEventManager.RemoveListener(AutomationElement.AutomationPropertyChangedEvent, element, eventHandler); }
public override void Stop() { if (!IsStarted) { return; } Automation.RemoveAutomationPropertyChangedEventHandler(element: this._root.AutomationElement, eventHandler: this._handlingDelegate); this._handlingDelegate = null; this._sinkReference = null; Log.Out(msg: "{0} Stopped", (object)ToString()); }
public override void HookEvents(UIItemEventListener eventListener) { handler = delegate(object sender, AutomationPropertyChangedEventArgs e) { if (e.NewValue.Equals(1)) { return; } eventListener.EventOccured(new ListBoxEvent(this, SelectedItemText)); }; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Descendants, handler, SelectionItemPattern.IsSelectedProperty); }
private void Start() { var condition = new OrCondition(new PropertyCondition(AutomationElement.ClassNameProperty, ShellTrayWnd), new PropertyCondition(AutomationElement.ClassNameProperty, ShellSecondaryTrayWnd)); var cacheRequest = new CacheRequest(); cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.BoundingRectangleProperty); _bars.Clear(); _children.Clear(); _lasts.Clear(); using (cacheRequest.Activate()) { var lists = Desktop.FindAll(TreeScope.Children, condition); if (lists == null) { Debug.WriteLine("Null values found, aborting"); return; } Debug.WriteLine(lists.Count + " bar(s) detected"); _lasts.Clear(); Parallel.ForEach(lists.OfType <AutomationElement>(), trayWnd => { var taskList = trayWnd.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, MSTaskListWClass)); if (taskList == null) { Debug.WriteLine("Null values found, aborting"); } else { _propChangeHandler = OnUIAutomationEvent; Automation.AddAutomationPropertyChangedEventHandler(taskList, TreeScope.Element, _propChangeHandler, AutomationElement.BoundingRectangleProperty); _bars.Add(trayWnd); _children.Add(trayWnd, taskList); _positionThreads[trayWnd] = Task.Run(() => LoopForPosition(trayWnd), _loopCancellationTokenSource.Token); } }); } _uiaEventHandler = OnUIAutomationEvent; Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, Desktop, TreeScope.Subtree, _uiaEventHandler); Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, Desktop, TreeScope.Subtree, _uiaEventHandler); SystemEvents.DisplaySettingsChanging += SystemEvents_DisplaySettingsChanged; }
internal static void Add( AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler handlingDelegate, AutomationProperty[] properties) { var e = new AutomationPropertyChangedEventHandlerImpl(uiAutomationElement: element.IUIAutomationElement, handlingDelegate: handlingDelegate); var cacheRequest = AutomationElement.DefaultCacheRequest.IUIAutomationCacheRequest; var propertiesArray = properties.Select(selector: p => p.Id).ToArray(); Boundary.UIAutomation(a: () => Automation.AutomationClass.AddPropertyChangedEventHandler(element: e._uiAutomationElement, scope: UiaConvert.Convert(treeScope: scope), cacheRequest: cacheRequest, handler: e, propertyArray: propertiesArray)); Add(instance: e); }
// </Snippet104> // <Snippet105> ///-------------------------------------------------------------------- /// <summary> /// Register for automation property change events of interest. /// </summary> /// <param name="targetControl"> /// The automation element of interest. /// </param> ///-------------------------------------------------------------------- private void RegisterForPropertyChangedEvents( AutomationElement targetControl) { AutomationPropertyChangedEventHandler propertyChangeListener = new AutomationPropertyChangedEventHandler( OnTopmostPropertyChange); Automation.AddAutomationPropertyChangedEventHandler( targetControl, TreeScope.Element, propertyChangeListener, WindowPattern.IsTopmostProperty); }
public void AddAutomationPropertyChangedEventHandler (IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty[] properties) { if (element == null) return; ClientElement clientElement = element as ClientElement; if (clientElement == null) { Log.Error ("[ClientAutomationSource.AddAutomationPropertyChangedEventHandler] Not ClientElement"); return; } int [] propertyIds = Array.ConvertAll (properties, p => p.Id); ClientEventManager.AddAutomationPropertyChangedEventHandler ( clientElement.Provider, scope, eventHandler, propertyIds); }
/// <summary> /// Sets the event listener hook depending on event type. /// </summary> private void SetEventHook() { /* se a property change hook */ if (_targetEvent.Property != null) { _propertyChangeHandler = OnPropertyChange; Automation.AddAutomationPropertyChangedEventHandler(_targetEvent.Source.UIAElement, TreeScope.Element, _propertyChangeHandler, _targetEvent.Property); return; } /* or a straight event handler */ _eventHandler = OnAutomationEvent; Automation.AddAutomationEventHandler(_targetEvent.EventType, _targetEvent.Source.UIAElement, TreeScope.Element, _eventHandler); }
/// <summary> /// Adds a property changed event handler /// </summary> /// <param name="element">th element for which to add the event handler</param> /// <param name="property">the property to track changes for</param> /// <param name="eventHandler">the event handler</param> public void AddAutomationPropertyChangedEventHandler(AutomationElement element, AutomationProperty property, AutomationPropertyChangedEventHandler eventHandler) { Log.Debug(); try { var events = (Hashtable)_controlElements[element];; if (events == null) { _controlElements.Add(element, new Hashtable()); events = (Hashtable)_controlElements[element]; } if (!events.Contains(property)) { Automation.AddAutomationPropertyChangedEventHandler(element, TreeScope.Element, onPropertyChanged, property); Log.Debug("Adding property changed event " + property.ProgrammaticName + ". AutomationID: " + (element.Current.AutomationId ?? "none")); var eventHandlerList = new List <AutomationPropertyChangedEventHandler>(); eventHandlerList.Add(eventHandler); events.Add(property, eventHandlerList); } else { var eventHandlerList = (List <AutomationPropertyChangedEventHandler>)events[property]; if (!eventHandlerList.Contains(eventHandler)) { Log.Debug("Registering event. " + property.ProgrammaticName + ". AutomationID: " + (element.Current.AutomationId ?? "none")); eventHandlerList.Add(eventHandler); } else { Log.Debug("Property change already registered. " + property.ProgrammaticName + ". AutomationID: " + (element.Current.AutomationId ?? "none")); } } } catch (Exception e) { Log.Exception(e); } }
public void Centerlize() { Applied = true; PropertyCondition isShell_TrayWnd = new PropertyCondition(AutomationElement.ClassNameProperty, Shell_TrayWnd); PropertyCondition isShell_SecondaryTrayWnd = new PropertyCondition(AutomationElement.ClassNameProperty, Shell_SecondaryTrayWnd); OrCondition condition = new OrCondition(isShell_TrayWnd, isShell_SecondaryTrayWnd); CacheRequest cacheRequest = new CacheRequest(); cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.BoundingRectangleProperty); _bars.Clear(); _children.Clear(); _lasts.Clear(); using (cacheRequest.Activate()) { AutomationElementCollection elements = Desktop.FindAll(TreeScope.Children, condition); if (elements == null) { return; } _lasts.Clear(); Parallel.ForEach(elements.OfType <AutomationElement>(), trayWnd => { //find taskbar AutomationElement taskbar = trayWnd.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, MSTaskListWClass)); if (taskbar != null) { propertyChangedHandler = OnUIAutomationEvent; Automation.AddAutomationPropertyChangedEventHandler(taskbar, TreeScope.Element, propertyChangedHandler, AutomationElement.BoundingRectangleProperty); _bars.Add(trayWnd); _children.Add(trayWnd, taskbar); repositionThreads[trayWnd] = Task.Run(() => LoopForReposition(trayWnd), loopCancellationTokenSource.Token); } }); } automationEventHandler = OnUIAutomationEvent; Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, Desktop, TreeScope.Subtree, automationEventHandler); Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, Desktop, TreeScope.Subtree, automationEventHandler); SystemEvents.DisplaySettingsChanging += SystemEvents_DisplaySettingsChanged; }
public void Z_PropertyEventTest() { var automationEventsArray = new [] { new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null } }; var automationEvents = automationEventsArray.ToList(); automationEvents.Clear(); AutomationPropertyChangedEventHandler handler = (o, e) => automationEvents.Add(new { Sender = o, Args = e }); SelectionItemPattern item1 = (SelectionItemPattern)child1Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern); item1.Select(); At.AddAutomationPropertyChangedEventHandler(treeView1Element, TreeScope.Subtree, handler, SelectionItemPattern.IsSelectedProperty); SelectionItemPattern item2 = (SelectionItemPattern)child2Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern); item2.Select(); Thread.Sleep(500); At.RemoveAutomationPropertyChangedEventHandler(treeView1Element, handler); if (Atspi) { Assert.AreEqual(2, automationEvents.Count, "event count"); Assert.AreEqual(child1Element, automationEvents [0].Sender, "event sender"); Assert.AreEqual(false, automationEvents [0].Args.NewValue, "new Value"); Assert.AreEqual(true, automationEvents [0].Args.OldValue, "old Value"); Assert.AreEqual(child2Element, automationEvents [1].Sender, "event sender"); Assert.AreEqual(true, automationEvents [1].Args.NewValue, "new Value"); Assert.AreEqual(false, automationEvents [1].Args.OldValue, "old Value"); } else { // TODO: This all seems wrong; test again with Windows 7 Assert.AreEqual(1, automationEvents.Count, "event count"); Assert.AreEqual(child2Element, automationEvents [0].Sender, "event sender"); Assert.AreEqual(true, automationEvents [0].Args.NewValue, "new Value"); Assert.IsNull(automationEvents [0].Args.OldValue, "old Value"); } automationEvents.Clear(); item1.Select(); Thread.Sleep(500); Assert.AreEqual(0, automationEvents.Count, "event count"); }
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 static void RemoveAutomationPropertyChangedEventHandler ( AutomationElement element, AutomationPropertyChangedEventHandler eventHandler) { ArgumentCheck.NotNull (element, "element"); ArgumentCheck.NotNull (eventHandler, "eventHandler"); if (element == AutomationElement.RootElement) foreach (var source in SourceManager.GetAutomationSources ()) source.RemoveAutomationPropertyChangedEventHandler ( null, eventHandler); else { var source = element.SourceElement.AutomationSource; source.RemoveAutomationPropertyChangedEventHandler ( element.SourceElement, eventHandler); } }
/// ------------------------------------------------------------------- /// <summary> /// Test that one can set the VisualState /// </summary> /// ------------------------------------------------------------------- internal void TS_SetWindowVisualState(AutomationElement element, WindowVisualState wvs, CheckType checkType) { AutomationPropertyChangedEventHandler handler; WindowPattern wp = ObtainWindowPattern(m_le, checkType); if (wp.Current.WindowVisualState != wvs) { // Want to wait till the BoundingRectangle changes to determine if the window changed Visual State handler = new AutomationPropertyChangedEventHandler(OnEvent); Automation.AddAutomationPropertyChangedEventHandler(element, TreeScope.Element, handler, new AutomationProperty[] { AutomationElement.BoundingRectangleProperty }); _gotNotifiedEvent.Reset(); // Set the new visual state wp.SetWindowVisualState(wvs); // Wait up to 5 seconds or until we get the event. If WaitOne returns false, the event was not fired. bool eventHappened = _gotNotifiedEvent.WaitOne(5000, true); // We don't need the event handler anymore, remove it Automation.RemoveAutomationPropertyChangedEventHandler(element, handler); // If the event did not happen, then log error if (!eventHappened) { ThrowMe(checkType, "BoundingRectangle property change event was not fired and should have. WindowState is set to {0}", wp.Current.WindowVisualState); } } m_TestStep++; }
public override void Add(WrappedEventHandler handler, AutomationElementWrapper element) { _element = element.Element; _handler = (o, e) => handler(element, e); Automation.AddAutomationPropertyChangedEventHandler(_element, _scope, _handler, _properties); }
public PropertyEventListener(AutomationEvent eventKind, AutomationElement element, AutomationPropertyChangedEventHandler handler) : base(AutomationElement.AutomationPropertyChangedEvent.Id, element.GetRuntimeId(), handler) { Debug.Assert(handler != null); this._propChangeHandler = handler; }
/// ----------------------------------------------------------------------- /// <summary></summary> /// ----------------------------------------------------------------------- void DetermineValidPosition(ScrollDirection direction, ref ArrayList array) { double priorPosition = -1; int TIMEOUT = 500; AutomationPropertyChangedEventHandler horzhandler = null; AutomationPropertyChangedEventHandler verthandler = null; _horizontalViewSize = pattern_getHorizontalViewSize; _horizontalScrollable = pattern_getHorizontallyScrollable; _verticalViewSize = pattern_getVerticalViewSize; _verticalScrollable = pattern_getVerticallyScrollable; // Do some excersise here to make sure we can make calls with no exceptions, // and to get some code coverage if (pattern_getVerticallyScrollable && pattern_getHorizontallyScrollable) { try { pattern_Scroll(ScrollAmount.SmallIncrement, ScrollAmount.SmallIncrement, null, CheckType.Verification); pattern_SetScrollPercent(0, 0, null, CheckType.Verification); } catch (TestErrorException) { } } else if (pattern_getHorizontallyScrollable && !pattern_getVerticallyScrollable) { try { pattern_Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount, null, CheckType.Verification); pattern_SetScrollPercent(0, -1, null, CheckType.Verification); } catch (TestErrorException) { } } else if (!pattern_getHorizontallyScrollable && pattern_getVerticallyScrollable) { try { pattern_Scroll(ScrollAmount.NoAmount, ScrollAmount.SmallIncrement, null, CheckType.Verification); pattern_SetScrollPercent(-1, 0, null, CheckType.Verification); } catch (TestErrorException) { } } // Need to wrap each call since some increments are not supported such as with LargeIncrement and the tab control switch (direction) { case ScrollDirection.Horizontal: // >>> Get 0 ResetScrollPosition(_ZERO, _NEGONE); ArrayListAdd(array, pattern_getHorizontalScrollPercent, false); // >>> Get 100 ResetScrollPosition(_HUNDRED, _NEGONE); ArrayListAdd(array, pattern_getHorizontalScrollPercent, false); // >>> Get SmallIncrement ResetScrollPosition(_ZERO, _NEGONE); horzhandler = new AutomationPropertyChangedEventHandler(ScrollHandler); Automation.AddAutomationPropertyChangedEventHandler( m_le, TreeScope.Element, horzhandler, new AutomationProperty[] { ScrollPattern.HorizontalScrollPercentProperty }); try { priorPosition = pattern_getHorizontalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getHorizontalScrollPercent) { _horizontalSmallIncrement = pattern_getHorizontalScrollPercent; ArrayListAdd(array, pattern_getHorizontalScrollPercent, false); } } catch (TestErrorException) { } // >>> Get LargeIncrement ResetScrollPosition(_ZERO, _NEGONE); try { priorPosition = pattern_getHorizontalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.LargeIncrement, ScrollAmount.NoAmount, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getHorizontalScrollPercent) { _horizontalLargeIncrement = pattern_getHorizontalScrollPercent; ArrayListAdd(array, pattern_getHorizontalScrollPercent, false); } } catch (TestErrorException) { } // >>> Get SmallDecrement ResetScrollPosition(_HUNDRED, _NEGONE); try { priorPosition = pattern_getHorizontalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.SmallDecrement, ScrollAmount.NoAmount, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getHorizontalScrollPercent) { _horizontalSmallDecrement = _HUNDRED - pattern_getHorizontalScrollPercent; ArrayListAdd(array, pattern_getHorizontalScrollPercent, false); } } catch (TestErrorException) { } // >>> Get LargeDecrement ResetScrollPosition(_HUNDRED, _NEGONE); try { priorPosition = pattern_getHorizontalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.LargeDecrement, ScrollAmount.NoAmount, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getHorizontalScrollPercent) { _horizontalLargeDecrement = _HUNDRED - pattern_getHorizontalScrollPercent; ArrayListAdd(array, pattern_getHorizontalScrollPercent, false); } } catch (TestErrorException) { } break; case ScrollDirection.Vertical: Comment("Determining valid Verical directions:"); verthandler = new AutomationPropertyChangedEventHandler(ScrollHandler); Automation.AddAutomationPropertyChangedEventHandler( m_le, TreeScope.Element, verthandler, new AutomationProperty[] { ScrollPattern.HorizontalScrollPercentProperty }); // >>> Get 0 ResetScrollPosition(_NEGONE, _ZERO); ArrayListAdd(array, pattern_getVerticalScrollPercent, false); // >>> Get 100 ResetScrollPosition(_NEGONE, _HUNDRED); ArrayListAdd(array, pattern_getVerticalScrollPercent, false); // >>> Get SmallIncrement ResetScrollPosition(_NEGONE, _ZERO); try { priorPosition = pattern_getVerticalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.NoAmount, ScrollAmount.SmallIncrement, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getVerticalScrollPercent) { _verticalSmallIncrement = pattern_getVerticalScrollPercent; ArrayListAdd(array, pattern_getVerticalScrollPercent, false); } } catch (TestErrorException) { } // Get LargeIncrement from 0 ResetScrollPosition(_NEGONE, _ZERO); try { priorPosition = pattern_getVerticalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.NoAmount, ScrollAmount.LargeIncrement, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getVerticalScrollPercent) { _verticalLargeIncrement = pattern_getVerticalScrollPercent; ArrayListAdd(array, pattern_getVerticalScrollPercent, false); } } catch (TestErrorException) { } // Get SmallDecrement from 100 ResetScrollPosition(_NEGONE, _HUNDRED); try { priorPosition = pattern_getVerticalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.NoAmount, ScrollAmount.SmallDecrement, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getVerticalScrollPercent) { _verticalSmallDecrement = _HUNDRED - pattern_getVerticalScrollPercent; ArrayListAdd(array, pattern_getVerticalScrollPercent, false); } } catch (TestErrorException) { } // Get LargeDecrement from 100 pattern_SetScrollPercent(_NEGONE, _HUNDRED, null, CheckType.Verification); try { priorPosition = pattern_getVerticalScrollPercent; pattern_ScrollWithEvent(ScrollAmount.NoAmount, ScrollAmount.LargeDecrement, TIMEOUT, CheckType.Verification); if (priorPosition != pattern_getVerticalScrollPercent) { _verticalLargeDecrement = _HUNDRED - pattern_getVerticalScrollPercent; ArrayListAdd(array, pattern_getVerticalScrollPercent, false); } } catch (TestErrorException) { } break; default: throw new Exception("Unhandled argument"); } // Now get x random elements between SmallDecrement and SmallIncrement if (array.Count > 3) { array.Sort(); double min = (double)array[0]; double max = (double)array[array.Count - 1]; double loc = -1, loc2 = -1; for (int i = 0; i < 5; i++) { loc = (double)Helpers.RandomValue(min, max); if (direction.Equals(ScrollDirection.Horizontal)) { // WCP: HorizontalScrollPercent = loc; pattern_SetScrollPercent(loc, _NEGONE, null, CheckType.Verification); if (_notifiedEvent.WaitOne(TIMEOUT, false)) loc = pattern_getHorizontalScrollPercent; //patternScroll may jump to near position // Make sure we can duplicate this. pattern_SetScrollPercent(loc, _NEGONE, null, CheckType.Verification); if (_notifiedEvent.WaitOne(TIMEOUT, false)) loc2 = pattern_getHorizontalScrollPercent; if (loc == loc2) { if (array.IndexOf(loc).Equals(-1)) { System.Diagnostics.Trace.WriteLine("H:" + loc); ArrayListAdd(array, loc, false); } } } else { // WCP: VerticalScrollPercent = loc; _notifiedEvent.Reset(); pattern_SetScrollPercent(_NEGONE, loc, null, CheckType.Verification); if (_notifiedEvent.WaitOne(TIMEOUT, false)) loc = pattern_getVerticalScrollPercent; //patternScroll may jump to near position // Make sure we can duplicate this. _notifiedEvent.Reset(); pattern_SetScrollPercent(_NEGONE, loc, null, CheckType.Verification); if (_notifiedEvent.WaitOne(TIMEOUT, false)) loc2 = pattern_getVerticalScrollPercent; //patternScroll may jump to near position if (loc == loc2) if (array.IndexOf(loc).Equals(-1)) { System.Diagnostics.Trace.WriteLine("V:" + loc); ArrayListAdd(array, loc, false); } } } } array.Sort(); foreach (object l in array) { Comment(" Found : " + l.ToString()); } if (horzhandler != null) Automation.RemoveAutomationPropertyChangedEventHandler(m_le, horzhandler); if (verthandler != null) Automation.RemoveAutomationPropertyChangedEventHandler(m_le, verthandler); }
public void AddAutomationPropertyChangedEventHandler (IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty [] properties) { PropertyChangedEventHandlerData data = new PropertyChangedEventHandlerData ( element, scope, eventHandler, properties); propertyEventHandlers.Add (data); }
public static void AddAutomationPropertyChangedEventHandler (AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, params AutomationProperty [] properties) { ArgumentCheck.NotNull (element, "element"); ArgumentCheck.NotNull (eventHandler, "eventHandler"); if (element == AutomationElement.RootElement) foreach (var source in SourceManager.GetAutomationSources ()) source.AddAutomationPropertyChangedEventHandler ( null, scope, eventHandler, properties); else { var source = element.SourceElement.AutomationSource; source.AddAutomationPropertyChangedEventHandler ( element.SourceElement, scope, eventHandler, properties); } }
/// <summary> /// Called by a client to add a listener for property changed events. /// </summary> /// <param name="element">Element on which to listen for property changed events.</param> /// <param name="scope">Specifies whether to listen to property changes events on the specified element, and/or its ancestors and children.</param> /// <param name="eventHandler">Callback object to call when a specified property change occurs.</param> /// <param name="properties">Params array of properties to listen for changes in.</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void AddAutomationPropertyChangedEventHandler( AutomationElement element, // reference element for listening to the event TreeScope scope, // scope to listen to AutomationPropertyChangedEventHandler eventHandler, // callback object params AutomationProperty [] properties // listen for changes to these properties ) { Misc.ValidateArgumentNonNull(element, "element" ); Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" ); Misc.ValidateArgumentNonNull(properties, "properties" ); if (properties.Length == 0) { throw new ArgumentException( SR.Get(SRID.AtLeastOnePropertyMustBeSpecified) ); } // Check that no properties are interpreted properties // foreach (AutomationProperty property in properties) { Misc.ValidateArgumentNonNull(property, "properties" ); } // Add a client-side listener for for this event request EventListener l = new EventListener(AutomationElement.AutomationPropertyChangedEvent, scope, properties, CacheRequest.CurrentUiaCacheRequest); ClientEventManager.AddListener(element, eventHandler, l); }
public static void RemoveAutomationPropertyChangedEventHandler(AutomationElement element, AutomationPropertyChangedEventHandler eventHandler) { Utility.ValidateArgumentNonNull(element, "element"); Utility.ValidateArgumentNonNull(eventHandler, "eventHandler"); try { PropertyEventListener listener = (PropertyEventListener)ClientEventList.Remove(AutomationElement.AutomationPropertyChangedEvent, element, eventHandler); Factory.RemovePropertyChangedEventHandler(element.NativeElement, listener); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
//TODO While recording you get exception when clicking at the corner of the cell public override void HookEvents(UIItemEventListener eventListener) { var safeAutomationEventHandler = new SafeAutomationEventHandler(this, eventListener, objs => ListViewEvent.Create(this, (AutomationPropertyChangedEventArgs) objs[0])); handler = safeAutomationEventHandler.PropertyChange; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Descendants, handler, SelectionItemPattern.IsSelectedProperty); }
internal PropertyChangedEventHandlerData (IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty [] properties) { this.Element = element; this.Scope = scope; this.EventHandler = eventHandler; this.Properties = properties; }
public override void HookEvents(UIItemEventListener eventListener) { lastSelectedItem = SelectedItem; handler = delegate(object sender, AutomationPropertyChangedEventArgs e) { if (SelectedItem == null || e.NewValue.Equals(1)) return; if (SameListItem()) return; lastSelectedItem = SelectedItem; eventListener.EventOccured(new ComboBoxEvent(this, SelectedItemText)); }; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Element, handler, ExpandCollapsePattern.ExpandCollapseStateProperty); }
public void RemoveAutomationPropertyChangedEventHandler (IElement element, AutomationPropertyChangedEventHandler eventHandler) { int handlerId = eventHandlerManager.GetPropertyEventIdByHandler (eventHandler); if (handlerId == -1) return; if (element == null) { //the element is the RootElement RootElementEventsManager.RemovePropertyEventRequest (handlerId); foreach (var entry in GetUiaApplications ()) entry.Value.RemoveRootElementAutomationPropertyChangedEventHandler (handlerId); } else { UiaDbusElement uiaDbusElement = element as UiaDbusElement; if (uiaDbusElement == null) { Log.Error ("[RemoveAutomationPropertyChangedEventHandler] " + "The element sent to UiaDbusSource is not UiaDbusElement"); return; } string busName = uiaDbusElement.BusName; DCI.IApplication app = Bus.Session.GetObject<DCI.IApplication> (busName, new ObjectPath (DC.Constants.ApplicationPath)); int [] runtimeId = uiaDbusElement.RuntimeId; app.RemoveAutomationPropertyChangedEventHandler (runtimeId, handlerId); } }
public void RemoveAutomationPropertyChangedEventHandler (IElement element, AutomationPropertyChangedEventHandler eventHandler) { if (element == null) return; ClientElement clientElement = element as ClientElement; if (clientElement == null) { Log.Error ("[ClientAutomationSource.RemoveAutomationPropertyChangedEventHandler] Not ClientElement"); return; } ClientEventManager.RemoveAutomationPropertyChangedEventHandler ( clientElement.Provider, eventHandler); }
/// ------------------------------------------------------------------- /// <summary> /// Method that registers the event handler OnEvent() /// </summary> /// ------------------------------------------------------------------- public void AddEventHandler(AutomationElement element, TreeScope treeScope, AutomationProperty[] properties) { base.AddEventHandler(); StringBuilder sb = new StringBuilder("["); string divider = ", "; foreach (AutomationProperty prop in properties) { sb.Append(prop.ProgrammaticName); sb.Append(divider); } if (sb.Length > 0) { sb.Remove(sb.Length - divider.Length, divider.Length).Append("]"); } Comment("Adding AddAutomationPropertyChangedEventHandler({0}, TreeScope.{1}, {2}) ControlPath = {3}", Library.GetUISpyLook(element), treeScope.ToString(), sb.ToString(), Helpers.GetXmlPathFromAutomationElement(element)); handler = new AutomationPropertyChangedEventHandler(OnEvent); Automation.AddAutomationPropertyChangedEventHandler(element, treeScope, handler, properties); }
/// <summary> /// Register for events of interest. /// </summary> /// <param name="ae">The automation element of interest.</param> /// <param name="ap">The control pattern of interest.</param> /// <param name="ts">The tree scope of interest.</param> private void RegisterForEvents(AutomationElement ae, AutomationPattern ap, TreeScope ts) { if (ap.Id == WindowPattern.Pattern.Id) { // The WindowPattern Exposes an element's ability // to change its on-screen position or size. // The following code shows an example of listening for the // BoundingRectangle property changed event on the window. Feedback("Start listening for WindowMove events for the control."); // Define an AutomationPropertyChangedEventHandler delegate to // listen for window moved events. var moveHandler = new AutomationPropertyChangedEventHandler(OnWindowMove); Automation.AddAutomationPropertyChangedEventHandler( ae, ts, moveHandler, AutomationElement.BoundingRectangleProperty); } }
public PropertyChangedEventEntry (IRawElementProviderSimple provider, TreeScope scope, int [] properties, AutomationPropertyChangedEventHandler handler) : base (provider, scope) { this.Properties = properties; this.Handler = handler; }
public override void HookEvents(UIItemEventListener eventListener) { handler = delegate { eventListener.EventOccured(new TextBoxEvent(this)); }; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Element, handler, ValuePattern.ValueProperty); }
public override void HookEvents(UIItemEventListener eventListener) { clickedTreeNodeHandler = delegate { TreeNode node = ClickedNode; eventListener.EventOccured((new TreeNodeClickedEvent(this, node, node.IsExpanded()))); }; selectedTreeNodeHandler = delegate { TreeNode node = SelectedNode; eventListener.EventOccured((new TreeNodeSelectEvent(this, node))); }; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Subtree, clickedTreeNodeHandler, ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty); Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Subtree, selectedTreeNodeHandler, SelectionItemPatternIdentifiers.IsSelectedProperty); }
/// <summary> /// Called by a client to remove a listener for property changed events. /// </summary> /// <param name="element">Element to remove listener for</param> /// <param name="eventHandler">The handler object that was passed to AutomationPropertyChangedEventHandler</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void RemoveAutomationPropertyChangedEventHandler( AutomationElement element, // reference element being listened to AutomationPropertyChangedEventHandler eventHandler // callback object (used as cookie here) ) { Misc.ValidateArgumentNonNull(element, "element" ); Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" ); //CASRemoval:AutomationPermission.Demand( AutomationPermissionFlag.Read ); // Remove the client-side listener for for this event ClientEventManager.RemoveListener(AutomationElement.AutomationPropertyChangedEvent, element, eventHandler); }
public override void HookEvents(UIItemEventListener eventListener) { handler = delegate { eventListener.EventOccured(new TabEvent(this)); }; Automation.AddAutomationPropertyChangedEventHandler(automationElement, TreeScope.Descendants, handler, SelectionItemPattern.IsSelectedProperty); }
public void RemoveAutomationPropertyChangedEventHandler (IElement element, AutomationPropertyChangedEventHandler eventHandler) { List<PropertyChangedEventHandlerData> handlersToDelete = new List<PropertyChangedEventHandlerData> (); foreach (var handlerData in propertyEventHandlers) { if (handlerData.Element == element && handlerData.EventHandler == eventHandler) { handlersToDelete.Add (handlerData); } } foreach (var h in handlersToDelete) propertyEventHandlers.Remove (h); }
public void AddAutomationPropertyChangedEventHandler (IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty [] properties) { int [] propertyIds = new int [properties.Length]; for (int i = 0; i < properties.Length; i++) propertyIds [i] = properties [i].Id; if (element == null) { //the element is the RootElement // TODO clean up registered handlers when they're removed int handlerId = eventHandlerManager.RegisterPropertyEventHandler (eventHandler); RootElementEventsManager.AddPropertyEventRequest (scope, handlerId, propertyIds); foreach (var entry in GetUiaApplications ()) { string busName = entry.Key; var app = entry.Value; EnsurePropertyEventsSetUp (app, busName); app.AddRootElementAutomationPropertyChangedEventHandler ( scope, handlerId, propertyIds); } } else { UiaDbusElement uiaDbusElement = element as UiaDbusElement; if (uiaDbusElement == null) { Log.Error ("[AddAutomationPropertyChangedEventHandler] The element sent to UiaDbusSource is not UiaDbusElement"); return; } string busName = uiaDbusElement.BusName; DCI.IApplication app = Bus.Session.GetObject<DCI.IApplication> (busName, new ObjectPath (DC.Constants.ApplicationPath)); int [] runtimeId = uiaDbusElement.RuntimeId; int handlerId = eventHandlerManager.RegisterPropertyEventHandler (eventHandler); EnsurePropertyEventsSetUp (app, busName); app.AddAutomationPropertyChangedEventHandler (runtimeId, scope, handlerId, propertyIds); } }