/// ------------------------------------------------------------------- /// <summary></summary> /// ------------------------------------------------------------------- internal static bool Equals(EventItem newEvent, EventItem storedEvent) { // WindowClosedEvent does not pass the element in as it is gone... if (newEvent.m_le == null && storedEvent.m_le == null) { if (((AutomationEventArgs)newEvent.m_EventArg).EventId != storedEvent.m_EventArg) { return(false); } else { return(true); } } if (Automation.Compare(newEvent.m_le, storedEvent.m_le)) { if (newEvent.m_EventArg is AutomationFocusChangedEventArgs && (storedEvent.m_EventArg == null)) { return(true); } else { if (((newEvent.m_EventArg == null) || (storedEvent.m_EventArg == null))) { return(false); } else { object obj = newEvent.m_EventArg; if (obj.GetType().Equals(typeof(AutomationPropertyChangedEventArgs))) { return(((AutomationPropertyChangedEventArgs)obj).Property == storedEvent.m_EventArg); } else { if (obj.GetType().Equals(typeof(AutomationEventArgs))) { return(((AutomationEventArgs)obj).EventId == storedEvent.m_EventArg); } else { if (obj.GetType().Equals(typeof(StructureChangedEventArgs))) { return(((StructureChangedEventArgs)(obj)).StructureChangeType == (StructureChangeType)storedEvent.m_EventArg); } return(false); } } } } } else { return(false); } }
public override bool Equals(object obj) { EventListener listener = obj as EventListener; return(listener != null && this._eventId == listener.EventId && this._handler == listener.Handler && Automation.Compare(this._runtimeId, listener.RuntimeId)); }
public void CompareTest() { AutomationElement el1 = GetTaskbar(); AutomationElement el2 = GetTaskbar(); Assert.IsTrue(Automation.Compare((AutomationElement)null, (AutomationElement)null)); Assert.IsFalse(Automation.Compare(null, el1)); Assert.IsFalse(Automation.Compare(el1, null)); Assert.IsTrue(Automation.Compare(el1, el2)); Assert.IsTrue(Automation.Compare(el1.GetRuntimeId(), el2.GetRuntimeId())); }
private static IntPtr WindowListed(int[] runtimeId) { for (int i = 0; i < windowList.Count; i++) { int[] listedId = windowList[i].AutomationElement.GetRuntimeId(); if (Automation.Compare(listedId, runtimeId)) { return(windowList[i].Hwnd); } } return(IntPtr.Zero); }
/* * the first one listens for "window opened" events * this catches when the checkout window opens. * * that way we can do 2 things: * 1: catch it when it closes (letting the caller know the window closed) and * 2: hide the "enter serial number" button because their UI for it isn't that great * and we want to support silent activation anyway (by gathering the info first * with our own UI) */ private void RegisterEventListeners() { Automation.AddAutomationEventHandler( WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Children, (sender, e) => { AutomationElement element = sender as AutomationElement; string automationID = element.Current.AutomationId; if (automationID != kLicenseWindowAutomationID) { return; } i_checkoutWindID = element.GetRuntimeId(); if (!i_showEnterSerialNumberB) { AutomationElement licenseButton = element.FindFirst( TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, kLicenseButtonAutomationID)); if (licenseButton != null) { IntPtr hwnd = new IntPtr(licenseButton.Current.NativeWindowHandle); Control buttonRef = Control.FromHandle(hwnd); HideButton_Safe(buttonRef); } } }); Automation.AddAutomationEventHandler( WindowPattern.WindowClosedEvent, AutomationElement.RootElement, TreeScope.Subtree, (sender, e) => { WindowClosedEventArgs args = e as WindowClosedEventArgs; int[] closingWindID = args.GetRuntimeId(); if (i_checkoutWindID != null && closingWindID != null) { if (Automation.Compare(closingWindID, i_checkoutWindID)) { Array.Clear(i_checkoutWindID, 0, i_checkoutWindID.Length); Paddle_CheckoutWindowClosed(); } } }); }
/// ------------------------------------------------------------------- /// <summary> /// Test step to verify that automation elements are same /// </summary> /// ------------------------------------------------------------------- void TS_AreTheseTheSame(AutomationElement le1, AutomationElement le2, bool ShouldTheyBe, CheckType ct) { Comment("Comparing AutomationElements (" + Library.GetUISpyLook(le1) + ") and (" + Library.GetUISpyLook(le2) + ")"); bool results = Automation.Compare(le1, le2).Equals(ShouldTheyBe); if (!results) { ThrowMe(ct, "Compare(" + Library.GetUISpyLook(le1) + ", " + Library.GetUISpyLook(le2) + ") = " + results + " but should be " + ShouldTheyBe); } Comment("Compare(" + Library.GetUISpyLook(le1) + ", " + Library.GetUISpyLook(le2) + ") == " + ShouldTheyBe); m_TestStep++; }
/// <summary> /// Ascertains whether the window is in the list. /// </summary> /// <param name="rid">Runtime ID of the window.</param> /// <returns>Index of the ID in the list, or -1 if it is not listed.</returns> /// <remarks> /// runtimteIds is an ArrayList that contains the runtime IDs of all top-level windows. /// </remarks> // <Snippet103> private int RuntimeIdListed(int[] runtimeId, ArrayList runtimeIds) { for (int x = 0; x < runtimeIds.Count; x++) { int[] listedId = (int[])runtimeIds[x]; if (Automation.Compare(listedId, runtimeId)) { return(x); } } return(-1); }
/// ------------------------------------------------------------------- /// <summary> /// Event handler /// </summary> /// ------------------------------------------------------------------- private void ExpandCollapseEventHandler(object src, AutomationPropertyChangedEventArgs arguments) { if (Automation.Compare((AutomationElement)src, _element)) { if (arguments.Property == ExpandCollapsePattern.ExpandCollapseStateProperty) { if (_desiredState == (ExpandCollapseState)arguments.NewValue) { _ev.Set(); } } } }
public void SpreadsheetPatternTest() { // Get the pattern SpreadsheetPattern pattern = (SpreadsheetPattern)mockObject.GetCurrentPattern(SpreadsheetPattern.Pattern); // Test it AutomationElement result = pattern.GetItemByName("primary"); Assert.IsNotNull(result); Assert.IsTrue(Automation.Compare(this.mockObject, result)); Assert.IsNull(pattern.GetItemByName("secondary")); }
public override bool Equals(object obj) { var uiObject = obj as UIObject; if (!(uiObject != null)) { return(base.Equals(obj: obj)); } try { return(Automation.Compare(el1: AutomationElement, el2: uiObject.AutomationElement)); } catch (COMException ex) { return(false); } }
bool ICollection <I> .Contains(I item) { Validate.ArgumentNotNull(parameter: item, parameterName: nameof(item)); var automationElement = item.AutomationElement; foreach (var el2 in Navigator) { if (Automation.Compare(el1: automationElement, el2: el2)) { return(true); } } return(false); }
public void TextChildPatternTest() { // Get the pattern TextChildPattern pattern = (TextChildPattern)mockObject.GetCurrentPattern(TextChildPattern.Pattern); // Test it AutomationElement container = pattern.TextContainer; Assert.IsTrue(Automation.Compare(this.mockObject, container)); System.Windows.Automation.Text.TextPatternRange childRange; childRange = pattern.TextRange; Assert.IsNotNull(childRange); Assert.AreEqual("fromChild", childRange.GetText(-1)); }
public override IEnumerator <AutomationElement> GetEnumerator() { var siblingsNavigator = this; var filter = siblingsNavigator.Filter; AutomationElement current; for (current = siblingsNavigator._treeWalker.GetFirstChild(element: siblingsNavigator._treeWalker.GetParent(element: siblingsNavigator._root)); current != (AutomationElement)null; current = siblingsNavigator._treeWalker.GetNextSibling(element: current)) { if (!Automation.Compare(el1: current, el2: siblingsNavigator._root) && filter.Matches(element: current)) { yield return(current); } } current = null; }
protected override bool Matches(WaiterEventArgs eventArgs) { var eventArgs1 = (StructureChangedEventArgs)eventArgs.EventArgs; var flag = false; if (eventArgs1.StructureChangeType == StructureChangeType.ChildRemoved) { flag = true; if (this._runtimeId != null) { flag = Automation.Compare(runtimeId1: eventArgs1.GetRuntimeId(), runtimeId2: this._runtimeId); } } return(flag); }
internal IRawElementProviderSimple FindProviderByRuntimeId(int [] runtimeId) { lock (providerWrapperMapping) { foreach (var provider in providerWrapperMapping.Keys) { int [] rid = (int [])provider.GetPropertyValue( AutomationElementIdentifiers.RuntimeIdProperty.Id); if (Automation.Compare(rid, runtimeId)) { return(provider); } } } return(null); }
public void DragPatternTest() { // Get the pattern DragPattern pattern = (DragPattern)mockObject.GetCurrentPattern(DragPattern.Pattern); // Test it Assert.AreEqual(true, pattern.Current.IsGrabbed); Assert.AreEqual("Copy", pattern.Current.DropEffect); Assert.AreEqual(2, pattern.Current.DropEffects.Length); Assert.AreEqual("Copy", pattern.Current.DropEffects[0]); Assert.AreEqual("Move", pattern.Current.DropEffects[1]); AutomationElement[] grabbedItems = pattern.Current.GrabbedItems; Assert.AreEqual(2, grabbedItems.Length); Assert.IsTrue(Automation.Compare(this.mockObject, grabbedItems[0])); Assert.IsTrue(Automation.Compare(this.mockObject, grabbedItems[1])); }
public void SpreadsheetItemPatternTest() { // Get the pattern SpreadsheetItemPattern pattern = (SpreadsheetItemPattern)mockObject.GetCurrentPattern(SpreadsheetItemPattern.Pattern); // Test it Assert.AreEqual("E=mc^2", pattern.Current.Formula); AutomationElement [] annotationObjects = pattern.Current.GetAnnotationObjects(); Assert.AreEqual(2, annotationObjects.Length); Assert.IsTrue(Automation.Compare(this.mockObject, annotationObjects[0])); Assert.IsTrue(Automation.Compare(this.mockObject, annotationObjects[1])); AnnotationType[] annotationTypes = pattern.Current.GetAnnotationTypes(); Assert.AreEqual(2, annotationTypes.Length); Assert.AreEqual(AnnotationType.SpellingError, annotationTypes[0]); Assert.AreEqual(AnnotationType.GrammarError, annotationTypes[1]); }
public void AnnotationPatternTest() { // Get the annotation pattern object patternAsObj; AnnotationPattern pattern; mockObject.TryGetCurrentPattern(AnnotationPattern.Pattern, out patternAsObj); Assert.IsNotNull(patternAsObj); pattern = (AnnotationPattern)patternAsObj; // Test it Assert.AreEqual(AnnotationType.Comment, pattern.Current.AnnotationTypeId); Assert.AreEqual("Comment", pattern.Current.AnnotationTypeName); Assert.AreEqual("John Doe", pattern.Current.Author); Assert.AreEqual("July 4, 1776", pattern.Current.DateTime); Assert.IsTrue(Automation.Compare(this.mockObject, pattern.Current.Target)); }
public int IndexOf(I item) { Validate.ArgumentNotNull(parameter: item, parameterName: nameof(item)); Validate.ArgumentNotNull(parameter: item.AutomationElement, parameterName: "item.AutomationElement"); var automationElement = item.AutomationElement; var num = -1; foreach (var el2 in Navigator) { ++num; if (Automation.Compare(el1: automationElement, el2: el2)) { return(num); } } throw new UIObjectNotFoundException(searchDomain: ToString(), uiObject: item); }
internal static IList <IInputAction> PreventAccidentalDoubleClick( double x, double y, ref int[] previousRuntimeId) { var inputActionList = new List <IInputAction>(); var runtimeId = AutomationElement.FromPoint(pt: new Point(x: x, y: y)).GetRuntimeId(); var duration = 550; if (previousRuntimeId != null && Automation.Compare(runtimeId1: previousRuntimeId, runtimeId2: runtimeId)) { inputActionList.Add(item: CreateWait(duration: duration)); } else { previousRuntimeId = runtimeId; } return(inputActionList); }
/// <summary> /// Gets control information for .Net controls /// </summary> /// <param name="focusedElement">The focused element.</param> private void ProcessTargetControl(AutomationElement focusedElement) { TsInteractions.DropDownItems.Clear(); foreach (MappedControl item in _thisWindow.AllFormsControls) { if (!Automation.Compare(item.AutoElement, focusedElement)) { continue; } PropControls.SelectedObject = item; _selectedControl = item; break; } Painter.PaintTarget(focusedElement, _focusedApplicationHandle); UpdateAutomationDisplay(focusedElement); }
/// ------------------------------------------------------------------- /// <summary> /// Check the IsOffScreen property, and that FromPoint(pt) == element where point /// was obtained from TryClickablePoint /// </summary> /// ------------------------------------------------------------------- private void TS_VerifyElementIsOnScreenAndNotOverlapped(AutomationElement element, CheckType checkType) { if (true == element.Current.IsOffscreen) { ThrowMe(checkType, "IsOffScreen == true"); } Point pt = new Point(); if (false == element.TryGetClickablePoint(out pt)) { ThrowMe(checkType, "TryGetClickablePoint() returned false"); } if (false == Automation.Compare(element, AutomationElement.FromPoint(pt))) { ThrowMe(checkType, "Could not get element from pt{0}, could the element be covered by another window?", pt); } m_TestStep++; }
/// <summary> /// Compares the two automation elements and returns if /// they are identical or not /// </summary> /// <param name="ele1">first element</param> /// <param name="ele2">second element</param> /// <returns></returns> public static bool IsDifferent(AutomationElement ele1, AutomationElement ele2) { bool retVal; if (ele1 == null || ele2 == null) { return(true); } try { retVal = !Automation.Compare(ele1.GetRuntimeId(), ele2.GetRuntimeId()); } catch { retVal = true; } Log.Debug(retVal ? "YES" : "NO"); return(retVal); }
/// <summary> /// Compares two elements. /// </summary> public bool Equals(AutomationElement other) { return(other != null && Automation.Compare(this, other)); }
/// ------------------------------------------------------------------- /// <summary> /// Called by the inheriting EventFramework class to determine if an event has been fired /// </summary> /// ------------------------------------------------------------------- internal static EventFired WasEventFired(EventItem eventItem) { if (_waitedForEventToFire == false) { throw new Exception("Did not wait for event to happen. Call TSC_WaitForEvents() first"); } if (_eventList == null) { return(EventFired.False); } string eventName = string.Empty; if (eventItem.m_EventArg != null) { if (eventItem.m_EventArg is StructureChangeType) { eventName = eventItem.m_EventArg.ToString(); } else if (eventItem.m_EventArg is AutomationIdentifier) { eventName = ((AutomationIdentifier)(eventItem.m_EventArg)).ProgrammaticName; } } else { eventName = "AutomationFocusChangedEvent"; } Comment(_eventList.Count + " was/were fired"); for (int index = 0; (index < _eventList.Count); index++) { EventItem tempEventItem = (EventItem)_eventList[index]; // Focused events are a bit complex. You can set focus to a combobox with // and edit window and the edit window is the one that gets the focus...so // need to search up tree and see if it or one of it's parent controls // received the focus. Since we cannot instantiate an AutomationFocusChangedEventArgs // we set it to null and this is the flag to tell us that we are testing focus change // events if (eventItem.m_EventArg == null & tempEventItem.m_EventArg is AutomationFocusChangedEventArgs) // focus event { AutomationElement eventListElement = tempEventItem.m_le; while (!Automation.Compare(eventListElement, AutomationElement.RootElement) && !Automation.Compare(eventListElement, eventItem.m_le)) { eventListElement = TreeWalker.ControlViewWalker.GetParent(eventListElement); } if (Automation.Compare(eventListElement, eventItem.m_le)) { return(EventFired.True); } } else { if (EventItem.Equals(tempEventItem, eventItem)) { { Comment("{0} was fired on ({1})", eventName, Library.GetUISpyLook(eventItem.m_le)); return(EventFired.True); } } } } Comment(eventName + " was not fired"); return(EventFired.False); }