iOS穩定性測試工具CrashMonkey4IOS

摘要:輸入如下命令,運行iOSMonkey:smart_monkey-acom.taobao-w785d322900ff8d86a934e8febf21c65fa3d7ee6b-t3000-n3--compress-result20%--detail-count200-staobaoapp.dSYMsmart_monkey-acom.tao.ios-w785d322900ff8d86a934e8febf21c65fa3d7ee6b--compress-result20%--detaios


輸入如下命令,運行iOSMonkey:git

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
簡要說明:github

支持真機測試、模擬器測試ruby

支持收集系統日誌(Systemlog)、崩潰日誌(Crashlog)、instrument行爲日誌app

支持測試報告截圖,繪製行爲軌跡less

支持測試設備信息收集
使用最新版的UIAutoMonkey,加入UI Holes與Application Not Repsonding ("ANR")的處理,添加custom.js做爲入口腳本.curl

加入tuneup依賴ide

修改UIAutoMonkey.js中截圖策略,爲每一個Event Action進行截圖測試

支持測試執行過程當中App進入後臺,自動恢復(測試不會block)ui

系統及環境要求:

安裝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便可

相關文章
相關標籤/搜索