- Get all the controls of our Application Under Test (AUT) and also we will get their properties.
- We will get the number of controls within application of same type (WinButton, WinText etc)
Figure 1: Calculator Application
//Collection of Matching Controls UITestControlCollection controlCol = btn8.FindMatchingControls(); //Select the Name property from Collection via LINQ var controls = controlCol.Select(x => x.Name); //Get the count Console.WriteLine("The number of controls in my AUT is : " + controls.Count()); //Iterate through all the values of all the controls foreach (var control in controls) { Console.WriteLine(control.ToString()); }Here is the complete code
public static void Button8Click() { //Instance for WinWindow UITestControl calcWindow = new UITestControl(); calcWindow.TechnologyName = "MSAA"; calcWindow.SearchProperties[UITestControl.PropertyNames.Name] = "Calculator"; calcWindow.SearchProperties[UITestControl.PropertyNames.ClassName] = "CalcFrame"; //Button UITestControl btn8 = new WinButton(calcWindow); //Collection of Matching Controls UITestControlCollection controlCol = btn8.FindMatchingControls(); //Select the Name property from Collection via LINQ var controls = controlCol.Select(x => x.Name); //Get the count Console.WriteLine("The number of controls in my AUT is : " + controls.Count()); //Iterate through all the values of all the controls foreach (var control in controls) { Console.WriteLine(control.ToString()); } btn8.SearchProperties[UITestControl.PropertyNames.Name] = "8"; Mouse.Click(btn8); UITestControl btn9 = new WinButton(calcWindow); btn9.SearchProperties[UITestControl.PropertyNames.Name] = "9"; Mouse.Click(btn9); UITestControl btnAdd = new WinButton(calcWindow); btnAdd.SearchProperties[UITestControl.PropertyNames.Name] = "Add"; Mouse.Click(btnAdd); UITestControl btn2 = new WinButton(calcWindow); btn2.SearchProperties[UITestControl.PropertyNames.Name] = "2"; Mouse.Click(btn2); UITestControl btn3 = new WinButton(calcWindow); btn3.SearchProperties[UITestControl.PropertyNames.Name] = "3"; Mouse.Click(btn3); UITestControl btnEquals = new WinButton(calcWindow); btnEquals.SearchProperties[UITestControl.PropertyNames.Name] = "Equals"; Mouse.Click(btnEquals); }Here is the Video for the above post