AppiumLibrary常用关键字

通过上一章节,open application关键字的使用,相信大家对手机自动化充满了兴趣,那么今天这一章节,主要介绍AppiumLibrary中常用关键字的使用。

一、实用函数

关键字

含义

实例

备注

Click Button

点击按钮

Click Button 注销

这里“注销”的class属性,必须是Button

Click Element

点击元素

Click Element [locator]

Locator可以是resource-id,也可以是xpath;但必须是当前页面唯一存在的;一般用该关键字可以完成所有元素点击

Click Text

点击文字

Click Text 我的

“我的”需要是当前页面唯一存在的

Input Text

在指定元素中输入文本

InputText [locator] 111111

Locator可以是resource-id,也可以是xpath

Swipe

滑动屏幕

Swipe 1000 1800 100 1800

 

 

Get Text

获取某标签内容

${account}   Get Text  [locator]  

获取内容后存储到指定变量中,从而在后续脚本中调用该内容

 

二、校验函数

关键字

含义

实例

备注

Element Name Should Be

检查元素的name属性

 

Element Name Should Be  [locator]  登录

locator可以是resource-id,也可以是xpath

Element Should Be Enabled

检查元素是否可用/可见

Element Should Be Enabled  [locator]

 

Page Should Contain Element

检查界面包含某些元素

Page Should Contain Element   [locator]

 

Page Should Contain Text

检查界面包含某些文字信息

Page Should Contain Text  预约挂号

 

Page Should Not Contain Element

检查界面不包含某些元素

Page Should Not Contain Element  [locator]

 

Page Should Not Contain Text

检查界面不包含某些文字信息

Page Should Not Contain Text  预约挂号

 

 

三、等待函数

关键字

含义

实例

备注

Wait Until Page Contains

等待直到界面中包含某些文字,才进行下一步

Wait Until Page Contains  预约挂号

默认等待时间为5s

Wait Until Page Contains Element

等待直到界面中包含某些元素,才进行下一步

Wait Until Page Contains Element   [locator]

locator可以是resource-id,也可以是xpath

Wait Until Page Does Not Contain

等待直到界面中不包含某些文字,才进行下一步

Wait Until Page Does Not Contain  预约挂号

 

Wait Until Page Does Not Contain Element

 

等待直到界面中不包含某些元素,才进行下一步

Wait Until Page Does Not Contain Element  [locator]

 

 

 

四、其他函数

1.条件判断函数

关键字:Run Keyword If

用法:

Run Keyword If

…ELSE IF   

…ELSE

实例:

1)用Run Keyword If执行单条语句时

2)用Run Keyword If执行多条语句时,在需要执行多条语句的if或else if或else后,增加关键字:Run Keywords

 

 2.检查某关键字的返回状态

关键字:Run Keyword And Return Status

返回值:布尔值,True False

实例   :通常和Run Keyword If关键字搭配使用       

${isMessage} Run Keyword And Return Status Wait Until Page Contains Element [locator]
Run Keyword If ${isMessage} do something  

 

 

含义  :判断当前界面中是否存在取消按钮;如果存在,则do something

 

3.For循环

关键字:For

实例:

1)For循环单独使用时

2)For循环嵌套Run Keyword If语句,退出循环

 

4.自定义关键字

创建方法:测试项目-New Resource-New User Keyword

实例:

在需要使用自定义关键字的测试套件Edit标签页,Resource导入关键字,导入结果为蓝色,则导入正确

用法:导入resource后,在测试用例中,直接调用

 

常用关键字就介绍到这里。

 

posted @ 2017-01-17 14:56  lynnLi  阅读(11581)  评论(0编辑  收藏  举报