• 自动化测试: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

  • 相关阅读:
    选择和冒泡
    马尔科夫模型
    网络IO
    java项目相对路径
    MySQL 数据类型
    基于 Token 的身份验证方法
    git 打标签
    git版本回退
    robotframework使用过程中的一些总结
    robotframework安装robotframework-requests库遇到的几种问题
  • 原文地址:https://www.cnblogs.com/Alvin-x/p/3455372.html
Copyright © 2020-2023  润新知