一.可用于locator的对象
text,resource-id,content-desc (通过UI automator获取),xpath
当控件存在前三个属性值时,该属性名称在代码中应写成:text 写成 name = 控件属性值resource-id 写成 id = 控件属性值content-desc 写成 accessibility_id = 控件属性值
二.通过xpath定义元素使用精确匹配和模糊匹配
模糊匹配:xpath=//*[contains(@控件属性名称,属性值)]
精确匹配:
xpath=//android.widget.TextView[@text='点击分享密码']
/../following-sibling::android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ImageView
精确匹配需找到唯一起始路径,然后再通过寻找父级,子级来填写路径,xpath的详细使用方法可自行百度
三.Click element | locator
可实现90%以上的点击操作,当然也可以通过tap,click button四.Android 手机常用硬件操作
Press keycode 数字3 (home键) 82 (Menu键) 4(back键) 24 (音量增加键 ) 25(音量增减键 )五.常用关键字:
1. Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=1560ab67 appPackage=com.android.settings appActivity=MainSettings
2. swipe x轴结束坐标 y轴结束坐标 x轴开始坐标 y轴开始坐标 默认为1000ms
如:swipe 849 934 70 482 1000
3. input text如果要输入中文,需在open application加入两列内容:unicodeKeyboard=True 和 resetKeyboard=True
input text locator text
如:input text id=com.android.browser:id/url 优酷
4.Wait Until Page Contains 和 Wait Until Page Contains element
前者是等待页面包含某个内容时才执行下一步,后者是等待页面包含某个元素时才执行下一步
如:Wait Until Page Contains Element name=优酷 :FOR ${i} in range 20 \ swipe 0 1362 0 210 1000 页面出现优酷的文本内容时,才开始执行for循环
5.Get Matching Xpath Count 计算xpath中控件的个数如:
${num} Get Matching Xpath Count xpath=//*[contains(@text,'优酷')]计算文本内容为优酷的控件个数
6.Page Should Contain Text 和 Page Should Contain Element页面应该包含某个内容和某个元素,可用作页面检查
7.Sleep | 2 #等待2秒
8.Close application #关闭应用
9.Background App | 5 #后台运行app 5秒
10.Remove application | 包名 #删除设备上的应用
11.Clear Text | locator 清空文本框内容
12.Hide Keyboard 隐藏键盘