测试步骤三要素
- 定位、交互、断言
定位
1. Id定位(优先级最高)(重点)
2. XPath定位(速度慢,定位灵活)(重点)
3. Accessibility ID定位(desc)(重点)
4. Uiautomator定位(速度快,语法复杂)
XPath定位
遵循w3c
常用:
not、contains、end_with、start_with
- 绝对定位(不推荐使用)
- 相对定位
//* 当前页面声所有元素
//*[contains(@resource-id,'login')] (重点)
//*[contains(@resource-id,'login') and contains(@text,'登录')] (重点)
//*[contains(@text,'login') or contains(@class,'edit') (了解)
//*[@clickable="true"]//android.widget.TextView[string-length(@text)>0 and string-length(@text)<20] (了解)
//*[contains(@text,'看点')]/ancestor::*//*[contains(@class,'edit')](轴)(了解)
原生定位
写法:
new UiSelector().text(“text”)
滚动查找:
new UiScrollable(new UiSelector() .scrollable(true).instance(0)) .scrollIntoView(new UiSelector().text(“打卡”).instance(0));