0

对于 UI 黑盒测试,我需要验证某个 UI 交互,这会导致通过以下方式打开某个目录Process.Start("Some Folder");

代码的实现已经过单元测试。在执行单元测试时,我模拟并验证了对此的调用,但 UI 已完全集成,我需要验证绑定是否正确设置(它们依赖于 CommandParameter)。缺少绑定会导致控制台中出现错误 40,但仅在运行时检测到调用缺少参数或参数错误的命令。

好吧,Process Explorer 向我展示了 explorer.exe 打开的句柄列表,但它们都被标记为文件,并且有很多文件和目录及其句柄没有直接显示为 Windows 任务栏中的打开目录。

4

1 回答 1

0

好。解决方案是如此的微不足道,以至于让我大吃一惊。我尝试了各种方法,例如使用 WinApi 挂钩挂钩 explorer.exe 和 ShellExecute WinApi 调用以及托管包装器。然后我想到了截图分析:/

当我使用 White 进行 WPF UI 测试时,它本身在很大程度上依赖于 Microsoft 强大的 UIAutomation 框架,并且 UIAutomation 几乎可以完成我通过自动化定位窗口所需的一切:

 var desktop = AutomationElement.RootElement;
 foreach (AutomationElement element in desktop.FindAll(TreeScope.Children, Condition.TrueCondition))
 {
     if (element.Current.ClassName != "CabinetWClass")
     {
          continue;
     }
     Console.WriteLine("{0}, {1}",element.Current.Name, element.Current.ClassName);
 }

不要忘记添加 UIAutomationClient 和 UIAutomationTypes 程序集和using System.Windows.Automation;

于 2013-10-18T06:18:02.680 回答