iOS稳定性测试工具CrashMonkey4IOS

输入以下命令,运行iOSMonkey:

smart_monkey -a com.taobao -w 785d322900ff8d86a934e8febf21c65fa3d7ee6b -t 3000 -n 3 --compress-result 20% --detail-count 200 -s taobaoapp.dSYM

smart_monkey -a com.tao.ios -w 785d322900ff8d86a934e8febf21c65fa3d7ee6b --compress-result 20% --detail-count 200 -n 3 -t 1000

简要说明:

支持真机测试、模拟器测试

支持收集系统日志(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

安装开发版

安装Ruby模块gem install erubis(如安装release版,此模块会自动配置加载。) 直接clone本项目, 执行入口:/CrashMonkey4IOS/bin/smart_monkey

执行命令

smart_monkey -a ${App_BundleID} -w ${iPhone_UDID}

参数说明:

-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

derekdeMac:CrashMonkey4IOS derek$ 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

-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

Troubleshooting:

安装和执行测试遇到的问题解决方案请参看:Troubleshooting.md

详见:https://github.com/vigossjjj/CrashMonkey4IOS

查看UDID:

instruments -s devices

脚本路径:

/Library/Ruby/Gems/2.0.0/gems/smart_monkey-0.5.0/lib/ui-auto-monkey

遇到问题一:

sudo gem install smart_monkey

ERROR:  Could not find a valid gem 'smart_monkey' (>= 0), here is why:

Unable to download data from https://rubygems.org/ - Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://rubygems.org/latest_specs.4.8.gz)

解决方法:更新一下ruby的源,过程如下:

$ gem sources -l (查看当前ruby的源)

$ gem sources --remove https://rubygems.org/

$ gem sources -a https://ruby.taobao.org/

$ gem sources -l

如果gem太老,可以尝试用如下命令升级gem

$ sudo gem update --system

升级成功后会提示: RubyGems system software updated

遇见问题二:

sudo brew install imagemagick

==> Installing dependencies for imagemagick: libpng, libtiff, freetype

==> Installing imagemagick dependency: libpng

==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.19.yosemite.bottle.tar.gz

######################################################################## 100.0%

curl: (35) Server aborted the SSL handshake

Error: Failed to download resource "libpng"

Download failed: https://homebrew.bintray.com/bottles/libpng-1.6.19.yosemite.bottle.tar.gz

Warning: Bottle installation failed: building from source.

==> Downloading ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.19.tar.xz

curl: (78) RETR response: 550

Trying a mirror...

==> Downloading https://dl.bintray.com/homebrew/mirror/libpng-1.6.19.tar.xz

curl: (35) Server aborted the SSL handshake

Error: Failed to download resource "libpng"

Download failed: https://dl.bintray.com/homebrew/mirror/libpng-1.6.19.tar.xz

解决方法:使用源码安装

curl -O ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

tar -zxf ImageMagick.tar.gz

cd ImageMagick-*/

./configure --prefix=/usr/local

make

sudo make install

遇到问题三:

跑真机报错误:Fail: An error occurred while trying to run the script.

在设置-开发者-打开UI AUTOMATION即可

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,425评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,058评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,186评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,848评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,249评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,554评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,830评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,536评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,239评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,505评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,004评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,346评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,999评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,060评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,821评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,574评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,480评论 2 267

推荐阅读更多精彩内容