我正在使用Microsoft UI Automation API在NUnit 2.5.10测试中执行WPF应用程序的自动化UI测试。但是,有些情况下,在我的开发机上运行测试能够定位到某些UI元素,但是当相同的脚本在我们的构建代理机器上运行时,它无法定位到这些元素。我找不到代理机器行为不同的原因。我怀疑这与UIAccess标志或UAC有关,但没有遇到具体的内容。请问有人能够提供一些指导,为什么构建代理会有不同的行为,或者如何修复代理以查看与其他机器相同的元素?例如,我有一个comboBox,其中有大约十几个选项。使用Win7 SDK中的“检查对象”工具,我可以看到每个选项都有一个子元素,其中包含实际显示的文本。所以在我的测试代码中,我做了这样的事情:
但在服务器上,我得到了这个:
// get the child elements
var options = comboBoxElement.FindAll(TreeScope.Children, (System.Windows.Automation.Condition) new PropertyCondition(AutomationElement.IsControlElementProperty, (object) true));
foreach (AutomationElement child in viewOptions)
{
var subControls = child.GetChildren();
Console.WriteLine("Child: {0} w/ {1} children", child.Current.Name, subControls.Count);
foreach (AutomationElement subControl in subControls)
Console.WriteLine("SubControl: {0}", subControl.Current.Name);
}
在我的开发机上,我得到了以下结果:
Child: My.BoundObject.ClassName w/ 1 children
SubControl: Displayed Text for first item
Child: My.BoundObject.ClassName w/ 1 children
SubControl: Displayed Text for second item
Child: My.BoundObject.ClassName w/ 1 children
SubControl: Displayed Text for third item
但在服务器上,我得到了这个:
Child: My.BoundObject.ClassName w/ 0 children
Child: My.BoundObject.ClassName w/ 0 children
Child: My.BoundObject.ClassName w/ 0 children
在这两种情况下,检查对象显示子对象。
建立代理和我的本地机器都运行Windows 7 SP1和.Net 4。在这两种情况下,我都是运行nunit-console.exe启动测试。我在机器之间复制整个环境,因此不仅是相同版本的nunit和我的应用程序的二进制文件,而且完全相同的文件、配置、库等。nunit-console正在作为管理员用户运行。