Element Attribute Should Match 关键字用来判断元素的属性值是否和预期值匹配,该关键字接收四个参数[ locator | attr_name | match_pattern | regexp=False ],当通过locator识别到元素超过1个元素时,会默认选择第一个元素,attr_name参数代表所选元素的属性的名称,match_pattern参数代表预期匹配值。Regexp代表了匹配时是否通过正则表达式来进行匹配。

示例1:使用Element Attribute Should Match 关键字来判断通过locator为id=com.example.calculator:id/factorone和attr_name=name 获取到的值是否能和预期值匹配。在这里依旧采用上面使用的APP来做操作示例。

Open Application   http://localhost:4723/wd/hub  platformName=Android platformVersion=22       deviceName=98YFBP522VSU       app=C:/Users/yongqing/Desktop/app-debug.apk   appPackage=com.example.calculator    appActivity=MainActivity

Element Attribute Should Match

id=com.example.calculator:id/factorone       name       输入框

执行结果:

Starting test: RobotFrameworkTest1.TestSuite5.TestCase017

20170513 15:48:54.838 :  INFO : msg:find id=com.example.calculator:id/factorone

20170513 15:48:54.839 :  INFO : prefix: id

20170513 15:48:54.840 :  INFO : criteria: com.example.calculator:id/factorone

20170513 15:48:56.622 :  INFO : elements: [<appium.webdriver.webelement.WebElement (session="6708d455-65b8-4af7-8d7c-ea86e7f039f3", element="1")>]

20170513 15:48:56.745 :  INFO : Element 'id=com.example.calculator:id/factorone' attribute 'name' is '输入框'

Ending test:   RobotFrameworkTest1.TestSuite5.TestCase017

从执行结果看,Element 'id=com.example.calculator:id/factorone' attribute 'name' is '输入框',正好和” 输入框”能匹配上。

示例2:改用locator为class=android.widget.Butto和attr_name=name来进行匹配验证,并且看一下,当locator匹配到多个元素时是如何进行处理。

Open Application   http://localhost:4723/wd/hub  platformName=Android platformVersion=22       deviceName=98YFBP522VSU       app=C:/Users/yongqing/Desktop/app-debug.apk   appPackage=com.example.calculator    appActivity=MainActivity

Element Attribute Should Match   class="android".widget.Button  name       计*  True

执行结果:

Starting test: RobotFrameworkTest1.TestSuite5.TestCase018

20170520 15:06:29.527 :  INFO : msg:find class=android.widget.Button

20170520 15:06:29.527 :  INFO : prefix: class

20170520 15:06:29.527 :  INFO : criteria: android.widget.Button

20170520 15:06:31.214 :  INFO : elements: [<appium.webdriver.webelement.WebElement (session="dce6f097-98d2-4632-8708-598e2f693721", element="1")>, <appium.webdriver.webelement.WebElement (session="dce6f097-98d2-4632-8708-598e2f693721", element="2")>]

20170520 15:06:31.214 :  INFO : CAUTION: 'class=android.widget.Button' matched 2 elements - using the first element only

20170520 15:06:31.243 :  INFO : Element 'class=android.widget.Button' attribute 'name' is '计*'

Ending test:   RobotFrameworkTest1.TestSuite5.TestCase018

从执行结果看:当通过class=android.widget.Button获取到两个元素时,默认只会使用第一个元素,从结果看能和预期结果匹配上。

