2
votes

I have started to automate my windows application using coded UI tests recently and facing issue while accessing some of the MSAA control. I am hand coding my automation and do not want to add controls to UI Map and then use it.

The control on which I got stuck is a treeItem on a left pane which selects machine and details are displayed in left over client area at the center.

I have tried to search control using properties as shown by crosshair onto the UI control but in vain.

Below is the code I have tried -

UITestControl machine = new UITestControl(App);
        machine.TechnologyName = "MSAA";
        machine.SearchProperties.Add(WinTreeItem.PropertyNames.ControlType,     "TreeItem");
        machine.SearchProperties.Add(WinTreeItem.PropertyNames.Name, "Machine1");
        machine.SearchProperties.Add(WinTreeItem.PropertyNames.ControlName, "m_tvPlantStructureView");
Mouse.Click(machine); // This code gives an error

ERROR-

Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details: TechnologyName: 'MSAA' ControlType: 'TreeItem' Name: 'Machine1' ControlName: 'm_tvPlantStructureView' ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

Refer to attachments. Let me know, what is the problem and what process to follow to completely get away of such kind of errors of controls not recognized in future.

Currently, I follow the method of doing a crosshair and getting properties and then coding on that property of control to automate user actions and assertions. But this way does not always work.

Let me know if there is any better way of doing it.

2
What control are you talking about? DevExpress, Infragistics, your custom control or ordinary .NET shipped? - nikita

2 Answers

0
votes

You need to do a hierarchy search. Create 2 controls: first the Treeview as Window. With control name m_tvPlantStructureView, then create a new TreeItem with name Machine1.

var treeView = new WinWindow(App);
treeView.SearchProperties.Add(WinWindow.PropertyNames.ControlName, "m_tvPlantStructureView");

var machine= new WinTreeItem(treeView);
machine.SearchProperties.Add(WinTreeItem.PropertyNames.Name, "Machine1");

Mouse.Click(machine); // This code gives an error

Another thing if this fails is to remove App from treeview and add window title.

Let me know if you have any questions.

var treeView = new WinWindow();
treeView.WindowTitles.Add("mywindowname");
treeView.SearchProperties.Add(WinWindow.PropertyNames.ControlName, "m_tvPlantStructureView");

var machine= new WinTreeItem(treeView);
machine.SearchProperties.Add(WinTreeItem.PropertyNames.Name, "Machine1");

Mouse.Click(machine); // This code gives an error
0
votes

Before doing the mouse clik, I perform a search of the control using

machine.Find();

After that, I check if machine has a value distinct of null, and if is it not null, i perform the click.