Monkey测试
原生monkey
命令:
adb shell monkey -p com.pinsmedical.pinslife --throttle 100 -s 999 --pct-touch 50 --pct-motion 50 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes -v -v -v 100 0 > C:\ Users\ admin\ Desktop\ Monkey\ log\ 20230117 .log
adb shell settings put global policy_control immersive.full = * 关闭手机的状态栏
adb shell settings put global policy_control null 开启手机状态栏
monkey script
命令:
adb push C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ MonkeyScript\ j3.txt /data/local/tmp
adb shell monkey -f /data/local/tmp/j3.txt -v-v-v 3 > C:\ Users\ admin\ Desktop\ Monkey\ log\ monkeyscript_log.txt
monkey runner
命令:
monkeyrunner C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ Monkeyrunner\ monkeyrunner_test.py
monkeyrunner C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ Monkeyrunner\ monkeyrunner_test1.py
录制:
monkeyrunner C:\ Users\ admin\ Downloads\ android-sdk-windows\ platform-tools\ monkey_recorder.py
回放:
monkeyrunner C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ Monkeyrunner\ monkey_playback.py C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ Monkeyrunner\ playback
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.panda.test.monkey.Monkey -p com.pinsmedical.pinslife --uiautomatormix --running-minutes 1 --throttle 500 -v -v
adb shell CLASSPATH = /sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p com.pinsmedical.pinslife --uiautomatortroy --running-minutes 1 --throttle 500 -v -v
adb shell CLASSPATH = /sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.api.Dumptree
adb shell CLASSPATH = /sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.api.CurrentActivity
adb shell dumpsys window w | findstr \ / | findstr name =
白名单(awl.strings):
com.pinsmedical.pinslife.base.CommonFragmentActivity
com.pinsmedical.pinslife.component.home.MainActivity
com.pinsmedical.pinslife.component.inquiry.InquiryListActivity
com.pinsmedical.pinslife.component.inquiry.InquiryMainActivity
com.pinsmedical.pinslife.component.inquiry.InquiryResultActivity
com.pinsmedical.pinslife.component.inquiry.order.InquiryOrderDetailActivity
com.pinsmedical.pinslife.component.myDoctor.DoctorInfoNewActivity
固定操作(max.xpath.actions):
[
{
"prob" : 1 ,
"activity" : "com.pinsmedical.pinslife.component.home.MainActivity" ,
"actions" : [
{
"xpath" : "//*[@resource-id='com.pinsmedical.pinslife:id/tv_click3' and @text='续方购药']" ,
"action" : "CLICK" ,
"throttle" : 2000
}
]
} ,
{
"prob" : 1 ,
"activity" : "com.pinsmedical.pinslife.component.buymedicine.ui.BuyMedicineMainActivity" ,
"actions" : [
{
"xpath" : "//*[@resource-id ='com.pinsmedical.pinslife:id/nameTv' and @text='[dong22222gaigaigai]哒哒哒哒哒哒哒哒哒哒哒哒哒哒哒哒哒哒结束']" ,
"action" : "CLICK" ,
"throttle" : 2000
} ,
{
"xpath" : "//*[@class='android.widget.TextView' and @text='说明书']" ,
"action" : "CLICK" ,
"throttle" : 2000
}
]
}
]
[
{
"prob" : 1 ,
"activity" : "com.pinsmedical.pinslife.component.home.MainActivity" ,
"actions" : [
{
"xpath" : "//*[@resource-id='com.pinsmedical.pinslife:id/tv_click1' and @text='问医生']" ,
"action" : "CLICK" ,
"throttle" : 1000
}
]
} ,
{
"prob" : 1 ,
"activity" : "com.pinsmedical.pinslife.component.inquiry.InquiryMainActivity" ,
"actions" : [
{
"xpath" : "//*[@resource-id ='com.pinsmedical.pinslife:id/tv_name' and @text='伍医生']" ,
"action" : "CLICK" ,
"throttle" : 1000
}
]
} ,
{
"prob" : 1 ,
"activity" : "com.pinsmedical.pinslife.component.myDoctor.DoctorInfoNewActivity" ,
"actions" : [
{
"xpath" : "//*[@resource-id ='com.pinsmedical.pinslife:id/tv_inquiry_goods_name' and @text='图文问诊']" ,
"action" : "CLICK" ,
"throttle" : 1000
}
]
}
]
屏蔽区域(max.widget.strings):
[
{
"activity" : "com.pinsmedical.pinslife.base.CommonFragmentActivity" ,
"xpath" : "//*[@resource-id ='com.pinsmedical.pinslife:id/privacy' and @text='《隐私政策》']"
} ,
{
"activity" : "com.pinsmedical.pinslife.base.CommonFragmentActivity" ,
"xpath" : "//*[@resource-id ='com.pinsmedical.pinslife:id/protocol' and @text='《服务协议》']"
}
]
[
{
"activity" : "com.pinsmedical.pinslife.component.home.MainActivity" ,
"bounds" : "[0,1175][720,1263]"
}
]
控件优先级(max.xpath.selector):
[
{
"firstList" : [
{
"xpath" : "//*[contains(@text,'下一步')]"
}
] ,
"selectList" : [
{
"xpath" : "//*[@clickable='true']"
} ,
{
"xpath" : "//*[@clickable='true']//*[contains(name(),'Text')]"
} ,
{
"xpath" : "//*[@clickable='true']//*[contains(name(),'Button')]"
} ,
{
"xpath" : "//*[@clickable='true']//*[contains(name(),'Image')]"
}
] ,
"lastList" : [
{
"xpath" : "//*[../*[@selected='true']]"
} ,
{
"xpath" : "//*[../../*/*[@selected='true']]"
} ,
{
"xpath" : "//*[../../*/*[@selected='true'] and contains(@resource-id,'tab_')]"
}
]
}
]
自定义输入(max.strings)
伍
伍医生
wu
截图,启动配置(max.config):
max.takeScreenShot = true
--imagepolling
max.takeScreenShot = True 开启截图
max.flushImagesThreshold = 50 回溯区间大小xx张
崩溃截图的生效条件: throttle > 200 && max.takeScreenShot = true && --imagepolling
fastbot
前置条件:
adb push framework.jar fastbot-thirdpart.jar monkeyq.jar /sdcard
adb push libs/* /data/local/tmp/
命令:
adb shell CLASSPATH = /sdcard/monkeyq.jar:/sdcard/framework.jar:/sdcard/fastbot-thirdpart.jar exec app_process /system/bin com.android.commands.monkey.Monkey -p com.pinsmedical.pinslife --agent reuseq --running-minutes 30 --throttle 500 -v -v --output-directory /sdcard/monkeypng> C:\ Users\ admin\ Desktop\ Monkey\ log\ monkeylog.txt
--act-whitelist-file /sdcard/awl.strings
adb shell CLASSPATH = /sdcard/monkeyq.jar:/sdcard/framework.jar:/sdcard/fastbot-thirdpart.jar exec app_process /system/bin com.android.commands.monkey.Monkey -p com.pinsmedical.pinsdoctor --agent reuseq --running-minutes 30 --throttle 500 -v -v --output-directory /sdcard/monkeypng > C:\ Users\ admin\ Desktop\ Monkey\ log\ monkeylog.txt
adb logcat -c
adb logcat -b main > C:\ Users\ admin\ Desktop\ Monkey\ log\ logcat.txt
Jenkins集成
monkey_fastbot
call
cd C:\ Users\ admin\ Desktop\ Monkey
set a = "%device_name%-%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%-%time:~3,2%-%time:~6,2%"
md %a%
adb logcat -c
start "" cmd /c adb logcat ^> C:\ Users\ admin\ Desktop\ Monkey\ %a%\ logcat.txt
adb -s %device_name% shell settings put global policy_control immersive.full = *
adb -s %device_name% shell CLASSPATH = /sdcard/monkeyq.jar:/sdcard/framework.jar:/sdcard/fastbot-thirdpart.jar exec app_process /system/bin com.android.commands.monkey.Monkey -p %package% --running-minutes %duration% --throttle %throttle% %white_list% --agent reuseq -v -v -v -v -v --output-directory /sdcard/max-output
adb pull /sdcard/max-output $WORKSPACE
adb pull /sdcard/crash-dump.log $WORKSPACE
adb pull /sdcard/oom-traces.log $WORKSPACE
exit 0
monkey_maxim
call
cd C:\ Users\ admin\ Desktop\ Monkey
set a = "%device_name%-%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%-%time:~3,2%-%time:~6,2%"
md %a%
adb logcat -c
start "" cmd /c adb logcat ^> C:\ Users\ admin\ Desktop\ Monkey\ %a%\ logcat.txt
adb -s %device_name% shell settings put global policy_control immersive.full = *
adb -s %device_name% shell CLASSPATH = /sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p %package_name% --running-minutes %duration% --throttle %throttle% %white_list% --uiautomator%model% -v -v -v -v -v --output-directory /sdcard/max-output
adb pull /sdcard/max-output $WORKSPACE
adb pull /sdcard/crash-dump.log $WORKSPACE
adb pull /sdcard/oom-traces.log $WORKSPACE
exit 0
config
call
adb -s %device_name%
adb shell rm /sdcard/max.xpath.actions
adb shell rm /sdcard/max.xpath.selector
adb shell rm /sdcard/awl.strings
adb shell rm /sdcard/max.config
adb shell rm /sdcard/max.strings
adb shell rm /sdcard/max.widget.black
exit 0
call
adb -s %device_name%
adb push C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ config\ %action% /sdcard
adb push C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ config\ %awl% /sdcard
adb push C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ config\ %selector% /sdcard
adb push C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ config\ %widget% /sdcard
adb push C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ config\ %string% /sdcard
adb push C:\ Users\ admin\ Desktop\ work\ learn\ Monkey\ config\ %config% /sdcard
exit 0
Activity名称
嘉医有品
com.pinsmedical.pinslife.component.inquiry.InquiryMainActivity问医生
com.pinsmedical.pinslife.component.inquiry.InquiryListActivity问医生搜索
com.pinsmedical.pinslife.component.inquiry.InquiryResultActivity搜索结果页
com.pinsmedical.pinslife.component.myDoctor.DoctorInfoNewActivity医生详情页
com.pinsmedical.pinslife.base.CommonFragmentActivity问诊过程页
com.pinsmedical.pinslife.component.inquiry.order.InquiryOrderDetailActivity订单详情页
com.pinsmedical.pinslife.component.home.MainActivity主页
adb shell CLASSPATH = /sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p com.pinsmedical.pinslife --uiautomatorapi --running-minutes 10 -v -v -v -v
adb devices 查看连接设备
adb shell monkey -f /sdcard/wdj.txt -v 1 > /存放路径/wdjj.txt
第一步:adb shell
第二步:root@android:/
adb shell monkey -f /sdcard/wdj.txt -v 1 1 > /存放路径/right.txt 2 > /存放路径/error.txt
连接模拟器
adb connect 127.0 .0.1:62001
adb shell monkey 200 针对手机进行200次随机事件
adb shell monkey -p 包名 200 对某个包进行200次的事件操作
查看第三方包名
adb shell pm list packages -3 或 abd shell am monitor 或adb shell dumpsys
执行中发现了以下问题会结束APP。重新开始启动执行操作,继承次数。日志中记录
--ignore-crashes 崩溃
--ignore-timeouts ANR 超时
遇到了直接忽略,不报错不记录
--ignore-security-exceptions 安全证书
序列值,种子值 2 次monkey命令执行一样的seed值,那么操作流程(点击、滑屏)一致,但是操作对象不一定一致
-s SEED( 数字)
日志级别程度
-v -v -v
延迟时间(450ms)
--throttle MILLISEC
monkey测试结束
monkey finished
1 .crash崩溃 logcat日志
2 .anr无响应 abd shell /data/anr/traces.txt
3 异常中断
日志重定向
adb logcat > D:\ logcat\ logcat_2022-12-3.txt
记录特定的事件类型
adb logcat -b ( radio、main、event) > D:\ logcat\ logcat_2022-12-3.txt
日志组成:
1 时间戳 adb logcat -v time
2 优先级
V 开发调试用的
D 调试信息
I info 提示信息
W 警告
E 错误error
3 标签(tag) 开发过滤筛选用 例如:ActivityManager
4PID 进程ID
5 正文 主体内容
adb shell dumpsys window w | findstr \ / | findstr name =
adb shell dumpsys window | findstr mCurrentFocus
am force-stop com.pinsmedical.pinslife
日志分析:
/data/system/dropbox
adb -s emulator-5554 shell CLASSPATH = /sdcard/monkeyq.jar:/sdcard/framework.jar exec app_process /system/bin com.android.commands.monkey.Monkey -p com.pinsmedical.pinslife --agent robot --running-minutes 5 --throttle 800 -v -v
adb shell settings put global policy_control immersive.full = * 关闭手机的状态栏
adb shell settings put global policy_control null 开启手机状态栏
adb shell monkey -p com.pinsmedical.pinslife --throttle 300 -s 999 --pct-touch 50 --pct-motion 50 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 100 0 > C:\ Users\ admin\ Desktop\ Monkey\ log\ 20230117 .log
adb shell monkey -p com.pinsmedical.pinsdoctor --throttle 300 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 100 0 > C:\ Users\ admin\ Desktop\ Monkey\ log\ 2023011711111 .log
com.pinsmedical.pinsdoctor