(摘要自:http://blogs.msdn.com/gisenberg/archive/2008/07/12/ui-automation-in-silverlight-simulating-user-interactions.aspx

在 Silverlight 中,UI 自动化(UIA)的相关内容在下列名称空间中:

System.Windows.Automation
System.Windows.Automation.Peers
System.Windows.Automation.Provider

要开放某个自定义控件为支持 UI 自动化的,则需要覆盖 OnCreateAutomationPeer 这个方法(定义在 Control 类中),来返回一个与该控件对应的 AutomationPeer 子类,实质是一个面向 COM 的 wrapper,用来描述和操作目标控件的一些信息,以及设值/取值等操作(用于模拟键盘输入)。

那么,这样做了之后,就可以在 UI Test 的代码里通过自动化的接口,来取得这个 wrapper 对象,并进行相应的自动化测试。

可以用 Windows SDK 里的一个工具 UISpy.exe 来查看 UI 结构信息(     public partial class SearchBar : Control
    {
       [Silverlight] UI 测试/UI 自动化相关知识
 
        
public SearchBar()
        {
            
this.GotFocus += (sender, args)
                
=>
                {
                    
this.SearchText.Focus();
                };
 
            InitializeComponent();
        }
 
       
protected override AutomationPeer OnCreateAutomationPeer()
       {
           
return new SearchBarAutomationPeer(this);
       }
    }

相关文章:

  • 2021-10-27
  • 2021-08-09
  • 2021-11-07
  • 2022-01-21
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
猜你喜欢
  • 2021-06-06
  • 2021-11-10
  • 2021-10-31
  • 2021-07-03
  • 2021-11-21
相关资源
相似解决方案