移动性能测试 CrashMonkey4iOS 试用过程总结

陈恒捷 · 2015年06月07日 · 最后由 陈恒捷 回复于 2019年12月26日 · 6498 次阅读
本帖已被设为精华帖!

CrashMonkey4iOS 已经出来一段时间了,最近有位同样做移动测试的朋友在尝试使用它的过程中遇到了些问题,过来问我,因此我也顺便把这个工具试用了一下。

安装过程:

1、把代码库 clone 下来:

git clone https://github.com/vigossjjj/CrashMonkey4IOS.git

2、执行里面的 reset.sh 文件进行环境配置:

chmod +x reset.sh && ./reset.sh

gem already installed ruby library erubis.
install depends libimobiledevice...
==> Installing dependencies for libimobiledevice: libtasn1, libxml2, libplist, libusb, usbmuxd, op
==> Installing libimobiledevice dependency: libtasn1
==> Downloading https://homebrew.bintray.com/bottles/libtasn1-4.5.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtasn1-4.5.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/libtasn1/4.5: 56 files, 572K
==> Installing libimobiledevice dependency: libxml2
==> Downloading https://homebrew.bintray.com/bottles/libxml2-2.9.2.yosemite.bottle.tar.gz ######################################################################## 100.0%
==> Pouring libxml2-2.9.2.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/libxml2/lib
    CPPFLAGS: -I/usr/local/opt/libxml2/include

==> Summary
🍺  /usr/local/Cellar/libxml2/2.9.2: 275 files, 11M
==> Installing libimobiledevice dependency: libplist
==> Downloading https://homebrew.bintray.com/bottles/libplist-1.12.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libplist-1.12.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/libplist/1.12: 26 files, 412K
==> Installing libimobiledevice dependency: libusb
==> Downloading https://homebrew.bintray.com/bottles/libusb-1.0.19.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring libusb-1.0.19.yosemite.bottle.1.tar.gz
🍺  /usr/local/Cellar/libusb/1.0.19: 11 files, 368K
==> Installing libimobiledevice dependency: usbmuxd
==> Downloading https://homebrew.bintray.com/bottles/usbmuxd-1.0.10.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring usbmuxd-1.0.10.yosemite.bottle.1.tar.gz
🍺  /usr/local/Cellar/usbmuxd/1.0.10: 11 files, 156K
==> Installing libimobiledevice dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2a-1.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2a-1.yosemite.bottle.1.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2a-1: 463 files, 18M
==> Installing libimobiledevice
==> Downloading https://homebrew.bintray.com/bottles/libimobiledevice-1.2.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libimobiledevice-1.2.0.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/libimobiledevice/1.2.0: 64 files, 1.2M
install depends libimobiledevice done.
imagemagick already install.
upgrade imagemagick...
upgrade imagemagick done.

(实际上就是安装三个依赖库:ruby 的 erubis,还有 libimobiledeviceimagemagick,至于为何没有它文档上介绍的 ideviceinstaller 原因不是很清楚)

使用方法

查看帮助:

$ 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_path                   Configuration custom.js Path
    -e extend_javascript_path        Extend Uiautomation Javascript for such Login scripts
        --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-iPhone-Simulator     Reset iPhone Simulator
        --version                    print smart monkey version

内容有点多,但对于启动 monkey 测试最关键是两个参数:-a app_name-w device

-a appname:app 的 bundle id,可在 app 源码的项目信息中看到(Bundle Identifier)。由于是直接通过 bundle id 来启动 app ,因此前置条件是 app 已经安装在被测设备上(包括模拟器)

-w device:被测设备的 UDID 。 CrashMonkey4iOS 支持 Simulator 和 真实设备 。需要使用模拟器时使用的 UDID 可以通过 bin/smart_monkey --list-devices 获取(严格来说不能算 UDID ,只能叫模拟器的 identifier,但为了保持统一后文还是称为 UDID)。例如我的输出为:

$ bin/smart_monkey --list-devices
...
iPhone 5s (7.1 Simulator) [A5D60D43-E673-4DB6-ADD6-1EB59ABDD97D]
iPhone 5s (8.1 Simulator) [DC34010F-69D8-4A29-B771-A90F15D71A58]
iPhone 5s (8.3 Simulator) [78E825CE-261A-4A86-8A8B-7466EDD0F564]
iPhone 6 (8.1 Simulator) [30874B86-ACA0-4B79-AA04-171FE8C6BB84]
iPhone 6 (8.3 Simulator) [E23DE92A-B6B1-4AEF-9632-4DA8DD7CE630]
iPhone 6 Plus (8.1 Simulator) [0FD26636-D91F-47C5-8649-1D4E8F3AB8ED]
iPhone 6 Plus (8.3 Simulator) [D8426A6C-82F0-4245-A003-8E63057EEBED]

此时 模拟器后面的一长串数字 + 字母 就是模拟器的 UDID ,例如 "iPhone 6 (8.3 Simulator)" 的 UDID 为 E23DE92A-B6B1-4AEF-9632-4DA8DD7CE630中间的破折号不能省略

此外,由于 CrashMonkey 没有集成自动启动模拟器的功能,因此使用的前置条件是 被测设备(包括模拟器)已经启动完毕并停留在桌面,如处在锁屏界面请先解锁

使用示例

我自己有一个应用 bundle id 为 chj.ToDoList,我想在 iPhone 6 (8.3 Simulator) 上运行这个应用,下面是完整的执行过程。

  • 前置条件

1、通过 bin/smart_monkey --list-app 能看到 ToDoList 这个应用:

$ bin/smart_monkey --list-app
============For iPhone Simulator:
AwesomeProject.app
HCCB_app.app
HCCB_score.app
PhonegapDemo.app
ToDoList.app
chjReactNativeProject.app
chjapp.app
ruby-china-for-ios.app
webViewDemo.app
============For iPhone Device:
...

