private static void checkEmptyElement(XmlDocument doc, AutomationElement.AutomationElementInformation ElementInfo, XmlElement searchCritchild) { if (!string.IsNullOrEmpty(ElementInfo.AutomationId)) { XmlElement propchildId = doc.CreateElement("Property"); propchildId.SetAttribute("AutomationId", ElementInfo.AutomationId); searchCritchild.AppendChild(propchildId); } if (!string.IsNullOrEmpty(ElementInfo.ClassName)) { XmlElement propchildName = doc.CreateElement("Property"); propchildName.SetAttribute("ClassName", ElementInfo.ClassName); searchCritchild.AppendChild(propchildName); } if (!string.IsNullOrEmpty(ElementInfo.Name)) { XmlElement propchildName = doc.CreateElement("Property"); propchildName.SetAttribute("Name", ElementInfo.Name); searchCritchild.AppendChild(propchildName); } if (!string.IsNullOrEmpty(ElementInfo.LocalizedControlType)) { XmlElement propchildName = doc.CreateElement("Property"); propchildName.SetAttribute("ControlType", ElementInfo.LocalizedControlType); searchCritchild.AppendChild(propchildName); } }
internal static object GetUIControlPropertyValue(UITestControl uiTestControl, string propertyName, Dictionary <string, UITestPropertyDescriptor> Properties) { if (Properties.ContainsKey(propertyName)) { AutomationElement automationElement = uiTestControl.NativeElement as AutomationElement; AutomationElement.AutomationElementInformation current = automationElement.Current; if (current.ItemStatus.Equals(string.Empty)) { throw new NotSupportedException(); } AutomationElement.AutomationElementInformation current2 = automationElement.Current; string[] array = current2.ItemStatus.Split(new string[] { "#" }, StringSplitOptions.None); return(array[PropertyProviderHelper.FindIndex(propertyName, Properties)]); } else if (propertyName == "ClassName") { AutomationElement automationElement = uiTestControl.NativeElement as AutomationElement; AutomationElement.AutomationElementInformation current = automationElement.Current; return(current.ClassName); } throw new NotSupportedException(); }
protected override void WndProc(ref Message m) { bool flag = m.Msg == 786; if (flag) { this.ListView1.Items.Clear(); this.TreeView1.Nodes.Clear(); this.RootElement = null; this.CurrentElement = null; this.Button1.Enabled = false; this.Timer1.Stop(); this.dic = new Dictionary <TreeNode, AutomationElement>(); this.RootElement = AutomationElement.RootElement; TreeNodeCollection arg_B5_0 = this.TreeView1.Nodes; AutomationElement.AutomationElementInformation current = this.RootElement.Current; string arg_B0_0 = current.Name; string arg_B0_1 = " "; current = this.RootElement.Current; this.RootNode = arg_B5_0.Add(arg_B0_0 + arg_B0_1 + current.LocalizedControlType.ToString()); this.dic.Add(this.RootNode, this.RootElement); this.LoopElement(this.RootElement, this.RootNode); this.TreeView1.ExpandAll(); this.TreeView1.Focus(); this.TreeView1.SelectedNode = this.RootNode; this.Button1.Enabled = true; } base.WndProc(ref m); }
/// <summary> /// Get the Property value /// </summary> /// <param name="uiTestControl">UITestControl</param> /// <param name="propertyName">PropertyName</param> /// <returns>object</returns> public object GetUIControlPropertyValue(UITestControl uiTestControl, string propertyName) { if (propertyName == "FriendlyName") { AutomationElement automationElement = uiTestControl.NativeElement as AutomationElement; AutomationElement.AutomationElementInformation current = automationElement.Current; if (current.ItemStatus.Equals(string.Empty)) { throw new NotSupportedException(); } AutomationElement.AutomationElementInformation current2 = automationElement.Current; string[] array = current2.ItemStatus.Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries); return(array[0]); } else if (propertyName == "Name") { return(null); } else { return(PropertyProviderHelper.GetUIControlPropertyValue(uiTestControl, propertyName, TreeGridCellProperties)); } }
public virtual Type GetTestControlType(AutomationElement automationElement) { TreeWalker tWalker = TreeWalker.ControlViewWalker; AutomationElement.AutomationElementInformation current = automationElement.Current; AutomationElement parent = tWalker.GetParent(automationElement); String frameId = current.FrameworkId; // This has to be in a try catch block because otherwise custom Windows Forms controls can cause exception if they have null parent // as IRawElementProviderFragmentRoot should have according to documentation try { while (string.IsNullOrEmpty(frameId) || tWalker.GetParent(parent) != null) { frameId = parent.Current.FrameworkId; parent = tWalker.GetParent(parent); } } catch { // Catch possible null reference exception frameId = String.Empty; parent = null; } return(GetTestControlType(current.ClassName, current.Name, current.ControlType, frameId, current.NativeWindowHandle != 0)); }
private static void SetDisplayName(UIControl control, AutomationElement.AutomationElementInformation ElementInfo) { Random random = new Random(); int randomNumber = random.Next(0, 100); if (!string.IsNullOrEmpty(ElementInfo.Name)) { control.Name = ElementInfo.Name; } else if (!string.IsNullOrEmpty(ElementInfo.ClassName)) { control.Name = ElementInfo.ClassName; } else if (!string.IsNullOrEmpty(ElementInfo.AutomationId)) { control.Name = ElementInfo.AutomationId; } else if (!string.IsNullOrEmpty(ElementInfo.LocalizedControlType)) { control.Name = ElementInfo.LocalizedControlType; } else { control.Name = "DispalyName_" + randomNumber; } }
private void ShowProperty() { this.ListView1.Items.Clear(); try { AutomationElement.AutomationElementInformation current = this.CurrentElement.Current; this.AddItems("名称", "Name", current.Name); this.AddItems("本地类型", "LocalizedControlType", current.LocalizedControlType); this.AddItems("控件类型", "ControlType", current.ControlType.ProgrammaticName); this.AddItems("类名", "ClassName", current.ClassName); this.AddItems("句柄", "NativeWindowHandle", Conversions.ToString(current.NativeWindowHandle)); this.AddItems("进程", "ProcessId", Conversions.ToString(current.ProcessId)); this.AddItems("自动化", "AutomationId", current.AutomationId); this.Rec = current.BoundingRectangle; this.AddItems("矩形", "BoundingRectangle", string.Format("({0},{1}),({2},{3})", new object[] { this.Rec.Left, this.Rec.Top, this.Rec.Right, this.Rec.Bottom })); this.AddItems("快捷键", "AcceleratorKey", current.AcceleratorKey); this.AddItems("快速访问键", "AccessKey", current.AccessKey); this.AddItems("具有键盘焦点", "HasKeyboardFocus", Conversions.ToString(current.HasKeyboardFocus)); this.AddItems("可接受键盘焦点", "IsKeyboardFocusable", Conversions.ToString(current.IsKeyboardFocusable)); this.AddItems("可用", "IsEnabled", Conversions.ToString(current.IsEnabled)); this.AddItems("消失", "IsOffscreen", Conversions.ToString(current.IsOffscreen)); this.AddItems("是内容元素", "IsContentElement", Conversions.ToString(current.IsContentElement)); this.AddItems("是控件元素", "IsControlElement", Conversions.ToString(current.IsControlElement)); this.AddItems("是密码框", "IsPassword", Conversions.ToString(current.IsPassword)); this.DrawRectangle(); } catch (Exception expr_254) { ProjectData.SetProjectError(expr_254); ProjectData.ClearProjectError(); return; } try { this.Pt = this.CurrentElement.GetClickablePoint(); this.AddItems("中心坐标", "ClickablePoint", string.Format("({0},{1})", this.Pt.X, this.Pt.Y)); } catch (Exception expr_2B6) { ProjectData.SetProjectError(expr_2B6); ProjectData.ClearProjectError(); } AutomationPattern[] supportedPatterns = this.CurrentElement.GetSupportedPatterns(); AutomationPattern[] array = supportedPatterns; checked { for (int i = 0; i < array.Length; i++) { AutomationPattern pattern = array[i]; this.AddItems("可用模式", "GetSupportedPatterns", Automation.PatternName(pattern) + "Pattern"); } } }
public static Element Create(AutomationElement element, int processId) { AutomationElement.AutomationElementInformation current = element.Current; if (current.NativeWindowHandle != 0 && current.ControlType == ControlType.Window) { return(new NativeElement(element, processId)); } return(new Element(element, processId)); }
private void GlobalHook_MouseEvent(object sender, MouseCoordinateEventArgs e) { //mouse down has occured //invoke UIA try { AutomationElement element = AutomationElement.FromPoint(e.MouseCoordinates); AutomationElement.AutomationElementInformation elementProperties = element.Current; LastItemClicked = $"[Name:{element.Current.Name}].[ID:{element.Current.AutomationId.ToString()}].[Class:{element.Current.ClassName}]"; lblSubHeader.Text = LastItemClicked; SearchParameters.Rows.Clear(); //get properties from class via reflection PropertyInfo[] properties = typeof(AutomationElement.AutomationElementInformation).GetProperties(); Array.Sort(properties, (x, y) => String.Compare(x.Name, y.Name)); //loop through each property and get value from the element foreach (PropertyInfo property in properties) { try { var propName = property.Name; var propValue = property.GetValue(elementProperties, null); //if property is a basic type then display if ((propValue is string) || (propValue is bool) || (propValue is int) || (propValue is double)) { SearchParameters.Rows.Add(false, propName, propValue); } } catch (Exception ex) { MessageBox.Show("Error Iterating over properties in window: " + ex.ToString()); } } } catch (Exception) { lblDescription.Text = "Error cloning element. Please Try Again."; //MessageBox.Show("Error in recording, please try again! " + ex.ToString()); } if (chkStopOnClick.Checked) { Close(); } }
public virtual Type GetTestControlType(AutomationElement automationElement) { TreeWalker tWalker = TreeWalker.ControlViewWalker; AutomationElement.AutomationElementInformation current = automationElement.Current; AutomationElement parent = tWalker.GetParent(automationElement); String frameId = current.FrameworkId; while (string.IsNullOrEmpty(frameId) || tWalker.GetParent(parent) != null) { frameId = parent.Current.FrameworkId; parent = tWalker.GetParent(parent); } return(GetTestControlType(current.ClassName, current.Name, current.ControlType, frameId, current.NativeWindowHandle != 0)); }
public static string Display(this AutomationElement automationElement) { try { if (automationElement == null) { return("(NULL)"); } AutomationElement.AutomationElementInformation elementInformation = automationElement.Current; return(String.Format("AutomationId:{0}, Name:{1}, ControlType:{2}, FrameworkId:{3}", elementInformation.AutomationId, elementInformation.Name, elementInformation.ControlType.LocalizedControlType, elementInformation.FrameworkId)); } catch { return("Cannot display automation element details. The UIItem might have been disposed"); } }
private static void SetSearchProperties(UIControl control, AutomationElement.AutomationElementInformation ElementInfo) { if (!string.IsNullOrEmpty(ElementInfo.AutomationId)) { control.SearchCriteria.SearchProperties.Add("AutomationID", ElementInfo.AutomationId); } if (!string.IsNullOrEmpty(ElementInfo.ClassName)) { control.SearchCriteria.SearchProperties.Add("ClassName", ElementInfo.ClassName); } if (!string.IsNullOrEmpty(ElementInfo.Name)) { control.SearchCriteria.SearchProperties.Add("Name", ElementInfo.Name); } if (!string.IsNullOrEmpty(ElementInfo.LocalizedControlType)) { control.SearchCriteria.SearchProperties.Add("ControlType", ElementInfo.LocalizedControlType); } }
public void LoopElement(AutomationElement ParentElement, TreeNode ParentNode) { try { AutomationElementCollection automationElementCollection = ParentElement.FindAll(TreeScope.Children, Condition.TrueCondition); IEnumerator enumerator = null; try { enumerator = automationElementCollection.GetEnumerator(); while (enumerator.MoveNext()) { AutomationElement automationElement = (AutomationElement)enumerator.Current; TreeNodeCollection arg_59_0 = ParentNode.Nodes; AutomationElement.AutomationElementInformation current = automationElement.Current; string arg_54_0 = current.Name; string arg_54_1 = " "; current = automationElement.Current; TreeNode treeNode = arg_59_0.Add(arg_54_0 + arg_54_1 + current.LocalizedControlType.ToString()); this.dic.Add(treeNode, automationElement); bool flag = automationElement.Equals(this.CurrentElement); if (flag) { this.CurrentNode = treeNode; } this.LoopElement(automationElement, treeNode); } } finally { if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } } catch (ElementNotAvailableException expr_BA) { ProjectData.SetProjectError(expr_BA); ProjectData.ClearProjectError(); } }
private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e) { this.CurrentElement = this.dic[e.Node]; try { AutomationElement.AutomationElementInformation current = this.CurrentElement.Current; bool flag = !current.IsOffscreen; if (flag) { this.ShowProperty(); } } catch (ElementNotAvailableException expr_3E) { ProjectData.SetProjectError(expr_3E); ElementNotAvailableException ex = expr_3E; this.ListView1.Items.Clear(); MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Hand); ProjectData.ClearProjectError(); } }
private void DrawRectangle() { checked { try { AutomationElement.AutomationElementInformation current = this.CurrentElement.Current; this.Rec = current.BoundingRectangle; bool flag = Operators.CompareString(this.Rec.ToString(), "Empty", false) != 0; if (flag) { Form1.Rectangle(this.hDC, (int)Math.Round(this.Rec.Left), (int)Math.Round(this.Rec.Top), (int)Math.Round(this.Rec.Right), (int)Math.Round(this.Rec.Bottom)); Thread.Sleep(100); Form1.Rectangle(this.hDC, (int)Math.Round(this.Rec.Left), (int)Math.Round(this.Rec.Top), (int)Math.Round(this.Rec.Right), (int)Math.Round(this.Rec.Bottom)); } } catch (ElementNotAvailableException expr_ED) { // ProjectData.SetProjectError(expr_ED); ProjectData.ClearProjectError(); } } }
public virtual Type GetTestControlType(AutomationElement automationElement) { TreeWalker tWalker = null; if (CoreAppXmlConfiguration.Instance.RawElementBasedSearch) { tWalker = TreeWalker.RawViewWalker; } else { tWalker = TreeWalker.ControlViewWalker; } AutomationElement.AutomationElementInformation current = automationElement.Current; AutomationElement parent = tWalker.GetParent(automationElement); String frameId = current.FrameworkId; while (string.IsNullOrEmpty(frameId) || tWalker.GetParent(parent) != null) { frameId = parent.Current.FrameworkId; parent = tWalker.GetParent(parent); } return(GetTestControlType(current.ClassName, current.Name, current.ControlType, frameId, current.NativeWindowHandle != 0)); }
// Some SelectionItem may be IsKeyboardFocusable = false but, in fact, it can be focused... private static bool IsFocusable(AutomationElement.AutomationElementInformation info, ControlType controlType) { return((info.IsKeyboardFocusable && info.IsEnabled) || controlType == ControlType.ListItem || controlType == ControlType.List); }
private void Timer1_Tick(object sender, EventArgs e) { Form1.GetCursorPos(ref this.P); this.Pt.X = (double)this.P.x; this.Pt.Y = (double)this.P.y; try { this.CurrentElement = AutomationElement.FromPoint(this.Pt); AutomationElement.AutomationElementInformation current = this.CurrentElement.Current; bool flag = current.ProcessId == Process.GetCurrentProcess().Id; if (flag) { return; } } catch (Exception expr_7A) { ProjectData.SetProjectError(expr_7A); ProjectData.ClearProjectError(); } this.DrawRectangle(); bool flag2 = ((int)Form1.GetAsyncKeyState(17) & 32768) != 0; if (flag2) { AutomationElement.AutomationElementInformation current = this.CurrentElement.Current; this.RootElement = this.CurrentElement; this.TW = TreeWalker.ControlViewWalker; // 上一个节点 AutomationElement lastElement = this.TW.GetParent(this.RootElement); AutomationElement.AutomationElementInformation lastAutomationElementInformation = lastElement.Current; while (true) { bool flag3 = this.TW.GetParent(this.RootElement).Equals(AutomationElement.RootElement); if (flag3) { break; } this.RootElement = this.TW.GetParent(this.RootElement); } // 找到上一级 /*this.TreeView1.Nodes.Clear(); * TreeNodeCollection treeNodeCollection = this.TreeView1.Nodes; * current = this.RootElement.Current; * this.RootNode = treeNodeCollection.Add(current.Name + " " + current.LocalizedControlType.ToString()); * this.dic = new Dictionary<TreeNode, AutomationElement>(); * this.dic.Add(this.RootNode, this.RootElement); * this.LoopElement(this.RootElement, this.RootNode); *//*Console.WriteLine("parent:"+ this.dic(this.RootNode.LastNode));*/ string pearentName = this.RootElement.Current.Name; string pearentClass = this.RootElement.Current.ClassName; /*string[] sourceArray = new string[] * { * "父名称:" + pearentName, * "父类名:" + pearentClass, * "名称:" + current.Name, * "本地类型:" + current.LocalizedControlType, * "控件类型:" + current.ControlType.ProgrammaticName, * "类名:" + current.ClassName, * "句柄:" + Conversions.ToString(current.NativeWindowHandle), * "进程:" + Conversions.ToString(current.ProcessId) * }; * MessageBox.Show(Strings.Join(sourceArray, "\r\n"), "句柄信息");*/ Dictionary <string, object> rootParent = new Dictionary <string, object>(); rootParent.Add("currentName", this.RootElement.Current.Name); rootParent.Add("currentClassName", this.RootElement.Current.ClassName); rootParent.Add("currentNativeWindowHandle", Conversions.ToString(this.RootElement.Current.NativeWindowHandle)); rootParent.Add("currentProcessId", Conversions.ToString(this.RootElement.Current.ProcessId)); rootParent.Add("currentControlTypeProgrammaticName", this.RootElement.Current.ControlType.ProgrammaticName); rootParent.Add("AutomationId", this.RootElement.Current.AutomationId); rootParent.Add("index", "1"); Dictionary <string, object> lastParent = new Dictionary <string, object>(); lastParent.Add("currentName", lastAutomationElementInformation.Name); lastParent.Add("currentClassName", lastAutomationElementInformation.ClassName); lastParent.Add("currentNativeWindowHandle", Conversions.ToString(lastAutomationElementInformation.NativeWindowHandle)); lastParent.Add("currentProcessId", Conversions.ToString(lastAutomationElementInformation.ProcessId)); lastParent.Add("currentControlTypeProgrammaticName", lastAutomationElementInformation.ControlType.ProgrammaticName); lastParent.Add("AutomationId", lastAutomationElementInformation.AutomationId); Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("rootParent", rootParent); dictionary.Add("lastParent", lastParent); dictionary.Add("currentName", current.Name); dictionary.Add("text", current.Name); dictionary.Add("currentClassName", current.ClassName); dictionary.Add("currentNativeWindowHandle", Conversions.ToString(current.NativeWindowHandle)); dictionary.Add("currentProcessId", Conversions.ToString(current.ProcessId)); dictionary.Add("currentControlTypeProgrammaticName", current.ControlType.ProgrammaticName); dictionary.Add("AutomationId", current.AutomationId); dictionary.Add("x", this.Rec.Left); dictionary.Add("y", this.Rec.Top); dictionary.Add("w", this.Rec.Right); dictionary.Add("h", this.Rec.Bottom); /*dictionary.Add("AccessKey", current.AccessKey);*/ // 截图 转字符串 this.Rec = current.BoundingRectangle; Console.WriteLine("this.Rec.Left:" + this.Rec.Left.ToString() + ",this.Rec.Top:" + this.Rec.Top.ToString() + ",this.Rec.Right:" + this.Rec.Right.ToString() + ",this.Rec.Bottom:" + this.Rec.Bottom.ToString()); Form1.Rectangle(this.hDC, (int)Math.Round(this.Rec.Left), (int)Math.Round(this.Rec.Top), (int)Math.Round(this.Rec.Right), (int)Math.Round(this.Rec.Bottom)); MouseHookHelper.SetCursorPos(0, 0); Thread.Sleep(150); String imagePath = this.SaveImage((int)Math.Round(this.Rec.Left), (int)Math.Round(this.Rec.Top), (int)Math.Round(this.Rec.Right - this.Rec.Left), (int)Math.Round(this.Rec.Bottom - this.Rec.Top)); // string base64FromImage = ImageUtil.GetBase64FromImage(image); dictionary.Add("screenShot", imagePath); PostData(dictionary); } else { this.ShowProperty(); } }
private void LoadSearchParameters(Point point) { AutomationElement element; try { element = AutomationElement.FromPoint(point); } catch (Exception) { Thread.Sleep(500); element = AutomationElement.FromPoint(point); } AutomationElement.AutomationElementInformation elementProperties = element.Current; LastItemClicked = $"[Automation ID:{elementProperties.AutomationId}].[Name:{elementProperties.Name}].[Class:{elementProperties.ClassName}]"; lblSubHeader.Text = LastItemClicked; //get properties from class via reflection PropertyInfo[] properties = typeof(AutomationElement.AutomationElementInformation).GetProperties(); Array.Sort(properties, (x, y) => string.Compare(x.Name, y.Name)); SearchParameters = NewSearchParameterDataTable(); if (IsRecordingSequence) { //loop through each property and get value from the element foreach (DataRow row in _parameterSettings.Rows) { foreach (PropertyInfo property in properties) { try { var propName = property.Name; var propValue = property.GetValue(elementProperties, null); //if property is a basic type then display if ((propName == row[1].ToString()) && ((propValue is string) || (propValue is bool) || (propValue is int) || (propValue is double))) { SearchParameters.Rows.Add(row[0], propName, propValue); } } catch (Exception ex) { MessageBox.Show("Error Iterating over properties in window: " + ex.ToString()); } } } } else { //loop through each property and get value from the element foreach (PropertyInfo property in properties) { try { var propName = property.Name; var propValue = property.GetValue(elementProperties, null); //if property is a basic type then display if ((propValue is string) || (propValue is bool) || (propValue is int) || (propValue is double)) { SearchParameters.Rows.Add(false, propName, propValue); } } catch (Exception ex) { MessageBox.Show("Error Iterating over properties in window: " + ex.ToString()); } } } }
/// <summary> /// /// </summary> /// <param name="elePara"></param> public CurrentElement(AT elePara) { this.elePara = elePara; this.current = elePara.GetMe().Current; }
private void OnStartAcqStandAlone() { MainWindow.log.Info("start acquisition"); if (this.lstboxPlates.SelectedItem == null) { MainWindow.log.Info("Please select a plate first!"); return; } if (GlobalVars.Instance.StartButton == null) { List <string> list = new List <string>(); SystemWindow[] allToplevelWindows = SystemWindow.AllToplevelWindows; SystemWindow systemWindow = null; for (int i = 0; i < allToplevelWindows.Length; i++) { string text = allToplevelWindows[i].Title; if (text != "") { list.Add(text); } text = text.ToLower(); if (text.Contains("tecan") && text.Contains("control")) { systemWindow = allToplevelWindows[i]; GlobalVars.Instance.IControlWindow = systemWindow; break; } } if (systemWindow == null) { string text2 = "c:\\windowsInfo.txt"; File.WriteAllLines(text2, list); MainWindow.log.Error(string.Format("Cannot find icontrol! Windows information has been written to:{0}", text2)); return; } AutomationElement automationElement = AutomationElement.FromHandle(systemWindow.HWnd); AutomationElement.AutomationElementInformation current = automationElement.Current; MainWindow.ShowWindow(current.NativeWindowHandle, 3); Thread.Sleep(200); AutomationElement startButton = automationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Start")); GlobalVars.Instance.StartButton = startButton; } if (!(bool)GlobalVars.Instance.StartButton.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty)) { MainWindow.log.Info("Cannot start acquisition, icontrol is not ready!"); return; } MainWindow.log.Info("Acquisition started."); try { Utility.BackupFiles(); } catch (Exception ex) { MainWindow.log.Error("backup failed:" + ex.Message); } MainWindow.log.Info("backup files"); this.fileWatcher = new FileWatcher(GlobalVars.Instance.WorkingFolder); this.fileWatcher.onCreated += new FileWatcher.Created(this.fileWatcher_onCreated); InvokePattern invokePattern = GlobalVars.Instance.StartButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern.Invoke(); Thread.Sleep(10000); this.fileWatcher.Start(); }
public virtual Type GetTestType(AutomationElement automationElement) { AutomationElement.AutomationElementInformation current = automationElement.Current; return(GetTestType(current.ClassName, current.ControlType, current.FrameworkId, current.Name, current.NativeWindowHandle != 0)); }
/// <summary> /// /// </summary> /// <param name="elePara"></param> public CurrentElement(AT elePara) { this.elePara = elePara; current = elePara.AutomationElement.Current; }
private static AutomationElement.AutomationElementInformation CheckDisplayName(AutomationElement.AutomationElementInformation ElementInfo, XmlElement childInfo) { if (!string.IsNullOrEmpty(ElementInfo.Name)) { childInfo.SetAttribute("DispalyName", ElementInfo.Name); } else { childInfo.SetAttribute("DispalyName", ElementInfo.ClassName); } return(ElementInfo); }
/// <summary> /// show properties of an item - use Reflection technology /// </summary> /// <returns></returns> private bool ShowProperties() { AutomationElement.AutomationElementInformation source = Object.AutomationElement.Current; //(Object as TestStack.White.UIItems.WindowItems.Window). // get all property methods of Object - use Reflection PropertyInfo[] properties = source.GetType().GetProperties(); bool ret = true; try { // currently stop updating the list listView.BeginUpdate(); // if current object is not matched if (CurrentInterface == null || CurrentName == null) { CandidateName = ""; // loop for each property foreach (PropertyInfo prop in properties) { // get property name and value string strName = prop.Name; object objVal = prop.GetValue(source); // create a corresponding item in the list if (objVal != null) { ListViewItem item = new ListViewItem(strName); string strVal = objVal.ToString(); if (objVal is System.Windows.Automation.ControlType) { System.Windows.Automation.ControlType c = objVal as System.Windows.Automation.ControlType; strVal = c.ProgrammaticName.Substring(c.ProgrammaticName.IndexOf('.') + 1); } item.SubItems.Add(strVal); listView.Items.Add(item); if (strName.Equals(ABT.Auto.Constants.PropertyNames.AutomationId, StringComparison.CurrentCultureIgnoreCase)) { CandidateName = CandidateName + strVal; } else if (strName.Equals(ABT.Auto.Constants.PropertyNames.ControlType, StringComparison.CurrentCultureIgnoreCase)) { CandidateName = strVal + CandidateName; } } } } else if (Object is TestStack.White.UIItems.WindowItems.Window) { // loop for each property foreach (PropertyInfo prop in properties) { // get property name and value string strName = prop.Name; object objVal = prop.GetValue(source); // create a corresponding item in the list if (objVal != null) { ListViewItem item = new ListViewItem(strName); string strVal = objVal.ToString(); if (objVal is System.Windows.Automation.ControlType) { System.Windows.Automation.ControlType c = objVal as System.Windows.Automation.ControlType; strVal = c.ProgrammaticName.Substring(c.ProgrammaticName.IndexOf('.') + 1); } item.SubItems.Add(strVal); if (Object is TestStack.White.UIItems.WindowItems.Window && CurrentInterface.Name.Equals(CurrentName, StringComparison.CurrentCultureIgnoreCase) && CurrentInterface.Properties.ContainsKey(strName.ToLower())) { item.Checked = true; item.Font = new Font(SystemFonts.DefaultFont, FontStyle.Bold); listView.Items.Insert(0, item); } else // just show the property { listView.Items.Add(item); } } } } else { // loop for each property foreach (PropertyInfo prop in properties) { // get property name and value string strName = prop.Name; object objVal = prop.GetValue(source); // create a corresponding item in the list if (objVal != null) { ListViewItem item = new ListViewItem(strName); string strVal = objVal.ToString(); if (objVal is System.Windows.Automation.ControlType) { System.Windows.Automation.ControlType c = objVal as System.Windows.Automation.ControlType; strVal = c.ProgrammaticName.Substring(c.ProgrammaticName.IndexOf('.') + 1); } item.SubItems.Add(strVal); if (CurrentInterface.Controls.ContainsKey(CurrentName) && CurrentInterface.Controls[CurrentName].ContainsKey(strName.ToLower())) { item.Checked = true; item.Font = new Font(SystemFonts.DefaultFont, FontStyle.Bold); listView.Items.Insert(0, item); } else // just show the property { listView.Items.Add(item); } } } } } catch (InvalidCastException) { // some error occured, we cannot show the properties, so the Object is considered as invalid ret = false; } finally { // resume updating the list listView.EndUpdate(); } return(ret); }
public static bool IsPrimaryControl(this AutomationElement automationElement) { AutomationElement.AutomationElementInformation elementInformation = automationElement.Current; return(ControlDictionary.Instance.IsPrimaryControl(elementInformation.ControlType, elementInformation.ClassName, elementInformation.Name)); }