我正在为Win Forms应用程序开发一个已编码的ui项目。我想以编程方式获取正在测试中的应用程序的主窗口。
我尝试过的是:
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);
此操作失败,并显示以下信息:
回放未能找到具有给定搜索属性的控件。额外细节: 技术名称:“ MSAA” 名称:“被测软件” 类别名称:'WindowsForms10.Window' ---> System.Runtime.InteropServices.COMException:从对COM组件的调用返回了错误HRESULT E_FAIL。
获取窗口的正确方法是什么?
答案 0 :(得分:0)
不确定该问题是否仍然相关,但这是我用来获取窗口的代码:
this.TechnologyName = "MSAA";
this.SearchProperties.Add(UITestControl.PropertyNames.Name, "MyProgram");
this.SearchProperties.Add(UITestControl.PropertyNames.ControlType, "Window");
this.SearchProperties.Add("ControlName", "TopScreen");
this.SearchConfigurations.Add(SearchConfiguration.ExpandWhileSearching);
也许,您需要ExpandWhileSearching
属性来查找屏幕。