经过上一章节,open application关键字的使用,相信你们对手机自动化充满了兴趣,那么今天这一章节,主要介绍AppiumLibrary中经常使用关键字的使用。app
1、实用函数函数
关键字测试 |
含义spa |
实例blog |
备注ip |
Click Buttonci |
点击按钮it |
Click Button 注销自动化 |
这里“注销”的class属性,必须是Buttonio |
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] |
获取内容后存储到指定变量中,从而在后续脚本中调用该内容 |
2、校验函数
关键字 |
含义 |
实例 |
备注 |
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 预定挂号 |
|
3、等待函数
关键字 |
含义 |
实例 |
备注 |
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]
|
|
4、其余函数
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后,在测试用例中,直接调用
经常使用关键字就介绍到这里。