I am working on a coded ui project for a win forms application. I would like to get the main window of the application under test programmatically.
What I tried is:
WinWindow mainWindow = new WinWindow();
mainWindow.TechnologyName = "MSAA";
main.Window.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.Name, "Soft under test", PropertyExpressionOperator.Contains));
mainWindow.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
mainWindow.SearchConfigurations.Remove(SearchConfiguration.VisibleOnly);
mainWindow.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
This fails with:
The playback failed to find the control with the given search properties. Additional Details: TechnologyName: 'MSAA' Name: 'Soft under test' ClassName: 'WindowsForms10.Window' ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
What is the correct way to get the window?