public static string ToIdOrName(this AutomationIdentifier automationIdentifier) { return(string.Format("AutomationName: {0}, ElementName : {1}, DisplayText: {2}", automationIdentifier.AutomationName, automationIdentifier.ElementName, automationIdentifier.DisplayedText)); }
protected override void DoImpl() { var element = GetFrameworkElementParent <ListBoxItem>(); if (element == null) { SendNotFoundResult(string.Format("ListBoxItemScrollIntoViewCommand: Could not find element : {0}", AutomationIdentifier.ToIdOrName())); return; } element.InvokeAutomationPeer <ListBoxItem, IScrollItemProvider>(PatternInterface.Selection, (pattern) => { try { pattern.ScrollIntoView(); } catch (Exception exception) { throw new TestAutomationException ("Exception while invoking list box select pattern", exception); } }); }
private RectangleF GetPositionOfAutomationIdentifier(AutomationIdentifier controlIdentifier, int ordinal, AutomationIdentifier parentIdentifier) { var command = new GetPositionCommand { AutomationIdentifier = controlIdentifier, Ordinal = ordinal, ParentIdentifier = parentIdentifier }; var result = SyncExecuteCommand(command); var positionResult = result as PositionResult; if (positionResult == null) { // TODO - should log the result here really return(RectangleF.Empty); } return(new RectangleF( (float)positionResult.Left, (float)positionResult.Top, (float)positionResult.Width, (float)positionResult.Height)); }
protected override void DoImpl() { var element = GetFrameworkElement(); if (element == null) { element = (FrameworkElement) AutomationElementFinder.FindElementByDisplayedText(AutomationIdentifier.AutomationName); } if (element != null) { //Find out its background color if (element is Border) { var elementControl = (Border)element; if (elementControl.Background is SolidColorBrush) { SendColorResult(((SolidColorBrush)elementControl.Background).Color.ToString()); return; } } } SendNotFoundResult(string.Format("GetColorCommand: Could not find the element - {0}", AutomationIdentifier.ToIdOrName())); }
protected override void DoImpl() { var element = GetFrameworkElement(); if (element == null) { return; } string textValue; if (ValueCommandHelper.TryGetValue(element, out textValue)) { SendTextResult(textValue); return; } var value = AutomationElementFinder.GetValueForFrameworkElement(element); if (value != null) { SendTextResult(value); return; } // if text is missing... then give up SendNotFoundResult(string.Format("GetValueCommand: Could not find the element : {0}", AutomationIdentifier.ToIdOrName())); }
public static void CheckPatternIdentifiers <T> () where T : BasePattern { Type patternType = typeof(T); Type patternIdsType = typeof(AutomationElementIdentifiers).Assembly.GetType (patternType.FullName + "Identifiers"); foreach (var fieldInfo in patternType.GetFields (BindingFlags.Public | BindingFlags.Static)) { string fieldName = fieldInfo.Name; if (fieldName == "Pattern" || fieldName.EndsWith("Property") || fieldName.EndsWith("Event")) { AutomationIdentifier value1 = fieldInfo.GetValue(null) as AutomationIdentifier; var fieldInfo2 = patternIdsType.GetField(fieldName, BindingFlags.Public | BindingFlags.Static); AutomationIdentifier value2 = fieldInfo2.GetValue(null) as AutomationIdentifier; Assert.AreEqual(value2.Id, value1.Id, string.Format("{0}.{1}.Id", patternType.Name, fieldName) ); Assert.AreEqual(value2.ProgrammaticName, value1.ProgrammaticName, string.Format("{0}.{1}.ProgrammaticName", patternType.Name, fieldName) ); } } }
protected override void DoImpl() { var element = GetUIElement(); if (element == null) { return; } if (AutomationElementFinder.SetElementProperty(element, "Text", Text)) { SendSuccessResult(); return; } if (AutomationElementFinder.SetElementProperty(element, "Password", Text)) { SendSuccessResult(); return; } if (AutomationElementFinder.SetElementProperty <object>(element, "Content", Text)) { SendSuccessResult(); return; } // if text, password and content are all missing... then give up SendNotFoundResult(string.Format("SetTextCommand: Could not set text :{0} for control :{1}", Text, AutomationIdentifier.ToIdOrName())); }
public static UIElement FindElement(AutomationIdentifier controlIdentifier, int ordinal = 0, AutomationIdentifier parentIdentifier = null) { // get the parent element as uielement var rootVisual = GetRootVisual(); var parent = parentIdentifier == null ? rootVisual : FindElementsNearestParentOfType <UIElement>(rootVisual, parentIdentifier); // get the control that is a child of parent as uielement var control = FindElementsNearestParentOfType <UIElement>(parent, controlIdentifier, ordinal); return(control); }
internal static bool GetPropertyTypeInfo(AutomationIdentifier id, out PropertyTypeInfo info) { foreach (PropertyTypeInfo info2 in _propertyInfoTable) { if (info2.ID == id) { info = info2; return(true); } } info = null; return(false); }
public void TestSetValue127(TestCaseAttribute testCase) { HeaderComment(testCase); AutomationIdentifier ai = m_le.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) as AutomationIdentifier; if (ai == ControlType.Calendar) { SetValue_SetToRandomValue(ObjectTypes.Date, false, false, true, true, true, EventFired.True, null); } else { SetValue_SetToRandomValue(ObjectTypes.DateTime, false, false, true, true, true, EventFired.True, null); } }
private bool SetValueOnAutomationIdentification(AutomationIdentifier controlIdentifier, string textValue, int ordinal, AutomationIdentifier parentIdentifier) { var command = new SetValueCommand { AutomationIdentifier = controlIdentifier, TextValue = textValue, Ordinal = ordinal, ParentIdentifier = parentIdentifier }; var result = SyncExecuteCommand(command); var successResult = result as SuccessResult; return(successResult != null); }
protected UIElement GetUIElement(bool sendNotFoundResultOnFail = true) { var element = AutomationElementFinder.FindElement(AutomationIdentifier, Ordinal, ParentIdentifier); if (element == null) { if (sendNotFoundResultOnFail) { SendNotFoundResult(string.Format("GetUIElement: Could not find - {0}", AutomationIdentifier.ToIdOrName())); } return(null); } return(element); }
public static UIElement FindElementsNearestParentOfType <TParentType>(UIElement root, AutomationIdentifier identifier, int index = 0) where TParentType : UIElement { if (!string.IsNullOrEmpty(identifier.AutomationName)) { var candidate = FindElementsNearestParentByAutomationProperty <TParentType>(root, identifier.AutomationName, index); if (candidate != null) { return(candidate); } } if (!string.IsNullOrEmpty(identifier.AutomationName)) { var candidate = FindElementsNearestParentByAutomationTag <TParentType>(root, identifier.AutomationName); if (candidate != null) { return(candidate); } } if (!string.IsNullOrEmpty(identifier.ElementName)) { var candidate = FindElementsNearestParentByElementName <TParentType>(root, identifier.ElementName, index); if (candidate != null) { return(candidate); } } if (!string.IsNullOrEmpty(identifier.DisplayedText)) { var candidate = FindElementsNearestParentByDisplayedText <TParentType>(root, identifier.DisplayedText); if (candidate != null) { return(candidate); } } // not found - return null :/ return(null); }
private ProgressValues GetProgressOfAutomationIdentifier(AutomationIdentifier automationIdentifier) { var command = new GetProgressCommand { AutomationIdentifier = automationIdentifier }; var result = SyncExecuteCommand(command); var progressResult = result as ProgressResult; if (progressResult == null) { // TODO - should log the result here really return(new ProgressValues()); } return(new ProgressValues( progressResult.Min, progressResult.Max, progressResult.Current)); }
protected FrameworkElement GetFrameworkElementParent <TParentType>(bool sendNotFoundResultOnFail = true) where TParentType : FrameworkElement { var element = AutomationElementFinder.FindElementsNearestParentOfType <TParentType>( AutomationElementFinder.GetRootVisual(), AutomationIdentifier) as FrameworkElement; if (element == null) { if (sendNotFoundResultOnFail) { SendNotFoundResult(string.Format("GetFrameworkElement<{0}>: Could not find - {1}", typeof(TParentType), AutomationIdentifier.ToIdOrName())); } return(null); } return(element); }
private bool LookForAutomationIdentifer(AutomationIdentifier controlIdentifier, int ordinal, AutomationIdentifier parentIdentifier) { var command = new GetPositionCommand { AutomationIdentifier = controlIdentifier, Ordinal = ordinal, ParentIdentifier = parentIdentifier, ReturnEmptyIfNotVisible = true }; var result = SyncLookExecuteCommand(command) as PositionResult; if (result == null) { return(false); } // check that position is not empty return(result.Width + result.Height > 0.0); }
protected override void DoImpl() { var element = GetFrameworkElement(); if (element == null) { return; } var control = element as Control; if (control == null) { SendNotFoundResult(string.Format("SetFocusCommand: Could not find the control : {0}", AutomationIdentifier.ToIdOrName())); return; } control.Focus(); SendSuccessResult(); }
internal static Dictionary <string, ControlType> GetControlTypeMappings() { Dictionary <string, ControlType> mapping = new Dictionary <string, ControlType>(); FieldInfo[] properties = typeof(ControlType).GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField); foreach (FieldInfo property in properties) { ControlType type = (typeof(ControlType).InvokeMember(property.Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField, null, null, null)) as ControlType; if (type == null) { continue; } AutomationIdentifier id = type; string typeString = id.ProgrammaticName; string shortTypeString = typeString.Substring(typeString.IndexOf('.') + 1); mapping.Add(shortTypeString, type); } return(mapping); }
protected override void DoImpl() { var element = GetFrameworkElement(); if (element == null) { return; } var text = AutomationElementFinder.GetTextForFrameworkElement(element); if (text != null) { SendTextResult(text); return; } // if text is missing... then give up SendNotFoundResult(string.Format("GetTextCommand: Could not find the element : {0}", AutomationIdentifier.ToIdOrName())); }
private bool TryGetValueFromAutomationIdentifier(AutomationIdentifier controlIdentifier, out string value, int ordinal, AutomationIdentifier parentIdentifier) { value = null; var command = new GetValueCommand { AutomationIdentifier = controlIdentifier, Ordinal = ordinal, ParentIdentifier = parentIdentifier }; var result = SyncExecuteCommand(command); var successResult = result as SuccessResult; if (successResult == null) { return(false); } value = successResult.ResultText; return(true); }
protected override void DoImpl() { var element = GetFrameworkElement(); if (element == null) { SendNotFoundResult( string.Format( "GetIsEnabledCommand: Could not find the control - {0}", AutomationIdentifier.ToIdOrName())); return; } var control = element as Control; if (control == null) { SendNotFoundResult(string.Format("GetIsEnabledCommand: Could not find the control - {0}", AutomationIdentifier.ToIdOrName())); return; } SendTextResult(control.IsEnabled.ToString()); }
protected override void DoImpl() { var element = GetFrameworkElement(false); if (element == null) { SendNotFoundResult(string.Format("ToggleButtonCommand: Could not find the element : {0}", AutomationIdentifier.ToIdOrName())); return; } var peer = FrameworkElementAutomationPeer.CreatePeerForElement(element); if (peer == null) { SendNotFoundResult("Couldn't find automation peer."); } var pattern = peer.GetPattern(PatternInterface.Toggle) as IToggleProvider; if (pattern == null) { SendNotFoundResult(); } pattern.Toggle(); var buttonBase = element as ButtonBase; // Execute the bound command, if available, because IToggleProvider doesn't trigger that. if (buttonBase != null && buttonBase.Command != null) { buttonBase.Command.Execute(buttonBase.CommandParameter); } SendSuccessResult(); }
protected override void DoImpl() { var element = GetFrameworkElement(false); if (element == null) { SendNotFoundResult(string.Format("PivotCommand: Could not find the element : {0}", AutomationIdentifier.ToIdOrName())); return; } var pivot = element as Pivot; if (pivot != null) { if (MovePivot(pivot)) { SendSuccessResult(); } } else { var pano = element as Panorama; if (pano != null) { if (MovePano(pano)) { SendSuccessResult(); } } else { SendNotFoundResult("PivotCommand: Could not find the Panorama"); } } }
internal static string GetPropertyName(AutomationIdentifier property) { var pattern = new Regex(@".*\.(?<name>.*)Property"); return(pattern.Match(property.ProgrammaticName).Groups["name"].Value); }
internal PropertyTypeInfo(PropertyConverter converter, AutomationIdentifier id, Type type) { this._id = id; this._type = type; this._converter = converter; }
protected override void DoImpl() { var element = GetUIElement(); if (element == null) { return; } if (ValueCommandHelper.TrySetValue(element, TextValue)) { SendSuccessResult(); return; } if (AutomationElementFinder.SetElementProperty(element, "Text", TextValue)) { SendSuccessResult(); return; } if (AutomationElementFinder.SetElementProperty(element, "Password", TextValue)) { SendSuccessResult(); return; } bool boolValue; if (bool.TryParse(TextValue, out boolValue)) { if (AutomationElementFinder.SetElementProperty(element, "IsChecked", boolValue)) { SendSuccessResult(); return; } } int intValue; if (int.TryParse(TextValue, out intValue)) { if (AutomationElementFinder.SetElementProperty(element, "Value", intValue)) { SendSuccessResult(); return; } } double doubleValue; if (double.TryParse(TextValue, out doubleValue)) { if (AutomationElementFinder.SetElementProperty(element, "Value", doubleValue)) { SendSuccessResult(); return; } } DateTime dateTimeValue; if (DateTime.TryParse(TextValue, out dateTimeValue)) { if (AutomationElementFinder.SetElementProperty(element, "Value", dateTimeValue)) { SendSuccessResult(); return; } if (AutomationElementFinder.SetElementProperty <DateTime?>(element, "Value", dateTimeValue)) { SendSuccessResult(); return; } } if (AutomationElementFinder.SetElementProperty(element, "Value", TextValue)) { SendSuccessResult(); return; } // if text, password IsChecked, Value are all missing... then give up SendNotFoundResult(string.Format("SetValueCommand: Could not set the value :{0} in control :{1}", TextValue, AutomationIdentifier.ToIdOrName())); }
protected override void DoImpl() { var element = GetFrameworkElement(); var selector = element as Selector; if (selector == null) { return; } var item = selector.Items[IndexOfItemToSelect]; var identifier = new AutomationIdentifier { DisplayedText = item.ToString() }; var listBoxItem = AutomationElementFinder.FindElement(identifier); if (listBoxItem == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the list box item element : {0}", identifier.ToIdOrName())); return; } var button = AutomationElementFinder.FindElementsChildByType <Button>(listBoxItem); if (button != null) // Workaround for nasty lists that use buttons instead of the list select method { // automate the invoke var buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(button); var pattern = buttonPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; if (pattern == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the invoke pattern : {0}", identifier.ToIdOrName())); return; } try { pattern.Invoke(); } catch (Exception exception) { SendExceptionFailedResult(exception); } } else { // automate the select var listBoxPeer = FrameworkElementAutomationPeer.CreatePeerForElement(listBoxItem); var pattern = listBoxPeer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; if (pattern == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the select pattern : {0}", identifier.ToIdOrName())); return; } try { pattern.Select(); } catch (Exception exception) { SendExceptionFailedResult(exception); } } SendSuccessResult(); }
protected override void DoImpl() { var element = GetFrameworkElement(); var selector = element as Selector; if (selector == null) { return; } var item = selector.Items[IndexOfItemToSelect]; var identifier = new AutomationIdentifier {DisplayedText = item.ToString()}; var listBoxItem = AutomationElementFinder.FindElement(identifier); if (listBoxItem == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the list box item element : {0}", identifier.ToIdOrName())); return; } var button = AutomationElementFinder.FindElementsChildByType<Button>(listBoxItem); if (button != null) // Workaround for nasty lists that use buttons instead of the list select method { // automate the invoke var buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(button); var pattern = buttonPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; if (pattern == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the invoke pattern : {0}", identifier.ToIdOrName())); return; } try { pattern.Invoke(); } catch (Exception exception) { SendExceptionFailedResult(exception); } } else { // automate the select var listBoxPeer = FrameworkElementAutomationPeer.CreatePeerForElement(listBoxItem); var pattern = listBoxPeer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; if (pattern == null) { SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the select pattern : {0}", identifier.ToIdOrName())); return; } try { pattern.Select(); } catch (Exception exception) { SendExceptionFailedResult(exception); } } SendSuccessResult(); }