AppCrawler得使用总结

背景

大家知道Monkey是Android平台上进行压力稳定性测试的工具,通过Monkey可以模拟用户触摸屏幕、滑动、按键等伪随机用户事件来对设备上的程序进行压力测试。而原生的Android Monkey存在一些缺陷:

事件太过于随机,测试有效性大打折扣
由于Monkey主要发送一些随机事件来进行测试,测试过程中的事件操作不受控制,大部分操作是无效的(比如点击的是空白区域、在不能滑动的页面进行滑动等等)。

对App页面内的控件覆盖率不佳
也是因为随机性这一特点,不能保证App页面的所有控件都能得到有效覆盖测试。

有概率跳出测试
点击到通知栏或者状态栏,就会跳转到其他的页面,从而中断当前App的测试。

工具Google App crawler

Google官方推出的App遍历工具,相比Monkey基于伪随机的事件,App Crawler是基于控件的遍历,可以更好的去遍历App的功能。

官方网址:

https://developer.android.google.cn/training/testing/crawler

目标受众

App Crawler 的目标用户是那些希望以最少配置确保应用基本功能的开发人员。除了纯黑盒测试之外,还可以配置爬虫程序来提供特定的输入,比如登录凭证或深度链接

使用

1.运行命令java -jar appcrawler-2.4.0-jar-with-dependencies.jar --demo,会在当前目录下生成一个demo.yml文件,这个文件就是我们进行定制化的配置文件模板:
2.打开配置文件demo.yaml如下

---
pluginList: []
saveScreen: true
reportTitle: ""
resultDir: "00000000"
waitLoading: 500
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 10
capability:
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"
testcase:
  name: "AppCrawler"
  steps:
  - given: []
    when: null
    then: []
    xpath: "/*"
    action: "Thread.sleep(5000)"
    actions: []
    times: 0
selectedList:
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
firstList: []
lastList:
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
backButton:
- given: []
  when: null
  then: []
  xpath: "xpath"
  action: null
  actions: []
  times: 0
triggerActions:
- given: []
  when: null
  then: []
  xpath: "btn"
  action: null
  actions: []
  times: 0
xpathAttributes:
- "name"
- "label"
- "value"
- "resource-id"
- "content-desc"
- "instance"
- "text"
sortByAttribute:
- "depth"
- "list"
- "selected"
findBy: "default"
defineUrl: []
baseUrl: []
appWhiteList: []
urlBlackList: []
urlWhiteList: []
blackList:
- given: []
  when: null
  then: []
  xpath: ".*[0-9]{2}.*"
  action: null
  actions: []
  times: 0
beforeRestart: []
beforeElement:
- given: []
  when: null
  then: []
  xpath: "/*"
  action: "Thread.sleep(500)"
  actions: []
  times: 0
afterElement: []
afterPage: []
afterPageMax: 2
tagLimitMax: 2
tagLimit:
- given: []
  when: null
  then: []
  xpath: "确定"
  action: null
  actions: []
  times: 1000
- given: []
  when: null
  then: []
  xpath: "取消"
  action: null
  actions: []
  times: 1000
- given: []
  when: null
  then: []
  xpath: "btn_name"
  action: null
  actions: []
  times: 1000
assertGlobal: []

执行参数

capability设置: 与appium完全一致,但要注意这里默认有noReset: "true"和appium: “http://127.0.0.1:4723/wd/hub” 属性

dontStopAppOnReset: true ;这个参数允许我们在某个页面继续执行遍历,比如我们希望App先进入到某个页面后再进行遍历,或者当一个session结束后继续下一个session的时候我们希望不要杀死App重新执行,而是继续上一次结束的页面开始执行
ignoreUnimportantViews: 这个参数设置为true的时候可以忽略不重要的view,加速pageSource的加载,加快测试速度
简写形态:
另外实际使用中我们会经常使用简写形态

直接使用xpath对应when里面的xpath
直接使用action对应when里面的action
具体写法如下:

  • xpath: 自选
    action: click
    then:
    • //*[contains(@text, ‘文本’)]
                           action的动作支持
"" :只是截图记录
back:后退
backApp:回退到当前的App,默认等价于back行为 可定制
monkey:随机事件
xxx()执行代码:
Thread.sleep(1000)
driver.swipe(0.9,0.8,0.9,0.5)
click:点击事件
longTap:长按

除以上所有行为外均视为输入行为
注:定位模式除了可以使用xpath之外还可以使用正则和包含关系,只不过经常使用的是xpath,也更为严谨;
包含:可以使用元素其中包含的内容进行定位;

testcase:
  name: "AppCrawler"
  steps:
  - { xpath: "//*[contains(@resource-id,'image')]", action: click }
  - xpath: home_search
    action: click
  - xpath: search_input_text
    action: 搜索文本

另外得:
也可以使用{}将需要执行的事件包裹起来,元素定位符和操作action时间用逗号隔开
{}内若使用xpath表达式的话需要加双引号
xpath中直接写id或text文本信息,就会默认使用包含去查找

selectedList: 遍历范围设定
这里如果想设置让其点击所有可点击的TextView和ImageView控件,修改完成如下:

selectedList:
- xpath: //android.widget.ImageView[@clickable='true']
- xpath: //*[@clickable='true' and contains(@class,"Text")]

firstList: 优先被点击

lastList:最后执行
设置其最后才执行"确定"按钮,修改完成如下:

lastList:
- { xpath: text_yes, action: click }

backButton: 当所有元素都被点击后默认后退控件定位

blackList:黑名单

triggerAction: 特定条件出发执行动作的设置;设置遇到重置密码输入框时输入123456abc两次,修改完成如下:

triggerActions:
- { xpath: android.widget.EditText, action: 123456abc, times: 2 }

tagLimitMax: 全局设置,同类型的最多点击的次数;这里设置为2次

tagLimitMax: 2

tagLimit: 自定义控件类型的点击次数,这里设置对于ListView类型的只点击一次;
修改完成如下

- { xpath: "//*[contains(@class, 'List')]//*", times: 1 }

maxDepth: 遍历的最大深度

assertGlobal:设置一个全局断言,例如可设置断言在当前App,如果包名不符合,就可能发生了崩溃,便会报错

注:执行参数比配置文件优先级高

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值