此处可以看到有 ToDoList.app。这个 app 文件在所有模拟器中通用,不需要再考虑它是在具体哪个模拟器上。
若没有出现,则想办法让这个应用在模拟器上跑一次。

2、通过 bin/smart_monkey --list-devices 看到的设备列表中有你想使用的设备,如果是模拟器则该模拟器必须处在打开状态(已经能看到模拟器里的桌面)

  • 运行过程

执行命令 bin/smart_monkey -a chj.ToDoList -w E23DE92A-B6B1-4AEF-9632-4DA8DD7CE630

$ bin/smart_monkey -a chj.ToDoList -w E23DE92A-B6B1-4AEF-9632-4DA8DD7CE630

INSTRUMENTS_TRACE_PATH : /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/*.trace
RESULT_BASE_PATH : /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result
{:app_path=>"chj.ToDoList", :device=>"E23DE92A-B6B1-4AEF-9632-4DA8DD7CE630", :run_count=>1, :time_limit_sec=>nil, :detail_event_count=>50}
=================================== Start Test (1/1) =======================================
2015-06-07 22:59:14.442 instruments[7163:208626] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Attempting iOS Simulator system log capture via tail system.log.
BundleID was found: chj.ToDoList
Run: ["instruments", "-w", "E23DE92A-B6B1-4AEF-9632-4DA8DD7CE630", "-t", "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate", "chj.ToDoList", "-e", "UIASCRIPT", "/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225913/custom.js", "-e", "UIARESULTSPATH", "/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225913"]
2015-06-07 22:59:16.176 instruments[7177:208756] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-07 14:59:24 +0000 Default: {"width":375,"height":667}
2015-06-07 14:59:24 +0000 Debug: target.tapWithOptions({x:"243.7460767105222", y:"184.1347451447509"}, {touchCount:"1", tapCount:"1", duration:"0"})
2015-06-07 14:59:24 +0000 Debug: target.captureRectOnScreenWithName("{origin:{x:0.00,y:0.00}, size:{height:667.00,width:375.00}}", UIScreen, "monkey-2015-06-07T14-59-24-203Z")
2015-06-07 14:59:24 +0000 Screenshot captured.
2015-06-07 14:59:24 +0000 Debug: target.tapWithOptions({x:"68.52816045284271", y:"506.7851242637262"}, {touchCount:"1", tapCount:"1", duration:"0"})
2015-06-07 14:59:24 +0000 Debug: target.captureRectOnScreenWithName("{origin:{x:0.00,y:0.00}, size:{height:667.00,width:375.00}}", UIScreen, "monkey-2015-06-07T14-59-24-447Z")
2015-06-07 14:59:24 +0000 Screenshot captured.
...
2015-06-07 14:59:42 +0000 Debug: MonkeyTest::ButtonHandler(CloseX,3,true,): 0
2015-06-07 14:59:42 +0000 Debug: MonkeyTest::ButtonHandler(确定,3,false,): 0
2015-06-07 14:59:42 +0000 Debug: MonkeyTest finish.
Instruments Trace Complete (Duration : 26.255495s; Output : /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/instrumentscli0.trace)
Stop iOS system log capture.
2015-06-07 22:59:50.578 instruments[7194:209328] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-07 22:59:54.966 instruments[7212:209396] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-07 22:59:55.800 instruments[7216:209428] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-07 22:59:56.653 instruments[7221:209477] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-07 22:59:57.468 instruments[7225:209502] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Monkey Test Report:/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225913/index.html
EXIT 0

此时会看到被测应用在模拟器上被启动,然后被随机事件操作,最后自动退出。

  • 运行结果

测试报告默认放在 bin/smart_monkey_result中,具体位置在测试命令最后输出的信息中可以找到,例如上面的例子中测试报告位置为: Monkey Test Report:/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225913/index.html

测试报告本身非常清晰,有足够的 log(system log,instruments log,如果 crash 还有 crash log)以及操作步骤截图。其中截图还包含了操作指示,例如:

发现的问题及解决方案

以下问题均已在 github 上建立 issue。也希望有发现存在其他问题的同学遵照原作者的指示统一在 github 上报 issue 。

1、由于 reset.sh 没有安装 ideviceinstaller ,而使用 bin/smart_monkey --list-app 时查看真机上的应用列表需要调用这个依赖项,所以会出现如下错误:

============For iPhone Device:
/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/lib/smart_monkey/monkey_runner.rb:175:in ``': No such file or directory - ideviceinstaller (Errno::ENOENT)
    from /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/lib/smart_monkey/monkey_runner.rb:175:in `list_app'
    from /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/lib/smart_monkey/monkey_runner.rb:24:in `run'
    from ./smart_monkey:49:in `<main>'

解决方法:手动运行 brew install ideviceinstaller 来安装这个依赖项
现在已经换成更友好的错误提示,会直接提示安装 ideviceinstaller 。

2、这个严格来说其实是 bug 。通过命令行信息我们可以看出实际上执行的是一条 instrument 命令,通过 google 得知 instrument 命令的 -w 参数支持使用类似 -w "iPhone 6 (8.3 Simulator)" 的方式来选择设备,但在 smart_monkey 中使用这种写法会出现如下错误:

=================================== Start Test (1/1) =======================================
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `"instruments" -s devices | grep iPhone 6 (8.3 Simulator)'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `idevicecrashreport -u iPhone 6 (8.3 Simulator) -e -k /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225716/crash_1'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `"instruments" -s devices | grep iPhone 6 (8.3 Simulator)'
Attempting iOS device system log capture via deviceconsole.
BundleID was found: chj.ToDoList
Run: ["instruments", "-w", "iPhone 6 (8.3 Simulator)", "-t", "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate", "chj.ToDoList", "-e", "UIASCRIPT", "/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225716/custom.js", "-e", "UIARESULTSPATH", "/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225716"]
Stop iOS system log capture.
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `"instruments" -s devices | grep iPhone 6 (8.3 Simulator)'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `idevicecrashreport -u iPhone 6 (8.3 Simulator) -e -k /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225716/crash_1'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `"instruments" -s devices | grep iPhone 6 (8.3 Simulator)'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `ideviceinfo -u iPhone 6 (8.3 Simulator) -k ProductType'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `"instruments" -s devices | grep iPhone 6 (8.3 Simulator)'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `ideviceinfo -u iPhone 6 (8.3 Simulator) -k ProductVersion'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `"instruments" -s devices | grep iPhone 6 (8.3 Simulator)'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `ideviceinfo -u iPhone 6 (8.3 Simulator) -k DeviceName'
Monkey Test Report:/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607225716/index.html
EXIT 1

由于没有被引号包围以表示这是字符串, iPhone 6 (8.3 Simulator) 被 shell 识别为错误语法,因此出现了不少错误。

解决方法:不要使用模拟器名称,使用 UDID 。 已 fix

3、使用模拟器运行过程中出现了一次锁屏操作,结果 CrashMonkey 无法自行解锁:

2015-06-07 15:01:47 +0000 Debug: target.flickFromTo({x:"55.99269334925339", y:"628.6212073885836"}, {x:"284.4106543343514", y:"408.6799378818832"})
2015-06-07 15:01:47 +0000 Debug: target.captureRectOnScreenWithName("{origin:{x:0.00,y:0.00}, size:{height:667.00,width:375.00}}", UIScreen, "monkey-2015-06-07T15-01-47-423Z")
2015-06-07 15:01:47 +0000 Screenshot captured.
2015-06-07 15:01:47 +0000 Debug: target.lockForDuration("0.3549308124929667")
2015-06-07 15:01:49 +0000 Debug: target.systemApp().mainWindow().scrollViews().firstWithPredicate("ANY elements.name == 'SlideToUnlock' OR ANY elements.name == 'SlideToSetup' OR ANY elements.name == 'Passcode field'").dragInsideWithOptions({endOffset:{x:0.90,y:0.90}}, duration:"0.5", startOffset:{x:0.20,y:0.90}}})
2015-06-07 15:01:52 +0000 Debug: Unlock failed. Retrying up to 2 more time(s).
2015-06-07 15:01:52 +0000 Debug: target.systemApp().mainWindow().scrollViews().firstWithPredicate("ANY elements.name == 'SlideToUnlock' OR ANY elements.name == 'SlideToSetup' OR ANY elements.name == 'Passcode field'").dragInsideWithOptions({endOffset:{x:0.90,y:0.90}}, duration:"0.5", startOffset:{x:0.20,y:0.90}}})
2015-06-07 15:01:53 +0000 Debug: Unlock failed. Retrying up to 1 more time(s).
2015-06-07 15:01:53 +0000 Debug: target.systemApp().mainWindow().scrollViews().firstWithPredicate("ANY elements.name == 'SlideToUnlock' OR ANY elements.name == 'SlideToSetup' OR ANY elements.name == 'Passcode field'").dragInsideWithOptions({endOffset:{x:0.90,y:0.90}}, duration:"0.5", startOffset:{x:0.20,y:0.90}}})
2015-06-07 15:01:55 +0000 Debug: target.captureRectOnScreenWithName("{origin:{x:0.00,y:0.00}, size:{height:667.00,width:375.00}}", UIScreen, "monkey-2015-06-07T15-01-55-572Z")
2015-06-07 15:01:55 +0000 Screenshot captured.
2015-06-07 15:01:55 +0000 Warning: Target app go to outside, trigger re-launch action.

然后程序就会一直停留在此处,而模拟器也不会再有任何反应。

解决方法:人工滑动屏幕解锁,然后 CrashMonkey 会自动继续执行下去。 修改 lib/ui-auto-monkey/custom.js:

monkey.config.eventWeights = {
            tap: 100,
            drag: 10,
            flick: 10,
            orientation: 1,
            lock: 1,
            pinchClose: 1,
            pinchOpen: 1,
            shake: 1
        };

lock: 1, 改成 lock: 0,

4、真机上务必开启 Enable UI Automation(在 Settings->Developer 里面),否则真机上运行时应用会闪退。

这个其实不算坑,是使用不当,而且官方 TroubleShooting 有提到,所以没有报 issue。而且出错后把测试报告的 sys log 看完就知道是啥问题了。

解决方法: 在真机上开启 Enable UI Automation。

5、真机上运行会出现如下错误:

INSTRUMENTS_TRACE_PATH : /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/*.trace
RESULT_BASE_PATH : /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result
{:app_path=>"chj.ToDoList", :device=>"2143b478b4141119f7ae286abdb693ebefd01ea5", :run_count=>1, :time_limit_sec=>nil, :detail_event_count=>50}
=================================== Start Test (1/1) =======================================
2015-06-07 23:59:36.852 instruments[7896:266326] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Attempting iOS device system log capture via deviceconsole.
BundleID was found: chj.ToDoList
Run: ["instruments", "-w", "2143b478b4141119f7ae286abdb693ebefd01ea5", "-t", "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate", "chj.ToDoList", "-e", "UIASCRIPT", "/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607235935/custom.js", "-e", "UIARESULTSPATH", "/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607235935"]
2015-06-07 23:59:42.646 instruments[7908:266524] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-07 15:59:50 +0000 Default: {"width":1024.0000335703464,"height":768.0000447604625}
...
2015-06-07 15:59:52 +0000 Debug: target.tapWithOptions({x:"332.7966623166576", y:"-42.84549929387867"}, {touchCount:"1", tapCount:"1", duration:"0"})
2015-06-07 15:59:52 +0000 Debug: tap point is not within the bounds of the screen
2015-06-07 15:59:52 +0000 Debug: MonkeyTest finish.
2015-06-07 15:59:52 +0000 Error: Script threw an uncaught JavaScript error: tap point is not within the bounds of the screen on line 145 of UIAutoMonkey.js
2015-06-07 15:59:53 +0000 Stopped: Script was stopped by the user
2015-06-07 23:59:53.194 instruments[7908:266624] Attempting to set event horizon when core is not engaged, request ignored
Instruments Trace Complete (Duration : 10.302137s; Output : /Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/instrumentscli0.trace)
Stop iOS system log capture.
2015-06-07 23:59:57.887 instruments[7918:266679] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-08 00:00:05.761 instruments[7937:267018] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2015-06-08 00:00:07.390 instruments[7947:267059] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Monkey Test Report:/Users/hengjiechen/Develop/iOS/research/CrashMonkey4IOS/bin/smart_monkey_result/report_20150607235935/index.html
EXIT 0

我的真机是 iPad mini2 + iOS 8.2 (买不起 iPhone 。。。),目前只能估计是 CrashMonkey4iOS 对 iPad 的支持还不是太好。

解决方法:暂时无解。

总结

虽然存在一些问题,但这是目前能找到的最好的 Monkey 测试完整解决方案,它让 发现问题和解决问题的效率同时得到了提高。

感谢 @vigossjjj 为我们带来这么好的工具。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 127 条回复 时间 点赞

#10 楼 @xxfcxx gem 默认源貌似需要 ***,你可以换用淘宝源。具体怎么换可以找百度。

#20 楼 @chentest 自备 *** 工具

韦林 回复

你好,环境配置好后,运行不起来,错误日志如下,是什么原因?
kascenddeMacBook-Pro-4:bin kascend$ smart_monkey -a com.baidu.Tieba.TBClient -w 3c4d7ad606b3500e37c8069eae80bb39e3f680c2
INSTRUMENTS_TRACE_PATH : /Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/.trace
RESULT_BASE_PATH : /Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/smart_monkey_result
{:app_path=>"com.baidu.Tieba.TBClient", :device=>"3c4d7ad606b3500e37c8069eae80bb39e3f680c2", :run_count=>1, :time_limit_sec=>nil, :detail_event_count=>50}
=================================== Start Test (1/1) =======================================
Attempting iOS device system log capture via deviceconsole.
BundleID was found: com.baidu.Tieba.TBClient
Run: ["instruments", "-w", "3c4d7ad606b3500e37c8069eae80bb39e3f680c2", "-t", "", "com.baidu.Tieba.TBClient", "-e", "UIASCRIPT", "/Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/smart_monkey_result/report_20191224132756/custom.js", "-e", "UIARESULTSPATH", "/Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/smart_monkey_result/report_20191224132756"]
2019-12-24 13:29:21.131 instruments[4946:493541] *
* -[__NSCFConstantString stringByAppendingPathExtension:]: cannot append extension 'tracetemplate' to path ''
Instruments Usage Error: The specified template '' does not exist.
instruments, version 9.4.1 (64086)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]
Stop iOS system log capture.

梦梦GO 回复

你好,环境配置好后,运行不起来,错误日志如下,是什么原因?
kascenddeMacBook-Pro-4:bin kascend$ smart_monkey -a com.baidu.Tieba.TBClient -w 3c4d7ad606b3500e37c8069eae80bb39e3f680c2
INSTRUMENTS_TRACE_PATH : /Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/.trace
RESULT_BASE_PATH : /Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/smart_monkey_result
{:app_path=>"com.baidu.Tieba.TBClient", :device=>"3c4d7ad606b3500e37c8069eae80bb39e3f680c2", :run_count=>1, :time_limit_sec=>nil, :detail_event_count=>50}
=================================== Start Test (1/1) =======================================
Attempting iOS device system log capture via deviceconsole.
BundleID was found: com.baidu.Tieba.TBClient
Run: ["instruments", "-w", "3c4d7ad606b3500e37c8069eae80bb39e3f680c2", "-t", "", "com.baidu.Tieba.TBClient", "-e", "UIASCRIPT", "/Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/smart_monkey_result/report_20191224132756/custom.js", "-e", "UIARESULTSPATH", "/Users/kascend/Documents/work/tools/CrashMonkey4IOS-master/bin/smart_monkey_result/report_20191224132756"]
2019-12-24 13:29:21.131 instruments[4946:493541] ** -[__NSCFConstantString stringByAppendingPathExtension:]: cannot append extension 'tracetemplate' to path ''
Instruments Usage Error: The specified template '' does not exist.
instruments, version 9.4.1 (64086)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]]
Stop iOS system log capture.

hz 回复

额,这个是 15 年的工具了,底层使用的 UIAutomation 在 xcode 9 左右就已经被去掉了,用不了也不奇怪。不确定现在最新版是否有适配新的 XCUITest 。

建议寻找更新一点的 iOS monkey 工具?

#3 楼 @chenhengjie123 我跟他们之前 QQ 沟通了!后面会搞定的吧!

我这边的情况就是经常越界,经常性收集到别的应用的 crash_log ,custom.js 配置之后貌似没多大变化

#2 楼 @testly 赶紧报 issue 啊,有能力直接 pull request 吧。

@chenhengjie123 非常感谢这样的问题汇总~!这些问题后边会一一修复@testly
问题 1:在"reset.sh",这个脚本中没有安装 ideviceinstaller 的步骤,后续会加上,之前疏忽了,后续计划通过 gem 安装实现一键配置。
问题 2:对于-w 参数来说在使用类似iPhone 6 (8.3 Simulator)这样的设备描述没有做支持及友好的错误信息,后续会改进。
问题 3:对于模拟器锁屏后 instuments 自动解锁失败的问题,我这边也遇到过但真机是没有问题的,应该是 apple 自己的问题,后续会再调研看是否有可惜 workaround。
问题 4:之前没有做 ipad 的测试,我怀疑是 app 在 ipad 上运行横屏时,x/y 坐标算法没有 cover 住导致的,后续我会对 iPad 做支持

#5 楼 @vigossjjj Good!
如果需要帮忙随时找我哈,虽然 ruby 方面语法不是很熟,但简单的 fix bug 应该还是 ok 的。

@chenhengjie123 @testly 问题 1、2 已经提交了,你们可以试试,
https://github.com/vigossjjj/CrashMonkey4IOS/issues/5
https://github.com/vigossjjj/CrashMonkey4IOS/issues/6

后边 2 个问题,后续抽空搞定

#8 楼 @vigossjjj
两个问题都试过了,确实已经 fix 了。
:plus1:

在执行 执行里面的 reset.sh 文件进行环境配置:的时候报错
Installing ri documentation for erubis-2.7.0
WARNING: Unable to pull data from 'https://rubygems.org/:' Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://rubygems.org/quick/Marshal.4.8/erubis-2.7.0.gemspec.rz)

https://rubygems.org/quick/Marshal.4.8/erubis-2.7.0.gemspec.rz 这个 link 在浏览器里也打不开

@chenhengjie123 你好,我是已经加了淘宝源,gem sources -a http://ruby.taobao.org/, 之后出了这个错误的。。

#12 楼 @xxfcxx 你检查一下你的网络? https://rubygems.org/quick/Marshal.4.8/erubis-2.7.0.gemspec.rz 这个链接我可以下下来的。

解决方法:人工滑动屏幕解锁,然后 CrashMonkey 会自动继续执行下去。 锁屏之后只有这个解决方案么。。。。好像不能设置模拟器永不锁

我在 文件 mechanic.js 中 去掉了 lock: function(duration) { target.lockForDuration(duration); }, 这行,而且 在 'delay,cmd,orientation,location,shake,pinchScreen,drag,lock,backgroundApp,volume'.split(',').forEach 这行删除了 lock, 可还是能执行到锁屏。。。

#15 楼 @xxfcxx 其实解决方案除了手动解锁之外还有别的办法,改 custom.js:

monkey.config.eventWeights = {
            tap: 100,
            drag: 10,
            flick: 10,
            orientation: 1,
            lock: 1,
            pinchClose: 1,
            pinchOpen: 1,
            shake: 1
        };

lock: 1, 改成 lock: 0,
刚刚试过跑 3 次 monkey ,不会再出现锁屏了。

我之前试用了下 发现在引导页会经常过不去 联系对引导页做个特殊处理

#14 楼 @xxfcxx 我也遇到了 : 在执行 执行里面的 reset.sh 文件进行环境配置:的时候报错
Installing ri documentation for erubis-2.7.0
WARNING: Unable to pull data from 'https://rubygems.org/:' Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://rubygems.org/quick/Marshal.4.8/erubis-2.7.0.gemspec.rz)

https://rubygems.org/quick/Marshal.4.8/erubis-2.7.0.gemspec.rz 这个 link 在浏览器里也打不开,请问你是怎么解决的呢?

clone 的代码库位置在/Users/chenlengyao/下面
你好,我在执行 chmod +x reset.sh && ./reset.sh
后面出现这样的错误
chmod: Unable to change file mode on reset.sh: Operation not permitted
权限问题,请问要如何解决,

#22 楼 @lengyao88 你当前使用的用户是 chenlengyao 吗?
如果不是,切换到这个用户,或者 clone 到你当前用户的 home 目录。

@chenhengjie123 如果遇到第三方,比如 QQ 登录,会打开一个网页的,弹出这样的,monkey 的脚本就会无法执行报错了。

WARN:no response in log,trigger re-launch action

@chenhengjie123
点的别的产品的时候,在别的产品界面弹出给这个产品是否好评,monkey 脚本是在执行,但是不会跑到要被测试的应用去。

#27 楼 @lengyao88 额,我只是试用,这些具体问题你可以找一下 @vigossjjj 或者直接上去 github 报 issue 。
这个 CrashMonkey 和 android 的 Monkey 还是有点区别的,一旦被测 app 不是在 running 状态它就控制不了了。
另外,现在可以通过 gem install smart_monkey 安装 Release 版本的 CrashMonkey4IOS 了,不需要像我正文那样子用 reset.sh 。

PS:麻烦添加一下头像,谢谢。

@vigossjjj 我用 Mac 盒子 + iPod(真机)试跑出现一个权限的问题:

2015-07-09 18:03:24.294 instruments[50836:422152] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Instruments Trace Error : Target failed to run: Permission to debug com.jinfuzi.gunxueqiu was denied. The app must be signed with a development identity (e.g. iOS Developer).
Stop iOS system log capture.

请问除了 github 和本贴提到的注意点外,还需要做其他的配置不?? 谢谢

#29 楼 @pajack UIAutomation 自身的限制,必须使用 development 证书签名的应用才能做测试。

需要你的.mobileprovision 和.p12 重签名才可以调 Instrument

@chenhengjie123 @a00ium 谢谢回复, 我对 UIAutomation 还不了解。 我再试试~~

#32 楼 改了签名重新打包,可以跑起来了。 很强大,感谢分享~

请教一个问题,我前两天用这个 monkey 测试是好用的,但今天跑另一个应用的时候发现,monkey 刚启动执行一下就退出了(exist 0),但是手机上还有点击动作在执行,result_000 下也没有任何截图信息,知道这是什么原因吗

跑一次就退出了,在哪里修改次数。可以多运行几次吗?

#35 楼 @joker 请看:

$ 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_path                   Configuration custom.js Path
    -e extend_javascript_path        Extend Uiautomation Javascript for such Login scripts
        --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-iPhone-Simulator     Reset iPhone Simulator
        --version                    print smart monkey version

留意 -n run_count 参数

#34 楼 @happy_sola 那些 log 也没有报错信息?例如 uiautomation log 和 iOS log 。

测试 bundle exec rake markdown_body:refresh 后回帖是否正确。

之前代码有bug。产生的代码块,没有 code tag

#39 楼 @kkself 选项确定没选错?
要 build 的 target 的 build setting -> Code Signing 应该是这样的:

The app must be signed with a development identity (e.g. iOS Developer).
我的测试包是企业证书打的测试包 为什么还包这个错误啊

#40 楼 @chenhengjie123 设备也必须加入到开发者设备列表中是么?

#41 楼 @kkself 必须的啊,否则装不上的。

为什么的报告里看不到截图呢。

#43 楼 @wangcityboy 你用啥参数启动的?

#44 楼 @chenhengjie123 smart_monkey -a com.yueapp.sns -w a5ba1247eb17079858e6bd1cc8ae78360b06cf0b -n 3 -t 500
我是用这个参数启动

那这个很奇怪。帮你找下原作者 @vigossjjj

@chenhengjie123

我在使用命令的时候真机没问题,但是使用模拟器报错如下:
$ smart_monkey -a com.lala.lala2 -w 7BFEF07D-36EE-4C3E-9A52-67020F100291(ps:UDID 用了各种写法都不行)

{:app_path=>"com.lala.la2", :device=>"7BFEF07D-36EE-4C3E-9A52-67020F100291", :run_count=>1, :time_limit_sec=>nil, :detail_event_count=>50}
=================================== Start Test (1/1) =======================================
sh: -c: line 0: syntax error near unexpected token ('
sh: -c: line 0:
idevicecrashreport -u 7BFEF07D-36EE-4C3E-9A52-67020F100291 (Simulator) -e -k ~/smart_monkey_result/report_20160412173136/crash_1'
Attempting iOS device system log capture via deviceconsole.
Stop iOS system log capture.
Invalid device, Please given a vaild device!

#47 楼 @sucheng 看起来是 crashMonkey4iOS 的问题。你到 github 上提个 Issue 给作者?

#48 楼 @chenhengjie123 恩恩,已经提了

#47 楼 @sucheng 嗨喽,你这个问题现在有解决吗,我现在运行也是这样的问题,没办法往下走了,我用的是 9.3 系统,OS X EI Capitan 系统,xcode7.3 版本。

麻烦帮忙看下,我是小白用户,安装环境后包真机,模拟器都出现问题,模拟器就提示无效设备,真机就提示无效 APP,这是怎么回事

#51 楼 @hexueqin 第一个截图你检查下 app 绝对路径如何

第二个不知道为啥你的 udid 里面会带有括号。正常应该不会带有括号的。

感觉新版本不是很稳定,偶尔出现提示 WARN: no response in log, trigger re-launch action.

@chenhengjie123 @vigossjjj 请问这个工具支持 IOS9.2.1 以上的系统版本吗,我这边使用真机 iPhone5S-IOS8.3 的版本可以正常使用,但是使用 iPhone6 和 iPhone6S 都是 IOS9.2.1 版本却跑不起来,报错信息是 “File size mismatch.Skipping...”

#54 楼 @miserable 给详细一点的信息?例如更完整的 Log 什么的?

#55 楼 @chenhengjie123 smart_monkey 版本是 0.5.0,求教

跑了 1 小时,logout 了,login 要输入用户名密码,请问这个脚本怎么写呢?@chenhengjie123
-e extend_javascript_path

使用模拟器一直提示 Invalid device, Please given a vaild device! 求教

#59 楼 @pacerron 这个脚本就是一个 UIAutomation 的脚本。具体写法建议你直接在 github 上咨询作者,我也没写过。。。

#60 楼 @fengfeng 麻烦给出完整的出错信息,而不仅仅是一句错误提示。


运行 smart_monkey --list-app 报这个错,该如何解决 啊?

#47 楼 @sucheng 请问问题解决了么,我也遇到同样的问题

问题已经解决,是因为没有在设备上连接真机导致的,这个可以在程序中加一个判断,没有真机时候是什么情况

#65 楼 @finallyopen123 能说详细点么?

已经是 development 证书的应用,真机 5S 跑的时候还是提示 instruments[11159:1975393] WebKit Threading Violation - initial use of WebKit from a secondary thread.

切到外面的 app 后有时候切不回来而停止运行
log 如下:
Warning: Target app go to outside, trigger re-launch action.
Fail: The target application appears to have died
Attempting to change event horizon while disengage
Stop iOS system log capture.

初步定为是线程问题,但是目前没有很好的解决方案。楼主有解决方案吗?辛苦看看。
目前感觉不少朋友受这个问题困扰。

@chenhengjie123 有没有遇到这样的问题?有没有解决方案啊?求指导

#71 楼 @junewang1990 我用得不多,但我之前用得时候没遇到过。

你在它的 github 上问下它的作者?

#72 楼 @chenhengjie123 恩,我和作者联系了一下,作者最近没空解决这个。
我刚定位问题了,是在最近的版本,在 relaunch_app 中,加入了 is_simulator 的判断,这个也是通过 ‘instruments -s devices’ 进行判断的。和 Instruments 的命令行起冲突了。

如果把这个操作提前的话,这个问题就能解决了。

#68 楼 @junewang1990 先确定下,你的 app 确实没有挂?再者,没看出这里和线程有什么关系。印象中 CrashMonkey4iOS 是通过 idevicedebug 命令唤醒 app 的,虽然是通过另外的线程启动,但应该和 app 切不回来关系不大。

#70 楼 @chenhengjie123 我确定没有挂。
我的操作是这样的,为了验证是否能从返回,我手动压后台。会出现切到目标 APP,然后停止运行的情况。
如果我把对应的那段代码,即 app_hang_monitor_thread 注释掉。然后手动压后台,然后在 terminal 输入 idevicedebug 命令,可以调回。(实验过多次也能调回)

你那里能正常运行?正常调回?

假如在跑 monkey 的过程中,crash 了,monkey 还会继续跑吗? 是不是扑捉到 crash 而已,不会真正的 crash。

#75 楼 @moxiaozhou crash 了 monkey 就不会继续跑了。因为底层用的是 UIAutomation ,只要被测应用的进程不在前台运行,就无法执行 monkey 。crashMonkey4iOS 也带有 crash 后自动重新启动应用重跑 monkey 的机制。

#74 楼 @junewang1990 不客气,感谢你才对,解决了一个问题~

#77 楼 @qyqzhlw 报啥错?

想问下,最高支持的 ios 系统版本和 xcode 版本是多少,用到 xcode7.3.1 ios 9.3 是跑不起来

#78 楼 @chenhengjie123 真机和虚拟机 都跑步起来

#79 楼 @qyqzhlw 你这个是啥 device ?看起来不像是设备 udid 。

#82 楼 @qyqzhlw 那不清楚了,我已经有一段时间没用 CrashMonkey4iOS 了,你上 github 报个 issue ?

#84 楼 @chenhengjie123 那你现在公司 ios 还有做 monkey 测试吗 用的是什么? 有更好的工具推荐吗

#85 楼 @qyqzhlw 目前所在的公司没有,上一家有,当时用的直接就是 UIAutomation 。

@chenhengjie123 crash 之后,并没有重新启动应用,而是测试结束,生成测试报告了。不知道 crash 之后,需要重新启动的话,还需要设置哪里?

#86 楼 @chenhengjie123 好吧,我先去 github 上报个 issue 吧

#87 楼 @moxiaozhou 你可以看下这个参数:

-n run_count                     How many times monkeys run(default: 1)

这样无论 monkey 是由于 crash 退出还是别的原因,都可以重复执行直到达到你指定的次数。

想问下,我运行 monkey 后生成的日志文件 console.txt。 里面没有任何的内容。是什么问题呢?


导致 system log 无法打开
知道是什么原因导致的吗?
@chenhengjie123

  1. 你试下安装 ideviceinstaller 后用 idevicesyslog 看能否捕获到你的系统日志?
  2. 我不大记得这个日志是有 crash 才存还是一直都存了,你先确认下?

#91 楼 @chenhengjie123
已近是安装过 ideviceinstaller,还是没有日志。这个日志时一直都有保存的,不是只有 crash 才保存。
我试着重新安装配置,貌似有些是直接跳过的。

#91 楼 @chenhengjie123 我想问下,跑这个手机是否要越狱

#93 楼 @qyqzhlw 不用。但要打开开发者模式,打开 UIAutomation 开关。

#51 楼 @hexueqin 你好,请问你这个问题解决了么??

#95 楼 @chenhengjie123 手机扫描不出来,提示这个
用 list-devices 能扫描出设备

模拟器如何安装包呢?

#97 楼 @dengwei729 你确定要模拟器安装包?能装在真机上的包模拟器一定跑不动的哦

#98 楼 @chenhengjie123 是想着自动化把 monkey 跑起来,你们 monkey 流程是啥? 模拟器支持多开么?

#99 楼 @dengwei729 我们是接真实机器跑的 monkey ,模拟器跑的结果不可靠,像内存泄漏太严重导致被系统 kill 掉这种模拟器就搞不出来。

@chenhengjie123 请问一下这个错误是因为什么?怎么改才是正确的?求回复!!!
我用的是 iOS10.0,xcode7.3.1
=================================== Start Test (1/1) =======================================
2016-11-01 10:32:13.548 instruments[26160:738984] WebKit Threading Violation - initial use of WebKit from a secondary thread.
ERROR: Could not connect to lockdownd, error code -19
2016-11-01 10:32:18.551 instruments[26188:739158] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Attempting iOS device system log capture via deviceconsole.

#101 楼 @anthonio 原因应该是调用一些 libmobiledevice 的命令的时候出问题。

不过这个 monkey 应该不支持 iOS 10 吧,底层是基于 UIAutomation 的,iOS 10 已经不能用 UIAutomation 了。

#100 楼 @chenhengjie123 为了使用 UIAutomation 专门下载的 Xcode 7.3,然后使用 Automation 运行 UIAutoMonkey.js 脚本,在 iOS10 上是可以跑起来的,但是因为 UIAutoMonkey 功能不太全,还是需要使用 smartmonkey,但是报了这个错!!!泣血求答案啊!!!

#103 楼 @anthonio 这个报错是 libmobiledevice 的命令报出来的。你重装 libmobiledevice 试试?

论坛里之前有个关于 Xcode 8 和 iOS 10 的问题集中贴,印象中里面有提到这个问题,你可以去搜索看看。


小白一个,instruments 的参数 template 为空,不知道咋整 求指点~~谢谢啊

有时间研究一下

#43 楼 @wangcityboy 最近使用也遇到了相同的问题,解决方法是 bootstrap.min.css,jquery.min.js,下载这两个文件到 result 文件夹下就可以打开了

#109 楼 @yefnegjun 这个是执行随机事件的,有可能是你界面跳转的按钮范围比较少所以随机点击的时候按到的概率比较低。

如果是为了尽可能遍历多的界面,你可以在论坛搜索下 appcrawler 这个遍历工具,可能更满足你的需要。

@ankhkid 你好 我跟你的问题一样 请问你解决了吗

@chenhengjie123 楼主你好,请问一下我想进行多个界面的测试怎么做呢?我运行起来只是在一个界面上面进行测试

@chenhengjie123 您好还想再请教个问题。CrashMonkey4IOS 这个工具只能运行本地有工程的 app 吗?如果没有工程代码,只有开发提供的测试安装包 ipa 文件和 BundleID 如何能跑起来呢。我现在运行起来不启动真机上的 app

yefengjundeMacBook-Pro:~ yefengjun$ smart_monkey -a com.JDVideo -w 65aa3a56dcd0fcb6b8e4b3dc769bba4baf991562
INSTRUMENTS_TRACE_PATH : /Users/yefengjun/*.trace
RESULT_BASE_PATH : /Users/yefengjun/smart_monkey_result
{:app_path=>"com.JDVideo", :device=>"65aa3a56dcd0fcb6b8e4b3dc769bba4baf991562", :run_count=>1, :time_limit_sec=>nil, :detail_event_count=>50}
2016-12-19 13:44:32.164 instruments[6392:422777] WebKit Threading Violation - initial use of WebKit from a secondary thread.
=================================== Start Test (1/1) =======================================
2016-12-19 13:44:33.174 instruments[6404:422865] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2016-12-19 13:44:34.350 instruments[6412:422912] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2016-12-19 13:44:35.380 instruments[6418:422973] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2016-12-19 13:45:15.398 instruments[6442:425184] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2016-12-19 13:45:16.486 instruments[6448:425266] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Attempting iOS device system log capture via deviceconsole.
2016-12-19 13:45:17.621 instruments[6455:425338] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2016-12-19 13:45:18.665 instruments[6464:425518] WebKit Threading Violation - initial use of WebKit from a secondary thread.
BundleID was found: com.JDVideo
Run: ["instruments", "-w", "65aa3a56dcd0fcb6b8e4b3dc769bba4baf991562", "-t", "/Applications/Xcode7.3.1.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate", "com.JDVideo", "-e", "UIASCRIPT", "/Users/yefengjun/smart_monkey_result/report_20161219134431/custom.js", "-e", "UIARESULTSPATH", "/Users/yefengjun/smart_monkey_result/report_20161219134431"]
2016-12-19 13:45:24.727 instruments[6472:425685] WebKit Threading Violation - initial use of WebKit from a secondary thread.
Stop iOS system log capture.
2016-12-19 13:45:29.455 instruments[6486:425903] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2016-12-19 13:45:30.383 instruments[6492:426019] WebKit Threading Violation - initial use of WebKit from a secondary thread.
2016-12-19 13:45:31.429 instruments[6498:426060] WebKit Threading Violation - initial use of WebKit from a secondary thread.


我用 instruments -s devices 命令可以看到我连接的真机,测试包装在真机上用 smart_monkey --list-app 命令并不显示我这个 app。
还请麻烦帮忙看一下吧..谢谢!

#112 楼 @chenhengjie123 感谢!现在感觉问题就是出在手机没装签名的问题了。但是开发说已经把测试机的 uuid 加到概要文件中了,不需要再在描述文件那里信任添加签名证书,直接就能运行。所以现在卡在签名证书了.....

#111 楼 @yefnegjun 使用条件和其它用 UIAutomation 运行的条件基本一致,要求 ipa 包必须是开发者调试证书签名。

你和开发确认下测试包用的是什么证书签名的吧。

#113 楼 @yefnegjun 建议你了解下 iOS 开发证书(iOS Developer)和 iOS 发布证书(iOS Distribution)的区别,开发应该也了解这个的。

instruments 对 app 签名有限制不是指必须加 udid(不加 udid 你的应用会闪退或者装不上),而是对打包时使用的签名证书有限制。 iOS distribution 证书签名是不行的。

#113 楼 @yefnegjun 给你一个看安装包签名信息的方法:

  1. 如果是 ipa 文件,先解压,然后找到 Payload/xx.app 文件(夹)。其中 xx 对应替换回你的应用名称,不过正常这个 Payload 文件夹里面只会有一个 .app 的文件(夹)
  2. 执行命令 codesign -dvvvv path/to/xx.app,就可以看到签名信息。

例如:

$ codesign -dvvvv temp/Payload/ToDoList.app
Executable=/Users/hengjiechen/Develop/iOS/develop/IOSTutorial/ToDoList/temp/Payload/ToDoList.app/ToDoList
Identifier=chj.ToDoList
Format=app bundle with Mach-O universal (armv7 arm64)
CodeDirectory v=20200 size=1176 flags=0x0(none) hashes=50+5 location=embedded
OSPlatform=37
OSSDKVersion=590080
OSVersionMin=458752
Hash type=sha1 size=20
CandidateCDHash sha1=8534c429ec4269909c65778970316e7e9d610e51
Hash choices=sha1
Page size=4096
CDHash=8534c429ec4269909c65778970316e7e9d610e51
Signature size=4350
Authority=iPhone Developer: Wei Feng Hou (RGR96FVT75)
Authority=Apple Worldwide Developer Relations Certification Authority
Authority=Apple Root CA
Signed Time=11 Dec 2015, 12:26:52 AM
Info.plist entries=31
TeamIdentifier=VN295HN9LJ
Sealed Resources version=2 rules=12 files=61
Internal requirements count=1 size=172

Authority=iPhone Developer: Wei Feng Hou (RGR96FVT75) 这里就说明了签名的证书是 iPhone Developer ,即开发证书(也可以叫调试证书,目前没有官方中文译名)

#114 楼 @chenhengjie123 哎,不好意思。刚开始测 ios 没多久 问题有点小白还请见谅....但是我现在不知道怎么添加开发证书。我装好测试包后去描述文件中没有看到要让我信任的证书..

#116 楼 @chenhengjie123 好的我先看一下。谢谢了!

Could not connect to lockdownd, error code -21,请问,运行 monkey 的时候,报这个错是什么意思?

#118 楼 @rolex_sky001 重装 ideviceinstaller 试试?

#94 楼 @dongcl,之前尝试修改源码也没有用,就换了种方式,自己创建了相同的目录路径就好了

楼主,再确认下,smartmonkey 是不是只能在 7.3.1 版本及以下的 xcode 才能跑?

陈恒捷 回复

xcode 8 以后还有什么工具能做 iOS Monkey 的测试么?

@chenhengjie123为什么我在真机上面的开发者,打开了 enable UI automation 运行 monkey 还是会闪退呢,求解,卡在这里进行不下去了;亲;呜呜呜呜

june 回复

你好,你的话这个问题解决了么?“WARN: no response in log, trigger re-launch action.”

你好,我设置运行 5000 次,但是在结果中显示只跑了 50 多秒,正常情况肯定不可能这样的
smart_monkey -a com.eufylife.dev -w ${udid} —event-number ${COUNT} —compress-result 50% --drop-useless-img

这是为什么呢 ‘

18楼 已删除
127楼 已删除

#56 楼 @miserable 这个我也不清楚。。。你还是直接找作者吧。

小施 回复

目前是的。7.3.1 以后的 xcode 没有了 UIAutomation 。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册