zoukankan      html  css  js  c++  java
  • monkey简单用法

      1. 连接模拟器设备

        adb connect 127.0.0.1:62001  第一个模拟器端口

        adb connect 127.0.0.1:62025  第二个模拟器端口

        adb connect 127.0.0.1:62025+1 即62026  第三个模拟器端口

        adb devices 可以查看连接了几个模拟器

      2. 获取apk的activity:aapt dump badging <apk路径,最好直接拖拽> |findstr launchable-activity

      3. 获取apk的package:aapt dump badging <apk路径,最好直接拖拽>

      4. adb shell monkey [options] <event-count>

    adb shell monkey 为固定语句,<event-count> 这里是指让monkey向系统发送多少次伪随机事件,重点和关键在[options]选项中,可以加不同的命令,如下

    1》.adb shell monkey 100    模拟器随意操作100次

    2》. adb shell monkey –v 100   模拟器随意操作100次,输出日志。日志一共有三个等级,0级,1级,2级,分别对应-v ,-v –v, -v –v –v, 级别越高日志越详细

    3》.adb shell monkey   提供帮助,可以查看monkey命令

    4》.adb shell monkey –s 1234 –v 100   -s<seed>伪随机数生成器的种子值,如果用相同的种子值再次运行monkey,将生成相同的事件序列。(该种子值对于Bug复现至关重要)注:如果不指定种子值,系统会随机生成一个种子值,在出现Bug时该种子值会和Bug信息一起被输出,这也是为了便于复现该Bug

    5》. adb shell monkey --throttle 300 -v 500   --throttle 300在事件之间插入特定的延时时间

    6 --pct-touch <percent>

    adb shell monkey --pct-touch 50 -v -v 500  指定touch(触摸)事件的百分比,touch事件是由一个DOWN和一个UP组成,按下并抬起即是一个touch事件。注:若不指定任何事件的百分比,系统将随机分配各种事件的百分比

    7》 --pct-motion <percent>

    adb shell monkey --pct-motion 100 -v -v 500   指定motion(手势)事件百分比,motion事件是由屏幕上某处一个down事件、一系列伪随机的移动事件和一个up事件组成。注:移动事件是直线移动

    8》 --pct-trackball <percent>

    adb shell monkey --pct-trackball 20 -v -v 500  指定trackball(轨迹球)事件的百分比,滚动球事件由一个或多个随机的移动事件组成,有时会伴随着点击事件。注:移动事件可以是曲线移动

    9》 下面几个事件与上面的类似,这里集中介绍

    --pct-nav <percent>

    指定基本的导航事件百分比。导航事件由方向输入设备的上下左右按键所触发的事件组成,即四个方向键

    --pct-majornav <percent>

    指定主导航事件百分比。这些导航事件通常会导致UI界面发生变化,如5-way键盘的中间键,返回按键、菜单按键

    --pct-syskeys <percent>

    指定系统事件百分比。这些按键通常由系统保留使用,如Home、Back、Start Call、End Call、音量调节

    --pct-appswitch <percent>

    指定Activity启动的百分比。在随机的时间间隔中,monkey执行startActivity()方法,最大程度地覆盖应用中全部的Activity

    --pct-anyevent <percent>

    指定其他事件的百分比。包含所有其他事件,如按键、其他在设备上不常用的按钮等

    --ignore-crashes

    adb shell monkey --ignore-crashes -v -v 500

    作用:忽略crashes,测试过程中发生crashes继续进行测试直到执行完指定的事件数,如果不忽略遇到crashesmonkey测试会停止

    --ignore-timeouts

    adb shell monkey --ignore-timeouts -v -v 500作用:忽略ANR,测试过程中发生ANR继续进行直到执行完指定的事件数,如果不忽略遇到ANR测试也会终止

        10adb shell monkey –p 软件包名 100

      5.    把文件电脑放入模拟器,adb push 本地路径 /sdcard/

        从模拟器下载到电脑,adb pull 远程路径 本地路径

      6. adb shell monkey –f </sdcard/文件名> -v 1  push 脚本到sd卡后,执行脚本,1 是随机事件执行个数

      7. 保存日志

    保存在PC中:
    adb shell monkey [option] <count> >d:monkey.txt

    保存在手机中:
    adb shell monkey [option] <count> > /mnt/sdcard/monkey.txt // 日志会保存在手机SD卡上的一个monkey.txt文件中

    标注流与错误留分开保存
    Monkey [option] <count> 1>/sdcard/monkey.txt 2>/sdcard/error.txt // Monkey 的运行日志和异常日志被开保存

      8. Monkey脚本API简介 

    LaunchActivity(pkg_name, cl_name):启动应用的Activity。参数:包名和启动的Activity。

    Tap(x, y, tapDuration): 模拟一次手指单击事件。参数:x,y为控件坐标,tapDuration为点击的持续时间,此参数可省略。

    DispatchPress(keyName): 按键。参数: keycode。 详细的Android Keycode列表: http://blog.csdn.net/feizhixuan46789/article/details/16801429

    RotateScreen(rotationDegree, persist): 旋转屏幕。 参数:rotationDegree为旋转角度, e.g. 1代表90度;persist表示旋转之后是否固定,0表示旋转后恢复,非0则表示固定不变。

    DispatchFlip(true/false): 打开或者关闭软键盘。

    LongPress(): 长按2秒。

    PressAndHold(x, y, pressDuration): 模拟长按事件。

    DispatchString(input): 输入字符串。

    Drag(xStart, yStart, xEnd, yEnd, stepCount): 用于模拟一个拖拽操作。

    PinchZoom(x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End, stepCount): 模拟缩放手势。

    UserWait(sleepTime): 休眠一段时间

    DeviceWakeUp(): 唤醒屏幕。

    PowerLog(power_log_type, test_case_status): 模拟电池电量信息。

    WriteLog(): 将电池信息写入sd卡。

    RunCmd(cmd): 运行shell命令。

    DispatchPointer(downtime,eventTime,action,x,yxpressure,size,metastate,xPrecision,yPrecision,device,edgeFlags): 向指定位置,发送单个手势。

    DispatchPointer(downtime,eventTime,action,x,yxpressure,size,metastate,xPrecision,yPrecision,device,edgeFilags): 发送按键消息。

    LaunchInstrumentation(test_name,runner_name): 运行一个instrumentation测试用例。

    DispatchTrackball: 模拟发送轨迹球事件。

    ProfileWait: 等待5秒。

    StartCaptureFramerate():  获取帧率。

    EndCaptureFramerate(input): 结束获取帧率。

  • 相关阅读:
    Codeforces Round #352 (Div. 1) B. Robin Hood 二分
    Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
    Codeforces Round #352 (Div. 2) B. Different is Good 水题
    Codeforces Round #352 (Div. 2) A. Summer Camp 水题
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题
    Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
    Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学
    Codeforces Beta Round #97 (Div. 1) B. Rectangle and Square 暴力
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/11045714.html
Copyright © 2011-2022 走看看