自动化测试:UIA

      在win8/8.1上做Metro app 的自动化测试,其中主要用到UIA相关的技术,下面就作一个简单的记录:

UIA原理图:(摘抄)

   

 

UIA基础:(VB.net版)

1.添加应用:UIAutomationClient.dll ,UIAutomationTypes.dll

 

2.UIA 的一些常用方法: 

1>对于一般的桌面应用程序,我们首先都会获取根元素,然后再通过FindFirst/FindAll 来寻找子元素: 

Dim Desktop As AutomationElement = AutomationElement.RootElement

  但是在Win8中对于Metro UI这个就不好用了,所以我们得用它的另外一个方法:

AutomationElement.FromHandle(HWND).FindFirst(......

 

2>根据条件查找:

单一条件: 

.FindAll(TreeScope.Children, New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem))

多条件:

.FindFirst(TreeScope.Descendants, New AndCondition(New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List),
New PropertyCondition(AutomationElement.AutomationIdProperty, "xx")))

找到所以孩子:

.FindAll(TreeScope.Children, Condition.TrueCondition)

 

 

3>获取属性值:   

.GetCurrentPropertyValue(AutomationElementIdentifiers.NameProperty)

 

4>操作:

点击button:

DirectCast(btn.GetCurrentPattern(InvokePattern.Pattern), InvokePattern).Invoke()

选择:

DirectCast(ele.GetCurrentPattern(SelectionItemPattern.Pattern), SelectionItemPattern).Select()
如果没选中:
If DirectCast(ele.GetCurrentPattern(SelectionItemPattern.Pattern), SelectionItemPattern).Current.IsSelected() = False Then
end if

ToggleSwitchs:如果=off ,则设为ON

If DirectCast(toggleswitch.GetCurrentPattern(TogglePattern.Pattern), TogglePattern).Current.ToggleState.ToString.Equals("Off") Then
DirectCast(toggleswitch.GetCurrentPattern(TogglePattern.Pattern), TogglePattern).Toggle() End If

combbox:

DirectCast(combbox.GetCurrentPattern(ExpandCollapsePattern.Pattern), ExpandCollapsePattern).Expand()

editbox:

设值:
DirectCast
(editbox.GetCurrentPattern(ValuePattern.Pattern), ValuePattern).SetValue("xx")
获取里面的值:
DirectCast(editbox.GetCurrentPattern(ValuePattern.Pattern), ValuePattern).Current.Value

获取第一个子孩子的值:

TreeWalker.ControlViewWalker.GetFirstChild(xxEle)

获取元素的坐标:

GetCurrentPropertyValue(AutomationElement.ClickablePointProperty).ToString()

 

参考:Test win8 app

http://blogs.msdn.com/b/windowsappdev/archive/2012/09/04/automating-the-testing-of-windows-8-apps.aspx

转载于:https://www.cnblogs.com/Alvin-x/p/3455372.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值