public static UITestControl OpenApplication(IConfiguration configuration) { ApplicationUnderTest applicationUnderTest = ApplicationUnderTest.Launch(configuration["AppPath"]); applicationUnderTest.WaitForControlExist(); var application = UITestControlFactory.FromWindowHandle(applicationUnderTest.WindowHandle); application.SetFocus(); return(application); }
/// <summary> /// Gets the UIA control from GridControl by using the live AutomationElement. /// </summary> /// <param name="control">The control.</param> /// <returns>The live UIA control.</returns> public static UITestControl GetLiveUiaControl(UITestControl control) { UITechnologyElement element = control.GetProperty(UITestControl.PropertyNames.UITechnologyElement) as UITechnologyElement; if (element != null) { AutomationElement ae = element.NativeElement as AutomationElement; if (ae != null) { return(UITestControlFactory.FromNativeElement(ae, "UIA")); } } throw new InvalidOperationException(); }
private static TWpfControl 属性编辑器 <TWpfControl>(this WpfTreeItem row, string title = null) where TWpfControl : WpfControl { var rowElement = row.NativeElement as WinUIA.AutomationElement; //开启单元格的编辑状态 var cellElement = rowElement.FindFirst(WinUIA.TreeScope.Subtree, new WinUIA.AndCondition ( new WinUIA.PropertyCondition(WinUIA.AutomationElement.NameProperty, title), new WinUIA.PropertyCondition(WinUIA.AutomationElement.ControlTypeProperty, WinUIA.ControlType.Custom) )); if (cellElement != null) { var p2 = cellElement.GetCurrentPattern(WinUIA.InvokePattern.Pattern) as WinUIA.InvokePattern; p2.Invoke(); } //由于 WinUIA 的速度太快,需要一定的时间来等待控件生成。 Thread.Sleep(100); //编辑状态打开后,再找到相应的编辑控件。 var editingCellElement = rowElement.FindFirst(WinUIA.TreeScope.Subtree, new WinUIA.PropertyCondition(WinUIA.AutomationElement.NameProperty, "编辑控件") ); var editingCell = UITestControlFactory.FromNativeElement(editingCellElement, "UIA"); //var cell = UITestControlFactory.FromNativeElement(cellElement, "UIA") as WpfCustom; //var cell = row.Find<WpfCustom>(title); //cell.Click(); //cell.SearchProperties[WpfControl.PropertyNames.ClassName] = "Uia.MTTGCell"; //cell.SearchProperties[WpfControl.PropertyNames.ClassName] = "Uia.AutomatableTextBlock"; //cell.Find(); //var editingCell = row.Find<WpfEdit>(title); return(editingCell as TWpfControl); }