• RobotFramework


    一、介绍

    AppiumLibrary 是 Robot Framework 的App测试库。

    它使用Appium 与Android 和 iOS应用程序进行通信,类似于Selenium WebDriver与Web浏览器的对话。

    AppiumLibrary是继承和引用appiumandroidlibrary,但重新实现使用appium 1.X技术,它完全支持Python 2.7,但对python 3.3+的支持仍然是实验性的。

    二、定位控件

    AppiumLibrary需要在应用程序中查找元素的所有关键字都使用参数locator。

    当提供locator值时,它将与特定元素类型的键属性进行匹配。支持的定位器(locator)有:

    定位器

    格式

    描述

    identifier

    Click Element | identifier=my_element

    匹配 @id 或 @name 属性

    id

    Click Element | id=my_element

    匹配 @id 属性

    name

    Click Element | name=my_element

    匹配 @name 属性

    xpath

    Click Element | xpath=//UIATableView/UIATableCell/UIAButton

    匹配 XPath

    class

    Click Element | class=UIAPickerWheel

    匹配 class name

    accessibility_id

    Click Element | accessibility_id=t

    匹配 辅助选项

    android

    Click Element | android=new UiSelector().description('Apps')

    匹配 Android UI Automator

    ios

    Click Element | ios=.buttons().withName('Apps')

    匹配 iOS UI Automation

    css

    Click Element | css=.green_button

    匹配 css in webview

     

     

     

     

     

     

     

     

     

     

      
     
     
     

     

    三、定位工具

    1. Appium通过 uiautomatorviewer.bat工具来查看控件的属性,该工具位于Android SDK的Tools目录下。
     
     
    2. 双击打开即可,为了方便起见,建议添加快捷方式到桌面。
     
     
    3. 然后USB连接真机(安装手机驱动,授权连接) 或者打开模拟器,点击获取详细布局。
     
     

    四、定位元素

    1. identifier 定位

    说明:匹配 @id 或 @name 属性,分别对应 resource-id 和 text 属性。

    案例:点击计算器数字“ 9 ”,可以使用id定位,也可以使用name定位。

    Click Element  identifier=com.android.calculator2:id/digit_9
    Click Element identifier=9

     

    2. id 定位 

    说明:匹配 @id 属性,对应 resource-id 属性。

    案例:点击计算器输入框,id可以指定也可以不指定,如果不指定策略,默认就是id定位。

    Click Element  id=com.android.calculator2:id/formula
    Click Element com.android.calculator2:id/formula

    3. name 定位

    说明:匹配 @name 属性,对应 text 属性。

    案例:点击计算器数字“ 9 ”。

    Click Element name=9              

    4. xpath 定位

    说明:匹配 Xpath ,这也是功能最强大的一种定位方式,不过通常用于web自动化。

    案例:点击计算器数字“ 7 ”。

    Click Element xpath=//android.widget.Button[contains(@text,'7')]

    附加Xpath定位表达式说明:

    5. class 定位

    说明:匹配 class name ,对应 class 属性,但通常class属性都不唯一。

    案例:点击计算器数字“ 6 ”。

    Click Element class=android.widget.Button 

    6. accessibility_id 定位

    说明:匹配 辅助选项,这个方法属于Appium扩展的定位方法,主要就是content-desc属性。

    案例:点击计算器加号“ + ”。

    Click Element accessibility_id=plus       

    7. android 定位

    说明:匹配 Android UI Automator。

    案例:点击计算器加号“ + ”。

    Click Element android=new UiSelector().description("plus")

     

    8. css 定位

    说明:匹配 css in webview,只适用于webview的html页面,继承自webdriver。

    9. ios 定位

    说明:匹配 iOS UI Automation,很显然只适用于ios系统。

    以上就是笔者对RF框架Appium引用控件定位总结,个人感受比较好用的定位器是id、name、xpath、accessibility_id,

    其他几个相对比较局限,用的不多,其中css、ios定位笔者还未使用过,读者有兴趣可以自己去发掘一下。

  • 相关阅读:
    减少注入元
    浅谈微服务基建的逻辑
    Linux系统Java环境安装配置
    ASP.NET Core 依赖注入
    C#并发编程实例讲解-概述(01)
    Linux系统从安装开始
    关于C#获取动态的时间差函数
    SQL Server 存储过程
    jQuery选择器大全(48个代码片段+21幅图演示)
    对齐方式
  • 原文地址:https://www.cnblogs.com/leozhanggg/p/9670652.html
Copyright © 2020-2023  润新知