IOS操作系统上执行monkey测试
2017-03-28 10:59 linkxu 阅读(2465) 评论(0) 收藏 举报IOS操作系统上执行monkey测试
IOS操作系统不像Android系统那么方便,各种限制也比较多,目前我的建议还是直接在模拟器上执行monkey测试。如果需要在真机上面执行,可以参考文档: http://testerhome.com/topics/2523
本文介绍怎么使用开源工具CrashMonkey进行IOS的monkey测试,步骤如下:
 一、安装测试环境
(1)MAC OS 
(2)XCode
(3)Ruby,至少1.8版本以上
Ruby的安装方法见:http://blog.csdn.net/li_huifeng/article/details/44456925,大致一下几 步:
1、安装RVM:
curl -L https://get.rvm.io | bash -s stable
2、载入RVM环境
source ~/.rvm/scripts/rvm
3、检查RVM安装是否成功
rvm -v
4、安装Ruby环境
rvm install 2.0.0
5、设置Ruby版本
rvm 2.0.0 --default
6、重新设置Ruby的默认源
gem source -r https://rubygems.org/
gem source -a https://ruby.taobao.org
7、验证是否重新设置成功
gem sources -l
二、安装CrashMonkey,参考链接:https://github.com/mokemokechicken/CrashMonkey
1、安装命令:gem install crash_monkey --no-ri --no-rdoc
三、使用CrashMonkey
1、使用命令:crash_monkey -a APP_NAME or APP_PATH -w DEVICE
四、直接使用instruments命令执行monkey:
instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -w EE564527-433A-42E3-92B8-F73A3EC0C8E7 /Users/xiehao/Temp/MYBPortal.app -e UIASCRIPT /Users/xiehao/program/CrashMonkey/bin/crash_monkey_result/UIAutoMonkey.js -e UIARESULTSPATH /Users/xiehao/program/CrashMonkey/bin/crash_monkey_result
 
 
 
iOS Monkey 测试方案
Step 1. brew install libimobiledevice
Step 2. brew install -HEAD ideviceinstaller
Step 3. brew install imagemagick
Step 4. gem install smart_monkey
上面这三部都执行成功就可以执行了,具体执行看说ReadMe https://github.com/vigossjjj/CrashMonkey4IOS 或者直接 smart_monkey -h 
CrashMonkey4IOS
iOS Monkey Test Tool.
简要说明:
- 支持真机测试、模拟器测试
- 支持收集系统日志(Systemlog)、崩溃日志(Crashlog)、instrument行为日志
- 支持测试报告截图,绘制行为轨迹
- 支持测试设备信息收集
- 使用最新版的UIAutoMonkey,加入UI Holes与Application Not Repsonding ("ANR")的处理,添加custom.js作为入口脚本.
- 加入tuneup依赖
- 修改UIAutoMonkey.js中截图策略,为每个Event Action进行截图
- 支持测试执行过程中App进入后台,自动恢复(测试不会block)
系统及环境要求:
- 安装Ruby运行环境,建议不要使用OS X自带版本,可自行使用RVM安装最新版的Ruby。建议使用淘宝镜像安装,速度比较快,$ sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' ~/.rvm/config/db
- 确保gem可用,也建议使用淘宝镜像 gem sources --remove https://rubygems.org/;gem sources -a http://ruby.taobao.org/;gem sources -l
- 安装Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 建议Xcode 6.x +
必要依赖安装:
- brew install -HEAD ideviceinstaller
- brew install libimobiledevice
- brew install imagemagick
使用说明:
安装Release版
gem install smart_monkey, 执行入口: 终端下直接使用smart_monkey 
安装开发版
直接clone本项目, 执行入口: /CrashMonkey4IOS/bin/smart_monkey 
执行命令
smart_monkey -a ${App_BunnelID} 
smart_monkey -a com.ajbapp.com id.... 
参数说明:
- -a: 指向被测程序的BundleID(不可缺省)。e.g.- -a com.mytest.app
- -w: 指向测试设备的UDID,可以通过- $instruments -s devices进行设备id的查看,若缺省则默认指向第一台设备(模拟器或真机)。e.g.- -w 26701a3a5bc17038ca0465186407b912375b35a7
- -n: monkey测试的执行次数,默认为1次。e.g.- -n 3
- -d: 测试报告地址,默认为当前目录下的smart_monkey_result文件夹下。e.g.- -d ~/my-monkey-test-result
- -t: 执行时间,单位为秒。e.g.- -t 60
- -s: 指向被测app的.dSYM文件,若出现crash,解析crash为明文。e.g.- -s testapp.dSYM
-  -c: 自定义的配置集路径,参数必须为目录,目录下必须包含custom.js,若使用handler,目录下需存在名为handler的文件夹,用于存放相关文件。e.g.-c /my/path/custom_cfg如果使用custom_cfg必须遵守如下目录结构: custom_cfg ├── custom.js └── handler ├── buttonHandler.js └── wbScrollViewButtonHandler.js
- 
--event-number: 定义Monkey测试的总事件数,默认为50。e.g.--event-number 100
- 
--compress-result: 对测试过程中截取的图片进行压缩,以节省空间开销。e.g.--compress-result 50%
- 
--detail-count: 定义报告详情中记录的事件总数,默认为50,即在报告当中展示最近的50次随机事件,且进行操作示意绘制。e.g.--detail-count 100
- 
--show-config: 打印当前的配置信息,即custom.js。e.g.--show-config
- 
--drop-useless-img: 删除除展示在报告当中的其余截图,以节省空间开销,如,一轮Monkey测试共产出截图100张,参数--detail-count设置为20,那么使用--drop-useless-img会删除其余80张截图。e.g.--drop-useless-img
- 
--list-app: 打印当前连接的真机及模拟器中所安装的app。e.g.--list-app
- 
--list-devices: 打印当前所有可用设备。e.g.--list-devices
- 
--reset-ios-sim: 重启模拟器。e.g.--reset-ios-sim
- 
--version: 打印smart_monkey的版本号。e.g.--version
⇒  CrashMonkey4IOS/bin/smart_monkey -h
Usage: smart_monkey [options]
    -a app_name                      Bundle ID of the desired target on device(Required)
    -w device                        Target Device UDID(Required)
    -n run_count                     How many times monkeys run(default: 1)
    -d result_dir                    Where to output result(default: ./smart_monkey_result)
    -t time_limit_sec                Time limit of running
    -s dsym_file                     Use .dSYM file to symbolicating crash logs
    -c custom_cfg_path               Indicate confige lib directory path, not a file path.
        --event-number event_number  The monkey event number(default: 50)
        --compress-result compress_rate
                                     compress the screenshot images to save disk space!(example: 50%)
        --detail-count detail_event_count
                                     How many events to show in detail result page(default 50)
        --show-config                Show Current Configuration custom.js
        --drop-useless-img           Delete the un-displayed images of detial page.
        --list-app                   Show List of Installed Apps in iPhone/iPhone Simulator
        --list-devices               Show List of Devices
        --reset-ios-sim              Reset iPhone Simulator
        --version                    print smart monkey version
 
 
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号