Question

I have a large WPF application that I need to run automation tests on. I am using Coded UI test builder. When I hover over a cell in the application I can see all of it properties: automationId, ColumnHeader and more. How is it that when I click the refresh button the spy can't find the control he found just couple of secondes ago?

I have the same problem if I try to find this control using code:

WpfCell myCell = new WpfCell();
myCell.SearchProperties.Add(WpfCustom.PropertyNames.AutomationId,"Cell_1_2");
myCell.DrawHighlight();

The cell is not highlighted and I get ControlNotFoundExceptin.

Was it helpful?

Solution

Finding an element with hit test (cross hair) is not the same as finding it with search (using MSAA/UIA hierarchy). The generated search properties are probably bad. Get the cell with the cross hair, add it to the UIMap then in the UIMap editor check if it can find all of the cell's parents/ancestors then start fiddling with the cell's search properties. Modify, save and search for the cell (Locate the UI Control). Repeat until it works.

As for the code: no. No no no. What that snippet does is try to find a cell element under your desktop. It won't work unless you set the hierarchy. Setting a UI element in the constructor will set it the control's "search limit container" or parent. Something like

var myWindow = new WpfWindow();
var myTable = new WpfTable(myWindow);
var myCell = new WpfCell(myTable);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top