//------------------------------------------------------ // // Public Properties // //------------------------------------------------------ #region Public Properties /// <summary> /// Retrieves a collection of all of the children that fall within the /// range. /// </summary> /// <returns>A collection of all children that fall within the range. Children /// that overlap with the range but are not entirely enclosed by it will /// also be included in the collection.</returns> public AutomationElement[] GetChildren() { object[] rawChildren = UiaCoreApi.TextRange_GetChildren(_hTextRange); AutomationElement[] wrappedChildren = new AutomationElement[rawChildren.Length]; for (int i = 0; i < rawChildren.Length; i++) { SafeNodeHandle hnode = UiaCoreApi.UiaHUiaNodeFromVariant(rawChildren[i]); wrappedChildren[i] = AutomationElement.Wrap(hnode); } return wrappedChildren; }
public Win32ListItem(AutomationElement automationElement, ActionListener actionListener) : base(automationElement, actionListener) { }
public override string SetControlValue(object obj, string value) { AutomationElement element = (AutomationElement)obj; //Check if control is enabled if (!element.Properties.IsEnabled) { throw new InvalidOperationException( "The control with an AutomationID of " + element.Properties.AutomationId.ToString() + " is not enabled.\n\n"); } object vp; string controlType = element.Properties.LocalizedControlType; switch (controlType) { case "edit": case "Edit Box": // Windows AutomationElementConversionExtensions.AsTextBox(element).Text = value; break; case "list": case "list item": bool isMultiSelect; AutomationElement parentElement = element.Automation.TreeWalkerFactory.GetContentViewWalker().GetParent(element); try { isMultiSelect = (bool)parentElement.BasicAutomationElement.GetPropertyValue(selectnPattrn.CanSelectMultiple); } catch (Exception e) { isMultiSelect = false; Console.WriteLine(e.StackTrace); } if (isMultiSelect) { String IsItemSelected = (element.BasicAutomationElement.GetPropertyValue(selItmProp.IsSelected)).ToString(); if (IsItemSelected == "False") { element.BasicAutomationElement.TryGetNativePattern(SelectionItemPattern.Pattern, out vp); ((ISelectionItemPattern)vp).AddToSelection(); } else { element.BasicAutomationElement.TryGetNativePattern(SelectionItemPattern.Pattern, out vp); ((ISelectionItemPattern)vp).RemoveFromSelection(); } } else { element.BasicAutomationElement.TryGetNativePattern(SelectionItemPattern.Pattern, out vp); ((ISelectionItemPattern)vp).Select(); } break; default: Reporter.ToUser(eUserMsgKey.ActionNotImplemented, controlType); break; } return("true"); }
public NewProjectDialog(VisualStudioApp app, AutomationElement element) : base(app, element) { }
public void VerifyInput() { // // Start the application we are testing // string sampleAppPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "SampleApp.exe"); AutomatedApplication a = new OutOfProcessApplication(new OutOfProcessApplicationSettings { ProcessStartInfo = new ProcessStartInfo(sampleAppPath), ApplicationImplementationFactory = new UIAutomationOutOfProcessApplicationFactory() }); a.Start(); try { a.WaitForMainWindow(TimeSpan.FromSeconds(10)); var mainWindow = a.MainWindow as AutomationElement; // // Discover various elements in the UI // AutomationElement inputTextBox = AutomationUtilities.FindElementsById(mainWindow, "inputTextBox")[0]; AutomationElement outputTextBox = AutomationUtilities.FindElementsById(mainWindow, "outputTextBox")[0]; AutomationElement appendButton = AutomationUtilities.FindElementsById(mainWindow, "appendButton")[0]; // // Click on the input text box and simulate typing // string inputText = "TestTest"; string expectedText = inputText + "\n"; WindowPattern winPattern = mainWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern; Helpers.MoveToAndClick(inputTextBox); winPattern.WaitForInputIdle(1000); Microsoft.Test.Input.Keyboard.Type(inputText); winPattern.WaitForInputIdle(1000); // // Now click the button // Helpers.MoveToAndClick(appendButton); winPattern.WaitForInputIdle(1000); // // Now, get the text of the outputTextBox and compare it against what's expected // Fail the test if expected != actual // TextPattern textPattern = outputTextBox.GetCurrentPattern(TextPattern.Pattern) as TextPattern; string actualText = textPattern.DocumentRange.GetText(-1); // // Report the test result // Assert.AreEqual(expectedText, actualText); } finally { // // Close the tested application // a.Close(); } }
public void SetCurrentWindow(AutomationElement wnd) { wnd.SetFocus(); }
public static ElementProperty FromElementProperty(AutomationProperty property, AutomationElement element) { var nameParts = property.ProgrammaticName.Split('.'); return(new ElementProperty() { Value = Convert.ToString(element.GetCurrentPropertyValue(property)), Root = nameParts.Length > 1 ? nameParts[0] : string.Empty, Name = nameParts.Length <= 1 ? nameParts[0] : nameParts[1] }); }
/// <summary> /// Reads the DropTargetPattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the DropTargetPattern.</param> /// <returns>The DropTargetPattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static DropTargetPattern GetDropTargetPattern(AutomationElement element) => Get<DropTargetPattern>(element, DropTargetPattern.Pattern);
/// <summary> /// Reads the ExpandCollapsePattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the ExpandCollapsePattern.</param> /// <returns>The ExpandCollapsePattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static ExpandCollapsePattern GetExpandCollapsePattern(AutomationElement element) => Get<ExpandCollapsePattern>(element, ExpandCollapsePattern.Pattern);
/// <summary> /// Reads the AnnotationPattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the AnnotationPattern.</param> /// <returns>The AnnotationPattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static AnnotationPattern GetAnnotationPattern(AutomationElement element) => Get<AnnotationPattern>(element, AnnotationPattern.Pattern);
/// <summary> /// Reads the DockPattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the DockPattern.</param> /// <returns>The DockPattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static DockPattern GetDockPattern(AutomationElement element) => Get<DockPattern>(element, DockPattern.Pattern);
private static TPattern Get<TPattern>(AutomationElement element, AutomationPattern pattern) where TPattern : BasePattern { if (element.TryGetCurrentPattern(pattern, out var readPattern)) return (TPattern)readPattern; throw new NotSupportedException(); }
/// <summary> /// Reads the WindowPattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the WindowPattern.</param> /// <returns>The WindowPattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static WindowPattern GetWindowPattern(AutomationElement element) => Get<WindowPattern>(element, WindowPattern.Pattern);
/// <summary> /// Reads the VirtualizedItemPattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the VirtualizedItemPattern.</param> /// <returns>The VirtualizedItemPattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static VirtualizedItemPattern GetVirtualizedItemPattern(AutomationElement element) => Get<VirtualizedItemPattern>(element, VirtualizedItemPattern.Pattern);
/// <summary> /// Reads the ValuePattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the ValuePattern.</param> /// <returns>The ValuePattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static ValuePattern GetValuePattern(AutomationElement element) => Get<ValuePattern>(element, ValuePattern.Pattern);
/// <summary> /// Reads the GridPattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the GridPattern.</param> /// <returns>The GridPattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static GridPattern GetGridPattern(AutomationElement element) => Get<GridPattern>(element, GridPattern.Pattern);
public void FaultAppendText() { string sampleAppPath = "SampleApp.exe"; //Create the FaultRule and FaultSession FaultRule rule = new FaultRule( "SampleApp.Window1.Append(string, string)", BuiltInConditions.TriggerOnEveryCall, BuiltInFaults.ReturnValueFault("")); FaultSession session = new FaultSession(rule); //Start the app ProcessStartInfo psi = session.GetProcessStartInfo(sampleAppPath); OutOfProcessApplication testApp = new OutOfProcessApplication( new OutOfProcessApplicationSettings { ProcessStartInfo = psi, ApplicationImplementationFactory = new UIAutomationOutOfProcessApplicationFactory() }); testApp.Start(); try { testApp.WaitForMainWindow(TimeSpan.FromSeconds(15)); // Discover various elements in the UI AutomationElement mainWindowElement = (AutomationElement)testApp.MainWindow; AutomationElement inputTextBox = AutomationUtilities.FindElementsById(mainWindowElement, "inputTextBox")[0]; AutomationElement outputTextBox = AutomationUtilities.FindElementsById(mainWindowElement, "outputTextBox")[0]; AutomationElement appendButton = AutomationUtilities.FindElementsById(mainWindowElement, "appendButton")[0]; // Click on the input text box and simulate typing string inputText = "TestTest"; string expectedText = ""; //expected text should be nothing since we intercept the Append method WindowPattern winPattern = mainWindowElement.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern; Helpers.MoveToAndClick(inputTextBox); winPattern.WaitForInputIdle(inputWaitTime); Microsoft.Test.Input.Keyboard.Type(inputText); winPattern.WaitForInputIdle(inputWaitTime); // Now click the button Helpers.MoveToAndClick(appendButton); winPattern.WaitForInputIdle(inputWaitTime); // Now, get the text of the outputTextBox and compare it against what's expected // Fail the test if expected != actual TextPattern textPattern = outputTextBox.GetCurrentPattern(TextPattern.Pattern) as TextPattern; string actualText = textPattern.DocumentRange.GetText(-1); // Report the test result Assert.AreEqual(expectedText, actualText); } finally { // Close the tested application testApp.Close(); } }
/// <summary> /// Reads the InvokePattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the InvokePattern.</param> /// <returns>The InvokePattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static InvokePattern GetInvokePattern(AutomationElement element) => Get<InvokePattern>(element, InvokePattern.Pattern);
public ListItem(AutomationElement element) : base(element) { }
/// <summary> /// Reads the ItemContainerPattern from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the ItemContainerPattern.</param> /// <returns>The ItemContainerPattern the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static ItemContainerPattern GetItemContainerPattern(AutomationElement element) => Get<ItemContainerPattern>(element, ItemContainerPattern.Pattern);
// <Snippet106> private void OnFocusChanged(object src, AutomationFocusChangedEventArgs e) { AutomationElement elementFocused = src as AutomationElement; // TODO: Do something in response to the focus change. }
/// <summary> /// If the record we select is not previously authorized, we can't use it for this test's purposes. This function iterates through records until we find one that has previous /// COD authorization. /// </summary> private static bool LookForNonCODWarningRecord() { var tableName = Actions.GetWindowChild(EllisWindow, "grdDispatchJobOrder"); var table = (WinTable)tableName; var rows = table.Rows; //We have to iterate through each Table Row until we find one that isn't Aging or COD for (int i = 0; i < rows.Count; ++i) { //Each row has several elements, we need to find the clickable one foreach (var child in rows[i].GetChildren()) { var cell = child as WinCell; if (cell == null) { continue; } if (cell.BoundingRectangle.Left == cell.BoundingRectangle.Right) { continue; } var clickPoint = new System.Drawing.Point(cell.BoundingRectangle.Left + 3, cell.BoundingRectangle.Top + 3); Mouse.Click(clickPoint); Playback.Wait(200); Mouse.DoubleClick(clickPoint); break; } Playback.Wait(3000); //If the row we clicked on creates a COD window or a Aging window, we dismiss that window, then cancel the Dispatch / Payout window so we can select the next row. if (App.Container.SearchFor <WinWindow>(new { Name = "OrderDetailLanding" }).Exists || App.Container.SearchFor <WinWindow>(new { Name = "Warning" }).Exists) { DispatchProfileWindow.WarningWindowProperties(); Playback.Wait(5000); AutomationElement window = AutomationElement.RootElement.FindFirst(TreeScope.Children, new System.Windows.Automation.PropertyCondition(AutomationElement.NameProperty, "Ellis")); var windows = window.FindAll( TreeScope.Descendants, new System.Windows.Automation.PropertyCondition( AutomationElement.IsWindowPatternAvailableProperty, true)); foreach (AutomationElement w in windows) { if (w.Current.Name.EndsWith("Dispatch / Payout")) { //cancel the dispatch / payout window so we can get back to the Ellis window and select the next row Mouse.Click(w.FindFirst(TreeScope.Descendants, new System.Windows.Automation.PropertyCondition( AutomationElement.AutomationIdProperty, "btnCancel")) .GetClickablePoint()); break; } } } else { return(true); } } return(false); }
internal ComboBox(AutomationElement element, IFactory <I> itemFactory) : base(element: element) { Initialize(itemFactory: itemFactory); }
public ColorBoard(AutomationElement element) : base(element) { }
public FormattingOptionsTreeView(AutomationElement element) : base(element) { }
public override Rect GetElementBoundingRectangle(object obj) { AutomationElement element = (AutomationElement)obj; return(element.Properties.BoundingRectangle.ValueOrDefault); }
public override Bitmap GetAppWindowAsBitmap(AppWindow aw) { AutomationElement tempWindow = (AutomationElement)((UIAElementInfo)aw.RefObject).ElementObject; return(tempWindow.Capture()); }
public override int GetElementNativeWindowHandle(object obj) { AutomationElement element = (AutomationElement)obj; return(element.Properties.NativeWindowHandle.ValueOrDefault.ToInt32()); }
public override string GetElementControlType(object obj) { AutomationElement element = (AutomationElement)obj; return(element.Properties.LocalizedControlType.ValueOrDefault); }
public override object[] GetSupportedPatterns(object obj) { AutomationElement element = (AutomationElement)obj; return(element.Automation.PatternLibrary.AllForCurrentFramework); }
public CachedListItemElement(AutomationElement elem, ExtendedItemsView parent) { Point offset = parent.GetWindowPos(); offset = new Point(-offset.X, -offset.Y); Index = elem.GetItemIndex(); Rectangle rect = elem.GetBoundingRect(); rect.Offset(offset); FullRect = rect; bool foundLabel = false; bool foundIcon = false; foreach(AutomationElement child in elem.GetChildren()) { if(!foundLabel && child.GetAutomationId() == "System.ItemNameDisplay") { rect = child.GetBoundingRect(); rect.Offset(offset); LabelRect = rect; if(foundIcon) break; foundLabel = true; } else if(!foundIcon && child.GetClassName() == "UIImage") { rect = child.GetBoundingRect(); rect.Offset(offset); IconRect = rect; if(foundLabel) break; foundIcon = true; } } }
/// <summary> /// Reads the TransformPattern2 from the given AutomationElement. /// </summary> /// <param name="element">The AutomationElement which supports the TransformPattern2.</param> /// <returns>The TransformPattern2 the the given AutomationElement.</returns> /// <exception cref="NotSupportedException">Thrown if the given AutomationElement is not supporting it. Check <see cref="BasicElement.SupportedPatterns" /> at runtime if the pattern is available.</exception> public static TransformPattern2 GetTransformPattern2(AutomationElement element) => Get<TransformPattern2>(element, TransformPattern2.Pattern);