Monkey
主要用于健壮性测试
adb shell monkey -p com.xueqiu.android --throttle 1000 --pct-touch 50 --pct-motion 50 -v 500
monkeyrunner
异常log
- /data/anr/traces.txt
- demo app https://github.com/cloudgrey-io/the-app/releases/download/v1.8.1/TheApp-v1.8.1.apk
gps未授权的情况下会崩溃
只展示ERROR级别的log
adb -s VED7N18403003958 logcat -s *:E
06-22 14:05:19.656 7145 7265 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
06-22 14:05:19.656 7145 7265 E AndroidRuntime: Process: io.cloudgrey.the_app, PID: 7145
06-22 14:05:19.656 7145 7265 E AndroidRuntime: java.lang.SecurityException: Looks like the app doesn't have the permission to access location.
06-22 14:05:19.656 7145 7265 E AndroidRuntime: Add the following line to your app's AndroidManifest.xml:
06-22 14:05:19.656 7145 7265 E AndroidRuntime: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.modules.location.LocationModule.throwLocationPermissionMissing(LocationModule.java:236)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.modules.location.LocationModule.startObserving(LocationModule.java:175)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat java.lang.reflect.Method.invoke(Native Method)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.os.Handler.handleCallback(Handler.java:891)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.os.Handler.dispatchMessage(Handler.java:102)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.os.Looper.loop(Looper.java:207)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat java.lang.Thread.run(Thread.java:784)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: Caused by: java.lang.SecurityException: "network" location provider requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.os.Parcel.createException(Parcel.java:1953)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.os.Parcel.readException(Parcel.java:1921)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.os.Parcel.readException(Parcel.java:1871)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:755)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.location.LocationManager.requestLocationUpdates(LocationManager.java:1155)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat android.location.LocationManager.requestLocationUpdates(LocationManager.java:709)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \tat com.facebook.react.modules.location.LocationModule.startObserving(LocationModule.java:167)
06-22 14:05:19.656 7145 7265 E AndroidRuntime: \t... 10 more
maxim
git clone https://github.com/zhangzhao4444/Maxim.git
cd Maxim
adb push framework.jar /sdcard
adb push monkey.jar /sdcard
adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.p.test.monkey.Monkey -p com.xueqiu.android --uiautomatormix --running-minutes 5 -v -v
appcrawler
localhost:appcrawler seveniruby$ java -jar appcrawler-2.4.0-jar-with-dependencies.jar
----------------
AppCrawler 2.4.0 [霍格沃兹测试学院特别纪念版]
Appium 1.8.1 Java8 tested
app爬虫, 用于自动遍历测试. 支持Android和iOS, 支持真机和模拟器
项目地址: https://github.com/seveniruby/AppCrawler
移动测试技术交流: https://testerhome.com
联络作者: seveniruby@testerhome.com (思寒)
致谢: 晓光 泉龙 杨榕 恒温 mikezhou yaming116 沐木
--------------------------------
Usage: appcrawler [options]
-a, --app <value> Android或者iOS的文件地址, 可以是网络地址, 赋值给appium的app选项
-e, --encoding <value> set encoding, such as UTF-8 GBK
-c, --conf <value> 配置文件地址
-p, --platform <value> 平台类型android或者ios, 默认会根据app后缀名自动判断
-t, --maxTime <value> 最大运行时间. 单位为秒. 超过此值会退出. 默认最长运行3个小时
-u, --appium <value> appium的url地址
-o, --output <value> 遍历结果的保存目录. 里面会存放遍历生成的截图, 思维导图和日志
--capability k1=v1,k2=v2...
appium capability选项, 这个参数会覆盖-c指定的配置模板参数, 用于在模板配置之上的参数微调
-r, --report <value> 输出html和xml报告
--template <value> 输出代码模板
--master <value> master的diff.yml文件地址
--candidate <value> candidate环境的diff.yml文件
--diff 执行diff对比
-vv, --verbose 是否展示更多debug信息
--demo 生成demo配置文件学习使用方法
--help
示例
appcrawler -a xueqiu.apk
appcrawler -a xueqiu.apk --capability noReset=true
appcrawler -c conf/xueqiu.json -p android -o result/
appcrawler -c xueqiu.json --capability udid=[你的udid] -a Snowball.app
appcrawler -c xueqiu.json -a Snowball.app -u 4730
appcrawler -c xueqiu.json -a Snowball.app -u http://127.0.0.1:4730/wd/hub
#生成demo例子
appcrawler --demo
#启动已经安装过的app
appcrawler --capability "appPackage=com.xueqiu.android,appActivity=.view.WelcomeActivityAlias"
#从已经结束的结果中重新生成报告
appcrawler --report result/
#新老版本对比
appcrawler --candidate result/ --master pre/ --report ./
java -jar appcrawler-2.4.0-jar-with-dependencies.jar --capability "appPackage=com.xueqiu.android,appActivity=.view.WelcomeActivityAlias"
java -jar appcrawler-2.4.0-jar-with-dependencies.jar --demo
#把生成的demo.yaml文件重命名demo_1.yaml
java -jar appcrawler-2.4.0-jar-with-dependencies.jar -c demo_1.yml
定位表达式
xpath
//*[@resource-id=‘xxxx’]
//*[contains(@text, ‘密码’)]
正则
^确定$
^.*输入密码
包含
密码
输入
请
action
“” 只是截图记录
back 后退
backApp 回退到当前的app 默认等价于back行为 可定制
monkey 随机事件
xxx() 执行代码
Thread.sleep(3000)
driver.swipe(0.9, 0.5, 0.1, 0.5)
click
longTap
非以上所有行为是输入 xx ddd
演示文件
localhost:0622_9 seveniruby$ cat demo.yml
---
pluginList: []
saveScreen: false
reportTitle: "霍格沃兹测试学院演练"
resultDir: ""
waitLoading: 1000
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 10
capability:
appPackage: com.xueqiu.android
appActivity: .view.WelcomeActivityAlias
noReset: "true"
fullReset: "false"
unicodeKeyboard: true
resetKeyboard: true
appium: "http://127.0.0.1:4723/wd/hub"
testcase:
name: "TesterHome AppCrawler"
steps:
- xpath: //*[@text='行情']/../android.widget.ImageView
- xpath: //*[contains(@resource-id, 'buttons_container')]//*[@text='私募']
- { xpath: 私募排行,action: back }
selectedList:
- xpath: //*[contains(@resource-id, 'buttons_container')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'ti_tab_indicator')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'll_stock_item_container')]//android.widget.TextView
firstList:
- xpath: 基金
lastList:
- xpath: 极速开户
backButton:
- xpath: 转到上一层级
triggerActions:
- xpath: //*[contains(@resource-id, 'home_search')]//*[contains(@resource-id, 'tv_search')]
times: 1
- xpath: //android.widget.EditText
action: alibaba
times: 1
xpathAttributes:
- "name"
- "label"
- "value"
- "resource-id"
- "content-desc"
#- "instance"
- "text"
sortByAttribute:
- "depth"
- "list"
- "selected"
findBy: "xpath"
defineUrl: []
baseUrl: []
appWhiteList: []
urlBlackList: []
urlWhiteList: []
blackList:
- given: []
when: null
then: []
xpath: ".*[0-9]{2}.*"
action: ""
actions: []
times: 0
beforeRestart: []
beforeElement:
- given: []
when: null
then: []
xpath: "/*"
action: "Thread.sleep(500)"
actions: []
times: 0
afterElement: []
afterPage: []
afterPageMax: 2
tagLimitMax: 5
tagLimit:
- xpath: //*[contains(@resource-id, 'ti_tab_indicator')]//android.widget.TextView
times: 10
assertGlobal: []
课间练习
遍历测试
把报告截图贴到回复里
2019-06-22 15:12:43
- indicator android.widget.HorizontalScrollView
- android.widget.LinearLayout indices quote_center_entrance_container quote_center_industry_chart_wrapper
- quote_center_industry_wrapper android.widget.LinearLayout[0]
- android.widget.ExpandableListView 3
2019-06-22 15:20:08
2019-06-22 15:32:37
cat demo_1.yml
---
pluginList: []
saveScreen: true
reportTitle: "霍格沃兹测试学院演练"
resultDir: ""
waitLoading: 500
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 1
capability:
appPackage: com.xueqiu.android
appActivity: .view.WelcomeActivityAlias
noReset: "true"
fullReset: "false"
unicodeKeyboard: true
resetKeyboard: true
appium: "http://127.0.0.1:4723/wd/hub"
testcase:
name: "TesterHome AppCrawler"
steps:
- xpath: //*[@text='行情']/../android.widget.ImageView
selectedList:
- xpath: //android.widget.ExpandableListView/android.widget.LinearLayout[1]//android.widget.TextView
- xpath: //android.widget.ExpandableListView/android.widget.LinearLayout[2]//android.widget.TextView
- xpath: //android.widget.HorizontalScrollView[contains(@resource-id, 'indicator')]//android.widget.TextView
firstList: []
lastList:
- xpath: //android.widget.HorizontalScrollView[contains(@resource-id, 'indicator')]//android.widget.TextView
backButton:
- xpath: 转到上一层级
triggerActions: []
xpathAttributes:
- "name"
- "label"
- "value"
- "resource-id"
- "content-desc"
- "index"
- "text"
sortByAttribute:
- "depth"
- "list"
- "selected"
findBy: "xpath"
defineUrl: []
baseUrl: []
appWhiteList: []
urlBlackList: []
urlWhiteList: []
blackList:
- given: []
when: null
then: []
xpath: ".*[0-9]{2}.*"
action: ""
actions: []
times: 0
beforeRestart: []
beforeElement:
- given: []
when: null
then: []
xpath: "/*"
action: "Thread.sleep(500)"
actions: []
times: 0
afterElement: []
afterPage: []
afterPageMax: 2
tagLimitMax: 5
tagLimit:
- xpath: //*[contains(@resource-id, 'ti_tab_indicator')]//android.widget.TextView
times: 10
assertGlobal: []
课后作业
- 遍历雪球的主界面,深度为2
- 注意先后顺序
- tagLimitMax与tagLimit 有的菜单有超过5个