RobotFramework自动化测试框架-移动手机自动化测试Element Attribute Should Match关键字的使用的更多相关文章

  1. RobotFramework自动化测试框架-移动手机自动化测试AppiumLibrary介绍

    在使用AppiumLibrary库时,需要预先安装好Appium自动化工具,Appium官网地址为:http://appium.io/ Appium的GitHub地址为:https://github. ...

  2. RobotFramework自动化测试框架-移动手机自动化测试Click Element关键字的使用

    Click Element关键字用来模拟点击APP界面上的一个元素,该关键字接收一个参数[ locator ] ,这里的locator指的是界面元素的定位方式. 示例1:使用Click Element ...

  3. RobotFramework自动化测试框架-移动手机自动化测试Click Element At Coordinates关键字的使用

    Click Element At Coordinates关键字通过一个具体的坐标点,来模拟点击一个Element,该关键字接收两个参数[ coordinate_X | coordinate_Y ]. ...

  4. RobotFramework自动化测试框架-移动手机自动化测试Get Element Location关键字的使用

    Get Element Location关键字用来获取一个Element的Location位置,该关键字接收一个参数[ locator ] 示例1:使用Get Element Location来获取一 ...

  5. RobotFramework自动化测试框架-移动手机自动化测试AppiumLibrary库其它的常见自动化关键字

    关键字 使用描述 Close Application 关闭掉当前已经打开的APP Application,该关键字不需要接收任何的参数,但是使用该关键字的前提是已经打开了一个APP Applicati ...

  6. RobotFramework自动化测试框架-移动手机自动化测试Input Text和Click Button关键字的使用

    Input Text和Click Button Input Text 关键字一般用来给输入框进行输入操作,该关键字接收两个参数[ locator | text ]. 示例1:启动安卓手机上一个APP的 ...

  7. RobotFramework自动化测试框架-移动手机自动化测试Get Network Connection Status和Set Network Connection Status关键字的使用

    Get Network Connection Status关键字用来获取手机的网络连接状态.在获取到连接状态后,会返回不同的数字. Set Network Connection Status关键字用来 ...

  8. RobotFramework自动化测试框架-移动手机自动化测试Clear Text关键字的使用

    Clear Text关键字用来清除输入框的数据,该关键字接收一个参数[ locator ],这里的locator指的就是界面元素的定位方式. 示例1:Clear Text清除输入框数据时,采用reso ...

  9. RobotFramework自动化测试框架-移动手机自动化测试Open Application关键字的使用

    在AppiumLibrary库中,Open Application关键字用来打开一个待测试移动APP. 示例1:连接本机已经打开的appium服务端,打开一个待测试的安卓APP,指定测试平台为Andr ...

随机推荐

  1. python利用django实现简单的登录和注册,并利用session实现了链接数据库

    利用session实现与数据库链接,登录模块(在views.py) def login(request): # return HttpResponseRedirect('/') # 判断是否post方 ...

  2. 微信小程序入门(一)

    想必当你对官方文档了解地差不多的时候,一颗跃跃欲试的心就开始骚动了吧. 开发小程序之前的准备工作: 1).准备一个域名 2).准备一台云服务器 3).搭建小程序的后台,博主的小程序后台请求的的是自己写 ...

  3. 项目实战2—LVS负载均衡

    负载均衡集群企业级应用实战-LVS 实现基于LVS负载均衡集群的电商网站架构 随着业务的发展,网站的访问量越来越大,网站访问量已经从原来的1000QPS,变为3000QPS,网站已经不堪重负,响应缓慢 ...

  4. 新建Vue项目

    新建Vue项目 1.安装Vue命令行工具,webpack和git,使用淘宝镜像CNPM.参考http://www.imooc.com/video/12299 2.打开命令行,进入到要存放的目录,win ...

  5. 初识Redux-Saga

    Redus-saga是一个redux的中间件,主要用来简便而优雅的处理redux应用里的副作用(side effect相对于pure function这类概念而言的).它之所以可以做到这一点主要是使用 ...

  6. pt-query-digest

    pt-query-digest默认查询时间分布 # Query_time distribution # 1us # 10us ##################################### ...

  7. MarkdownPad2测试

    IO利用率统计 SAS SSD MegaRaid

  8. UWP更改标题栏颜色

    你是否因为UWP标题栏太丑而想过改变?那么这篇文章或许可以帮助你美化UWP界面,让你的UWP的标题栏也变好看 这里的代码,都要在MainPage的构造函数中.如果你在App类中更改了首页,则在该首页的 ...

  9. 社群公会GangSDK:程序员入行AI领域需要哪些技能?

    作为一名Android开发工程师,身边总有些同行很焦虑,看着人工智能越来越火,总是担心Android要不行了,所以,我们需要转行么?Android还能走多久?其实,无论是对于Android还是iOS开 ...

  10. input[type='file']样式美化及实现图片预览

    前言 上传图片是常见的需求,多使用input标签.本文主要介绍 input标签的样式美化 和 实现图片预览. 用到的知识点有: 1.input标签的使用 2.filelist对象 和 file对象 3 ...