appium简明教程(10)——控件定位基础
狭义上讲,UI级的自动化测试就是让机器代替人去点来点去的过程。
但机器去点什么(点上面还是点左边),怎么点(是长按还是轻触),这些东西是必须由代码的编写者所指示清楚的。
控件定位就是解决机器点什么的问题的。
一般说来,我们可以这样告诉机器:去点登陆按钮。
机器很笨,它并不知道什么是登陆按钮。因为登陆按钮是自然语言的描述。
如果你让一个人去点登陆按钮,那么他其实也是要经过一系列的脑补以后才可以做这件事的。
这个脑补的过程还原如下:
这个一定是个按钮
这个按钮一定在被测的应用上
这个按钮大概上面有登陆这个文字信息
嗯,还真有一个,那么点吧。
这就是人探索性测试的一个简单过程。一般来说,如果你给出的信息不太充分,人类还是可以通过一系列的探索性思维去理解你的描述的。这个属于心理学的问题,不展开解释。
但是机器并不是人,如果你给出的描述不精确的话,机器是不会自发性的进行探索和脑补的。
因此控件定位就是精确的描述控件特征并告诉机器的过程。
本文版权归乙醇所有,欢迎转载,但请注明作者与出处,严禁用于任何商业用途
控件的特征就是控件的属性,我们可以通过上一讲中的uiautomatorviewer去获取。
在appium的定位世界里,下面这些方法是可以为我们使用的。也就是说,我们通过下面几个约定好的方式,按照webdriver和appium的DSL(自行搜索并理解)进行控件特征的描述和定位。
继承自webdriver的方法,也就是通过这3个特征可以定位控件
- find by "class" (i.e., ui component type,andorid上可以是android.widget.TextView)
- find by "xpath" (i.e., an abstract representation of a path to an element, with certain constraints,由于appium的xpath库不完备的原因,这个不太推荐)
- find by "id"(android上是控件的resource id)
由Mobile JSON Wire Protocol 协议中定义的方法,更适合移动设备上的控件定位
-ios uiautomation: a string corresponding to a recursive element search using the UIAutomation library (iOS-only)-android uiautomator: a string corresponding to a recursive element search using the UiAutomator Api (Android-only)accessibility id: a string corresponding to a recursive element search using the Id/Name that the native Accessibility options utilize.
在appium 的client对Mobile JSON Wire Protocol中定义的方法进行了封装,使其调用起来更加方便
ruby篇
find_element :accessibility_id, 'Animation'
find_elements :accessibility_id, 'Animation'
find_element :uiautomator, 'new UiSelector().clickable(true)'
find_elements :uiautomator, 'new UiSelector().clickable(true)'
当然了,你也可以使用原生的webdriver方法
find_element id: 'resource_id'
另外,ruby lib里提供了一些非常好用的简便方法来进行控件的定位,好写,好读。
- text(value_or_index) :Find the first TextView that contains value or by index. If int then the TextView at that index is returned.
- button(value_or_index):Find the first button that contains value or by index. If int then the button at that index is returned
更多请看这里
python篇
el = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Animation")')
self.assertIsNotNone(el)
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
self.assertIsInstance(els, list)
el = self.driver.find_element_by_accessibility_id('Animation')
self.assertIsNotNone(el)
els = self.driver.find_elements_by_accessibility_id('Animation')
self.assertIsInstance(els, list)
总的来说就是在driver里增加了
- find_element_by_accessibility_id
- find_elements_by_accessibility_id
- find_element_by_android_uiautomator
- find_element_by_android_uiautomator
等方法
java篇
前面也讲过了,新增了这些方法
findElementByAccessibilityId()
findElementsByAccessibilityId()
findElementByIosUIAutomation()
findElementsByIosUIAutomation()
findElementByAndroidUIAutomator()
findElementsByAndroidUIAutomator()
讨论:从上面可以看出来,python 和 java client对移动端控件定位的封装是比较初级的。ruby lib中封装了很多方便和简洁的方法,因此可以看出,使用ruby lib是优于python和java的选择。当然,如果忽略性能的话。
下一节我们开始具体看下如何用resource id去定位控件。
本文版权归乙醇所有,欢迎转载,但请注明作者与出处,严禁用于任何商业用途
appium简明教程(10)——控件定位基础的更多相关文章
- 2013 duilib入门简明教程 -- 简单控件介绍 (12)
前面的教程应该让大家对duilib的整体有所映像了,下面就来介绍下duilib具体控件的使用. 由于官方没有提供默认的控件样式,所以我就尽量使用win7或者XP自带的按钮样式了,虽然界 ...
- Appium移动端自动化测试--控件定位方法
常用定位手段 id Accessibility ID XPath 控件基础知识 DOM: Document Object Model文档对象模型 DOM应用:最早应用于HTML和Javascript的 ...
- 2013 duilib入门简明教程 -- 复杂控件介绍 (13)
首先将本节要介绍的控件全部拖到界面上,并调整好位置,如图: 然后将Name属性改成其他名字, 不能是[控件名+UI+数字]这种,因为这是DuiDesigner ...
- appium简明教程
appium简明教程 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use to automate mobi ...
- 转载乙醇大师的appium简明教程
appium简明教程(11)——使用resource id定位(仅支持安卓4.3以上系统) 乙醇 2014-06-28 21:01 阅读:16406 评论:21 appium简明教程(10)——控件定 ...
- duilib进阶教程 -- TreeView控件(6)
代码下载:http://download.csdn.net/detail/qq316293804/6483905 上一个教程中,界面已经和迅雷一模一样啦,大小和位置一个像素都不差哟,亏得Alberl调 ...
- appium简明教程(11)——使用resource id定位(仅支持安卓4.3以上系统)
上一节乙醇带大家了解了appium的定位策略.实际上appium的控件定位方式是完全遵守webdriver的mobile扩展协议的. 这一节将分享一下如何使用resource id来定位android ...
- 转载:Robotium之Android控件定位实践和建议(Appium/UIAutomator姊妹篇)
来源于:http://blog.csdn.net/zhubaitian/article/details/39803857 1. 背景 为保持这个系列的一致性,我们继续用SDK自带的NotePad实例应 ...
- Robotium之Android控件定位实践和建议(Appium/UIAutomator姊妹篇)
本人之前以前撰文描写叙述Appium和UIAutomator框架是怎样定位Android界面上的控件的. UIAutomator定位Android控件的方法实践和建议 Appium基于安卓的各种Fin ...
随机推荐
- slf4j、jcl、jul、log4j1、log4j2、logback大总结
1 系列目录 jdk-logging.log4j.logback日志介绍及原理 commons-logging与jdk-logging.log4j1.log4j2.logback的集成原理 slf4j ...
- 使用jstl报错:According to TLD or attribute directive in tag file, attribute value does not accept any expressions
使用jstl报错:According to TLD or attribute directive in tag file, attribute value does not accept any ex ...
- MyBatis - (一) 基本数据操作命令和简单映射
1. 简单的select映射 <mapper namespace="com.mybatis3.mappers.StudentMapper"> <select id ...
- jQuery函数的等价原生函数代码示例
选择器 jQuery的核心之一就是能非常方便的取到DOM元素.我们只需输入CSS选择字符串,便可以得到匹配的元素.但在大多数情况下,我们可以用简单的原生代码达到同样的效果. .代码如下: //---- ...
- Spring Jdbc事例说明(三)
上一篇文章已经讲解了如何使用Spring搭建工程,这一篇文章是接着上一篇文章来描述的. 一.载入依赖 新增加了两个依赖,mysql数据库驱动和alibaba数据源包 <!-- mysql驱动包 ...
- 安装MySQL-python报错:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory或者 build\lib.win-amd64-2.7\_mysql.pyd : fatal error LNK1120: 56 unresolved externa
解决办法1: 直接下载MySQL-python-1.2.5.win-amd64/32-py2.7.exe,点击安装 此处要注意自己安装的Python和MySQL版本是64位还是32位,否则在进行安装M ...
- loadrunner脚本001
Action() { ; lr_start_transaction("login"); web_add_cookie("JSESSIONID=061460B7DFF2F7 ...
- C#用openfiledialog文件和savefileDialog打开和保存文件
一 打开文件 Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog ...
- Struts 2相关配置与基本操作演示(案例Demo)
基本介绍 Struts 2 Struts 2是Struts的下一代产品,是在 struts 1和WebWork的技术基础上进行了合并的全新的Struts 2框架.其全新的Struts 2 ...
- ES6学习笔记六:迭代
一:迭代器 它是一种接口,为各种不同的数据结构提供统一的访问机制.任何数据结构只要部署Iterator接口,就可以完成遍历操作(即依次处理该数据结构的所有成员). ES6创造了一种新的遍历命令for. ...