- 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 Thanks for reading the post and watching the video !!! Please leave your comments and let me know if you like it and wanna improve it. Thanks, Karthik KK
Hi,
I am getting an error at:
var controls = controlCol.Select(x => x.Name);
I seems like controlCol.Select() method doesn’t exists? I’m using VS 2013 Premium.
Thanks
-Asif
Hi Asif,
Thanks for reading the post !!
The Select() is the extension method which is available with LINQ.
Try to add the namespace for LINQ and this should work.
Thanks,
Karthik KK
Hi Asif,
Here is the code, to get all the menu item controls
And its working fine for me !!!
I have added following LINQ reference
Thanks,
Karthik KK
Hi Karthik,
Thanks for your very useful information.
I just want to leave a note for those who have DevExpress Components in their applicatons.
It works well with MSAA control. However, FindMatchingControls() method is not able to get controls for DevExpress components due to the reasons that there is no DXTestControlCollection, as far as I inferred.
The only solution to be able to find the controls is defining the whole control hierarchy.
The issue had my hands full for days. Just wanted to inform people who will face with the same problem 🙂
Thank you for your contribution to community, this will help !!!
Is there a way to access more than MSAA / UAI properties of an object? In Test Complete we had access to all public class objects, methods, and variables of an object. We moved away from test complete because of performance and stability issues, but want to maintain that level of testing.
Need a help with instance property that is used for indexing child controls.
Could you please provide guidance.
Please let me know if you have any video regarding this as well.
Thanks,
Sagar
How to handle tabpages of tabcontrol in windows application, handcoded ui
Great article, but I am getting an error on FindMAtchingControls
Error message:”+ $exception {“No search information has been specified. To search for a control, you must specify one or more search properties or filter properties.\r\nParameter name: SearchProperties”} System.ArgumentException
”
Any help would be appreciated
Full code:
public UITestControl findControl(WpfControl parentControl, string controlProperty)
{
UITestControl cntrlToFind = new UITestControl(parentControl);
UITestControlCollection controlCol = cntrlToFind.FindMatchingControls();
var controls = controlCol.Select(x => x.Name);
Console.WriteLine(“The number of controls in my AUT is : ” + controls.Count());
foreach (var control in controls)
{
Console.WriteLine(control.ToString());
}
cntrlToFind.SearchProperties[UITestControl.PropertyNames.Name] = controlProperty;
return cntrlToFind;
}
Hi ! Since I’m getting a similar kind of error, it would be great help if you could let me know how did you rectify it? Also, is there any alternative available for the same?
Hi Karthik,
Thanks for sharing this information.
I am facing issue in finding controls (it is third party controls – DotNetBars).
Even i am unable to spy these controls . it is throwing Object instance set to null error.
Please suggest me how to automate this control in codedui
Which means the control is either not supported by coded ui or your visual studio has to be reinstalled if it happens to be problem with visual studio installation
(may be, not sure)
Thanks,
Karthik KK
Hi Karthik,
I would like to know how to edit/add properties for a control that doesn’t have a Name/DisplayText, or any other unique property for a desktop application ?
Thanks,
Pro