上两篇文章介绍了 自动遍历的测试需求、工具选择和 AppCrawler 的环境安装、启动及配置文件字段基本含义,这里将以实际案例更加细致的说明配置文件的用法和一些特殊场景的处理。
实操演示
常规使用
下面我们继续之前的例子,在雪球搜索框输入搜索内容后的页面开始:
testcase:设置测试用例,输入 alibaba 后,点选"阿里巴巴"
yaml 写法如下:
selectedList:遍历范围设定
接上一步点选"阿里巴巴"后到达如下界面:
我们先看demo配置文件中的原始写法,如下:selectedList:
- given: []
when: null
then: []
xpath: “//*[contains(name(), ‘Button’)]”
action: null
actions: []
times: 0 - given: []
when: null
then: []
xpath: “//*[contains(name(), ‘Text’) and @clickable=‘true’ and string-length(@text)<10]”
action: null
actions: []
times: 0 - given: []
when: null
then: []
xpath: “//[@clickable=‘true’]/[contains(name(), ‘Text’) and string-length(@text)<10]”
action: null
actions: []
times: 0 - given: []
when: null
then: []
xpath: “//*[contains(name(), ‘Image’) and @clickable=‘true’]”
action: null
actions: []
times: 0 - given: []
when: null
then: []
xpath: “//[@clickable=‘true’]/[contains(name(), ‘Image’)]”
action: null
actions: []
times: 0 - given: []
when: null
then: []
xpath: “//*[contains(name(), ‘Image’) and @name!=’’]”
action: null
actions: []
times: 0 - given: []
when: null
then: []
xpath: “//*[contains(name(), ‘Text’) and @name!=’’ and string-length(@label)<10]”
action: null
actions: []
times: 0
原始文件中将所有可点击的控件类型都包括了进去,再加上了部分 text 长度的限制 现在我们按照自己平常的简便写法重新编写,先设置所有 clickable 等于 true 的控件进行点击:
在 Android 中,一个控件如果绑定了用户响应行为的事件,那么 clickable 的属性值就是 true