【发布时间】:2015-06-27 02:12:56
【问题描述】:
我刚刚开始使用 AutomationElement,因为我们想对自定义控件进行集成测试,我认为我应该使用 AutomationElement。
我已经成功创建了一个包含自定义控件的Window,并且可以成功获取该窗口和控件的AutomationElements
// Retrieve the View
System.Windows.Automation.Condition viewCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, "MyTestView");
AutomationElement view = AutomationElement.RootElement.FindFirst(TreeScope.Children, viewCondition);
Assert.IsNotNull(view);
// Retrieve the CustomControl
System.Windows.Automation.Condition comboboxCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, "MyCustomControl");
AutomationElement combobox = view.FindFirst(TreeScope.Children, comboboxCondition);
Assert.IsNotNull(comboboxCondition);
现在,我想做的是使用,例如 ValuePattern。这就是我感到困惑的地方。
为了寻找信息,我在 referencesource.microsoft.com 上搜索了 WPF 源。遇到了ComboboxAutomationPeer,它实现了IValueProvider,所以现在一头雾水。
我应该也实现实现 IValueProvider 的 MyCustomControlAutomationPeer,然后 AutomationElement 将与 ValuePattern 一起使用吗?还是应该让 MyCustomControl 实现 IValueProvider?
【问题讨论】:
-
一个 AutomationPeer 存在于您尝试自动化的应用程序中。就像 WPF 应用程序中的 ComboBox 一样。 AutomationElement 是您在代码中使用的使用 自动化来修补此类 WPF 应用程序的元素。这段代码。
-
感谢您解释汉斯的区别。
标签: c# wpf ui-automation microsoft-ui-automation