smart_monkey 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -11
- data/VERSION +1 -1
- data/bin/smart_monkey +11 -4
- data/lib/smart_monkey/command_helper.rb +16 -16
- data/lib/smart_monkey/monkey_runner.rb +44 -13
- data/lib/ui-auto-monkey/custom.js +3 -37
- metadata +1 -3
- data/lib/ui-auto-monkey/handler/buttonHandler.js +0 -111
- data/lib/ui-auto-monkey/handler/wbScrollViewButtonHandler.js +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 847d8e2008d02e4d0dea00c85c4bf3c7bb106792
|
4
|
+
data.tar.gz: 4646d1a3da95b94cc90ae2601f9706a93ed83732
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bda662b08477fee72e67f081d16404a01651e02424e6b99931ba3f41172bb8d2e5210b79955f654a40569fb60eb274a419939795841a0d21ff05224f4c7c97e
|
7
|
+
data.tar.gz: 241f3eeec81ba69252e271b0e8e79d1e842239b61ad21ef78767b9e0e64f98eb3e73326c3eaadd125a60901632953d5fe7d0849723646c097a3853ae752ad9c7
|
data/README.md
CHANGED
@@ -17,35 +17,66 @@ iOS Monkey Test Tool.
|
|
17
17
|
[tp]:https://github.com/vigossjjj/CrashMonkey4IOS/tree/master/lib/ui-auto-monkey/tuneup
|
18
18
|
[troubleshooting]:https://github.com/vigossjjj/CrashMonkey4IOS/tree/master/Troubleshooting.md
|
19
19
|
|
20
|
-
|
21
|
-
###### 系统要求
|
20
|
+
###系统及环境要求:
|
22
21
|
1. 安装Ruby运行环境,建议不要使用OS X自带版本,可自行使用RVM安装最新版的Ruby。建议使用淘宝镜像安装,速度比较快,`$ sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' ~/.rvm/config/db`
|
23
22
|
2. 确保gem可用,也建议使用淘宝镜像 `gem sources --remove https://rubygems.org/;gem sources -a http://ruby.taobao.org/;gem sources -l`
|
24
23
|
3. 安装**Homebrew** `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
|
25
24
|
4. 建议Xcode 6.x +
|
26
25
|
|
27
|
-
|
26
|
+
###必要依赖安装:
|
28
27
|
1. `brew install -HEAD ideviceinstaller`
|
29
28
|
2. `brew install libimobiledevice`
|
30
29
|
3. `brew install imagemagick`
|
31
|
-
4. `gem install smart_monkey`
|
32
30
|
|
33
31
|
###使用说明:
|
34
|
-
|
35
|
-
|
32
|
+
###### 安装Release版
|
33
|
+
`gem install smart_monkey`, 执行入口: 终端下直接使用`smart_monkey`
|
34
|
+
###### 安装开发版
|
35
|
+
直接clone本项目, 执行入口: `/CrashMonkey4IOS/bin/smart_monkey`
|
36
|
+
|
37
|
+
###### 执行命令
|
38
|
+
`smart_monkey -a ${App_BunnelID} -w ${iPhone_UDID}`
|
36
39
|
|
37
40
|
###参数说明:
|
41
|
+
|
42
|
+
* **`-a`**: 指向被测程序的**BundleID**(不可缺省)。e.g.`-a com.mytest.app`
|
43
|
+
* **`-w`**: 指向测试设备的**UDID**,可以通过`$instruments -s devices`进行设备id的查看,若缺省则默认指向第一台设备(模拟器或真机)。e.g.`-w 26701a3a5bc17038ca0465186407b912375b35a7`
|
44
|
+
* **`-n`**: monkey测试的执行次数,默认为1次。e.g.`-n 3`
|
45
|
+
* **`-d`**: 测试报告地址,默认为当前目录下的**smart_monkey_result**文件夹下。e.g.`-d ~/my-monkey-test-result`
|
46
|
+
* **`-t`**: 执行时间,单位为秒。e.g.`-t 60`
|
47
|
+
* **`-s`**: 指向被测app的**.dSYM**文件,若出现crash,解析crash为明文。e.g.`-s testapp.dSYM`
|
48
|
+
* **`-c`**: 自定义的配置集路径,**参数必须为目录**,目录下必须包含`custom.js`,若使用handler,目录下需存在名为**handler**的文件夹,用于存放相关文件。e.g.`-c /my/path/custom_cfg`
|
49
|
+
|
50
|
+
**如果使用custom_cfg必须遵守如下目录结构**:
|
51
|
+
|
52
|
+
```
|
53
|
+
custom_cfg
|
54
|
+
├── custom.js
|
55
|
+
└── handler
|
56
|
+
├── buttonHandler.js
|
57
|
+
└── wbScrollViewButtonHandler.js
|
58
|
+
```
|
59
|
+
* **`--event-number`**: 定义Monkey测试的总事件数,默认为50。e.g.`--event-number 100`
|
60
|
+
* **`--compress-result`**: 对测试过程中截取的图片进行压缩,以节省空间开销。e.g.`--compress-result 50%`
|
61
|
+
* **`--detail-count`**: 定义报告详情中记录的事件总数,默认为50,即在报告当中展示最近的50次随机事件,且进行操作示意绘制。e.g.`--detail-count 100`
|
62
|
+
* **`--show-config`**: 打印当前的配置信息,即**custom.js**。e.g.`--show-config`
|
63
|
+
* **`--drop-useless-img`**: 删除除展示在报告当中的其余截图,以节省空间开销,如,一轮Monkey测试共产出截图100张,参数`--detail-count`设置为20,那么使用`--drop-useless-img`会删除其余80张截图。e.g.`--drop-useless-img`
|
64
|
+
* **`--list-app`**: 打印当前连接的真机及模拟器中所安装的app。e.g.`--list-app`
|
65
|
+
* **`--list-devices`**: 打印当前所有可用设备。e.g.`--list-devices`
|
66
|
+
* **`--reset-ios-sim`**: 重启模拟器。e.g.`--reset-ios-sim`
|
67
|
+
* **`--version`**: 打印smart_monkey的版本号。e.g.`--version`
|
68
|
+
|
38
69
|
```
|
39
|
-
|
70
|
+
⇒ CrashMonkey4IOS/bin/smart_monkey -h
|
40
71
|
Usage: smart_monkey [options]
|
41
72
|
-a app_name Bundle ID of the desired target on device(Required)
|
42
|
-
-w device Target
|
73
|
+
-w device Target Device UDID(Required)
|
43
74
|
-n run_count How many times monkeys run(default: 1)
|
44
75
|
-d result_dir Where to output result(default: ./smart_monkey_result)
|
45
76
|
-t time_limit_sec Time limit of running
|
46
77
|
-s dsym_file Use .dSYM file to symbolicating crash logs
|
47
|
-
-c
|
48
|
-
|
78
|
+
-c custom_cfg_path Indicate confige lib directory path, not a file path.
|
79
|
+
--event-number event_number The monkey event number(default: 50)
|
49
80
|
--compress-result compress_rate
|
50
81
|
compress the screenshot images to save disk space!(example: 50%)
|
51
82
|
--detail-count detail_event_count
|
@@ -54,7 +85,7 @@ Usage: smart_monkey [options]
|
|
54
85
|
--drop-useless-img Delete the un-displayed images of detial page.
|
55
86
|
--list-app Show List of Installed Apps in iPhone/iPhone Simulator
|
56
87
|
--list-devices Show List of Devices
|
57
|
-
--reset-
|
88
|
+
--reset-ios-sim Reset iPhone Simulator
|
58
89
|
--version print smart monkey version
|
59
90
|
```
|
60
91
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/bin/smart_monkey
CHANGED
@@ -12,20 +12,20 @@ require 'smart_monkey'
|
|
12
12
|
opts = {}
|
13
13
|
ARGV.options do |o|
|
14
14
|
o.on('-a app_name', 'Bundle ID of the desired target on device(Required)') {|b| opts[:app_path] = b}
|
15
|
-
o.on('-w device', 'Target Device UDID
|
15
|
+
o.on('-w device', 'Target Device UDID') {|b| opts[:device] = b}
|
16
16
|
o.on('-n run_count', 'How many times monkeys run(default: 1)') {|b| opts[:run_count] = b.to_i}
|
17
17
|
o.on('-d result_dir', 'Where to output result(default: ./smart_monkey_result)') {|b| opts[:result_base_dir] = File.expand_path(b)}
|
18
18
|
o.on('-t time_limit_sec', 'Time limit of running') {|b| opts[:time_limit_sec] = b.to_i}
|
19
19
|
o.on('-s dsym_file', 'Use .dSYM file to symbolicating crash logs') {|b| opts[:dsym_file_path] = File.expand_path(b)}
|
20
|
-
o.on('-c
|
21
|
-
o.on('-
|
20
|
+
o.on('-c custom_cfg_path', 'Indicate confige lib directory path, not a file path.') {|b| opts[:custom_cfg_path] = File.expand_path(b)}
|
21
|
+
o.on('--event-number event_number', 'The monkey event number(default: 50)'){|b| opts[:event_number] = b}
|
22
22
|
o.on('--compress-result compress_rate', 'compress the screenshot images to save disk space!(example: 50%)'){|b| opts[:compress_rate] = b}
|
23
23
|
o.on('--detail-count detail_event_count', 'How many events to show in detail result page(default 50)'){|b| opts[:detail_event_count] = b.to_i}
|
24
24
|
o.on('--show-config', 'Show Current Configuration custom.js') {|_| opts[:show_config] = true}
|
25
25
|
o.on('--drop-useless-img', 'Delete the un-displayed images of detial page.') {|_| opts[:drop_useless_img] = true}
|
26
26
|
o.on('--list-app', 'Show List of Installed Apps in iPhone/iPhone Simulator') {|_| opts[:list_app] = true}
|
27
27
|
o.on('--list-devices', 'Show List of Devices') {|_| opts[:list_devices] = true}
|
28
|
-
o.on('--reset-
|
28
|
+
o.on('--reset-ios-sim', 'Reset iPhone Simulator'){|_| opts[:reset_iphone_simulator] = true}
|
29
29
|
o.on('--version', 'print smart monkey version'){|_| opts[:version] = true}
|
30
30
|
o.parse!
|
31
31
|
end
|
@@ -39,6 +39,13 @@ if opts[:version]
|
|
39
39
|
exit(1)
|
40
40
|
end
|
41
41
|
|
42
|
+
if opts[:custom_cfg_path]
|
43
|
+
if !File.directory? opts[:custom_cfg_path]
|
44
|
+
puts ARGV.options.help
|
45
|
+
exit(1)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
42
49
|
unless opts[:app_path] || opts[:show_config] || opts[:list_app] || opts[:reset_iphone_simulator] || opts[:list_devices]
|
43
50
|
puts ARGV.options.help
|
44
51
|
exit(1)
|
@@ -28,18 +28,18 @@ module UIAutoMonkey
|
|
28
28
|
Open3.popen3(*cmds) do |stdin, stdout, stderr, thread|
|
29
29
|
@tmpline = ""
|
30
30
|
stdin.close
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
31
|
+
app_hang_monitor_thread = Thread.start{
|
32
|
+
sleep 30
|
33
|
+
while true
|
34
|
+
current_line = @tmpline
|
35
|
+
sleep 30
|
36
|
+
after_sleep_line = @tmpline
|
37
|
+
if current_line == after_sleep_line
|
38
|
+
puts "WARN: no response in log, trigger re-launch action."
|
39
|
+
relaunch_app(device, app)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
}
|
43
43
|
instruments_stderr_thread = Thread.start{
|
44
44
|
stderr.each do |line|
|
45
45
|
puts line
|
@@ -48,11 +48,11 @@ module UIAutoMonkey
|
|
48
48
|
stdout.each do |line|
|
49
49
|
@tmpline = line.strip
|
50
50
|
puts @tmpline
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
if @tmpline =~ /MonkeyTest finish/ || @tmpline =~ /Script was stopped by the user/
|
52
|
+
app_hang_monitor_thread.kill
|
53
|
+
end
|
54
54
|
end
|
55
|
-
|
55
|
+
app_hang_monitor_thread.kill
|
56
56
|
instruments_stderr_thread.kill
|
57
57
|
end
|
58
58
|
end
|
@@ -186,8 +186,9 @@ module UIAutoMonkey
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def reset_iphone_simulator
|
189
|
-
|
190
|
-
|
189
|
+
`killall -9 "iOS Simulator"`
|
190
|
+
# FileUtils.rm_rf("#{Dir.home}/Library/Application\ Support/iPhone\ Simulator/")
|
191
|
+
# puts 'reset iPhone Simulator successful'
|
191
192
|
end
|
192
193
|
|
193
194
|
def total_test_count
|
@@ -324,10 +325,15 @@ module UIAutoMonkey
|
|
324
325
|
"3"=>"270",
|
325
326
|
"4"=>"90",
|
326
327
|
}
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
328
|
+
orientation_file = File.join(result_base_dir,"orientation")
|
329
|
+
if File.exists?(orientation_file)
|
330
|
+
orientationNum = File.read(orientation_file).strip
|
331
|
+
value = rotated_map[orientationNum]
|
332
|
+
unless value.nil?
|
333
|
+
`mogrify -rotate #{value} "#{path}/*.png"`
|
334
|
+
end
|
335
|
+
else
|
336
|
+
exit(1)
|
331
337
|
end
|
332
338
|
end
|
333
339
|
|
@@ -368,6 +374,10 @@ module UIAutoMonkey
|
|
368
374
|
File.expand_path('../../ios_device_log/deviceconsole', __FILE__)
|
369
375
|
end
|
370
376
|
|
377
|
+
def ui_auto_monkey_lib_original_path
|
378
|
+
File.expand_path('../../ui-auto-monkey', __FILE__)
|
379
|
+
end
|
380
|
+
|
371
381
|
def ui_auto_monkey_original_path
|
372
382
|
File.expand_path('../../ui-auto-monkey/UIAutoMonkey.js', __FILE__)
|
373
383
|
end
|
@@ -476,6 +486,20 @@ module UIAutoMonkey
|
|
476
486
|
`xsltproc --output "#{result_dir}/uiautomation.html" #{uiautomation_xsl_path} "#{result_dir}/Automation Results.plist"`
|
477
487
|
end
|
478
488
|
|
489
|
+
def replace_event_num_for_time_limit(custom_file)
|
490
|
+
File.open(custom_file) do |fr|
|
491
|
+
buffer = fr.read.gsub(/monkey.config.numberOfEvents.*;/, "monkey.config.numberOfEvents = 99999999;")
|
492
|
+
File.open(custom_file, "w") { |fw| fw.write(buffer) }
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
def replace_event_num_for_user_define(custom_file, event_number)
|
497
|
+
File.open(custom_file) do |fr|
|
498
|
+
buffer = fr.read.gsub(/monkey.config.numberOfEvents.*;/, "monkey.config.numberOfEvents = #{event_number};")
|
499
|
+
File.open(custom_file, "w") { |fw| fw.write(buffer) }
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
479
503
|
def generate_ui_auto_monkey
|
480
504
|
# extend_javascript_flag, extend_javascript_path = show_extend_javascript
|
481
505
|
# orig = File.read(ui_custom_original_path)
|
@@ -487,15 +511,23 @@ module UIAutoMonkey
|
|
487
511
|
# end
|
488
512
|
envs_str="UniqueDeviceID=\"#{device}\";\nResultBaseDir=\"#{result_base_dir}\";\n"
|
489
513
|
File.open(File.join(result_base_dir,"Env.js"), 'w') {|f| f.write(envs_str)}
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
514
|
+
if @options[:custom_cfg_path]
|
515
|
+
FileUtils.cp_r(File.join(@options[:custom_cfg_path], "."), result_base_dir)
|
516
|
+
FileUtils.copy(ui_auto_monkey_original_path, result_base_dir)
|
517
|
+
FileUtils.cp_r(ui_tuneup_original_path, result_base_dir)
|
518
|
+
else
|
519
|
+
FileUtils.cp_r(File.join(ui_auto_monkey_lib_original_path, "."), result_base_dir)
|
520
|
+
end
|
521
|
+
replace_event_num_for_user_define(ui_custom_path, @options[:event_number]) if @options[:event_number]
|
522
|
+
replace_event_num_for_time_limit(ui_custom_path) unless time_limit_sec.nil?
|
495
523
|
end
|
496
524
|
|
497
525
|
def config_custom_path
|
498
|
-
@options[:
|
526
|
+
if @options[:custom_cfg_path]
|
527
|
+
File.join(@options[:custom_cfg_path], "custom.js")
|
528
|
+
else
|
529
|
+
ui_custom_original_path
|
530
|
+
end
|
499
531
|
end
|
500
532
|
|
501
533
|
def replace_text(orig, replace_str, marker_begin_line, marker_end_line)
|
@@ -540,7 +572,6 @@ module UIAutoMonkey
|
|
540
572
|
hash[:uia_trace] = @uia_trace
|
541
573
|
hash[:crashed] = @crashed
|
542
574
|
hash[:no_run] = @no_run
|
543
|
-
|
544
575
|
er = Erubis::Eruby.new(File.read(template_path('result.html.erb')))
|
545
576
|
open("#{result_dir}/result.html", 'w') do |f|
|
546
577
|
f.write(er.result(hash))
|
@@ -1,11 +1,9 @@
|
|
1
1
|
#import "UIAutoMonkey.js"
|
2
|
-
#import "handler/buttonHandler.js"
|
3
|
-
#import "handler/wbScrollViewButtonHandler.js"
|
4
2
|
#import "tuneup/tuneup.js"
|
5
3
|
|
6
4
|
// Configure the monkey: use the default configuration but a bit tweaked
|
7
5
|
monkey = new UIAutoMonkey();
|
8
|
-
monkey.config.numberOfEvents = 50; //
|
6
|
+
monkey.config.numberOfEvents = 50; // total number of monkey event
|
9
7
|
monkey.config.delayBetweenEvents = 0.05;
|
10
8
|
monkey.config.eventWeights = {
|
11
9
|
tap: 100,
|
@@ -30,44 +28,12 @@ monkey.config.frame = {
|
|
30
28
|
x: parseInt(UIATarget.localTarget().rect().origin.x),
|
31
29
|
y: parseInt(UIATarget.localTarget().rect().origin.y)+20
|
32
30
|
},
|
33
|
-
size:
|
31
|
+
size:
|
32
|
+
{
|
34
33
|
width: parseInt(UIATarget.localTarget().rect().size.width),
|
35
34
|
height: parseInt(UIATarget.localTarget().rect().size.height)-20
|
36
35
|
}
|
37
36
|
};// Ignore the UIAStatusBar area, avoid to drag out the notification page.
|
38
37
|
|
39
|
-
//UI Holes handlers
|
40
|
-
var handlers = [];
|
41
|
-
handlers.push(new ButtonHandler("WBBack", 10, true));
|
42
|
-
handlers.push(new WBScrollViewButtonHandler("weatherLeftBack", 5, false, 1));
|
43
|
-
handlers.push(new ButtonHandler("取消", 3, true));
|
44
|
-
handlers.push(new ButtonHandler("CloseX", 3, true));
|
45
|
-
handlers.push(new ButtonHandler("确定", 3, false));
|
46
|
-
|
47
|
-
monkey.config.conditionHandlers = handlers;
|
48
|
-
|
49
|
-
//ANR settings
|
50
|
-
var aFingerprintFunction = function() {
|
51
|
-
var mainWindow = UIATarget.localTarget().frontMostApp().mainWindow();
|
52
|
-
//if an error occurs log it and make it the fingerprint
|
53
|
-
try {
|
54
|
-
var aString = mainWindow.elementAccessorDump("tree", true);
|
55
|
-
// var aString = mainWindow.logElementTree();
|
56
|
-
// var aString = mainWindow.logElementJSON(["name"])
|
57
|
-
if (monkey.config.anrSettings.debug) {
|
58
|
-
UIALogger.logDebug("fingerprintFunction tree=" + aString);
|
59
|
-
}
|
60
|
-
}
|
61
|
-
catch (e) {
|
62
|
-
aString = "fingerprintFunction error:" + e;
|
63
|
-
UIALogger.logWarning(aString);
|
64
|
-
}
|
65
|
-
return aString;
|
66
|
-
};
|
67
|
-
monkey.config.anrSettings.fingerprintFunction = false;//false | aFingerprintFunction
|
68
|
-
monkey.config.anrSettings.eventsBeforeANRDeclared = 18; //throw exception if the fingerprint hasn't changed within this number of events
|
69
|
-
monkey.config.anrSettings.eventsBetweenSnapshots = 8; //how often (in events) to take a snapshot using the fingerprintFunction
|
70
|
-
monkey.config.anrSettings.debug = false; //log extra info on ANR state changes
|
71
|
-
|
72
38
|
// Release the monkey!
|
73
39
|
monkey.RELEASE_THE_MONKEY();
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_monkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vigossjjj
|
@@ -144,8 +144,6 @@ files:
|
|
144
144
|
- lib/smart_monkey/templates/result_view.js
|
145
145
|
- lib/ui-auto-monkey/UIAutoMonkey.js
|
146
146
|
- lib/ui-auto-monkey/custom.js
|
147
|
-
- lib/ui-auto-monkey/handler/buttonHandler.js
|
148
|
-
- lib/ui-auto-monkey/handler/wbScrollViewButtonHandler.js
|
149
147
|
- lib/ui-auto-monkey/tuneup/LICENSE
|
150
148
|
- lib/ui-auto-monkey/tuneup/assertions.js
|
151
149
|
- lib/ui-auto-monkey/tuneup/image_asserter
|
@@ -1,111 +0,0 @@
|
|
1
|
-
// Copyright (c) 2015 Yahoo inc. (http://www.yahoo-inc.com)
|
2
|
-
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
8
|
-
// furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
11
|
-
// all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
// THE SOFTWARE.
|
20
|
-
|
21
|
-
"use strict";
|
22
|
-
//Conforms to the ConditionHandler protocol in UIAutoMonkey
|
23
|
-
//Usage
|
24
|
-
// var handlers = [ ];
|
25
|
-
// var handlerInterval = 20; //every how many events to process. Can vary by each handler, but often useful to group them
|
26
|
-
// handlers.push(new ButtonHandler("Done", handlerInterval, false)); //every 20 events, press "Done" button if found as a top level button (no nav bar).
|
27
|
-
// ...
|
28
|
-
// config.conditionHandlers = handlers
|
29
|
-
//
|
30
|
-
function ButtonHandler(buttonName, checkEveryNumber, useNavBar, optionalIsTrueFunction) {
|
31
|
-
this.buttonName = buttonName;
|
32
|
-
this.checkEveryNumber = checkEveryNumber || 10;
|
33
|
-
if (useNavBar == undefined) {
|
34
|
-
useNavBar = true;
|
35
|
-
};
|
36
|
-
this.useNavBar = useNavBar;
|
37
|
-
this.optionalIsTrueFunction = optionalIsTrueFunction || null;
|
38
|
-
//stats
|
39
|
-
this.statsIsTrueInvokedCount = 0;
|
40
|
-
this.statsIsTrueReturnedTrue = 0;
|
41
|
-
this.statsIsTrueReturnedFalse = 0;
|
42
|
-
this.statsHandleInvokedCount = 0;
|
43
|
-
this.statsHandleNotValidAndVisibleCount = 0;
|
44
|
-
this.statsHandleErrorCount = 0;
|
45
|
-
}
|
46
|
-
|
47
|
-
// return true if we our button is visible
|
48
|
-
ButtonHandler.prototype.isTrue = function(target, eventCount, mainWindow) {
|
49
|
-
this.statsIsTrueInvokedCount++;
|
50
|
-
var result;
|
51
|
-
if (this.optionalIsTrueFunction == null) {
|
52
|
-
var aButton = this.findButton(target);
|
53
|
-
// result = aButton.isNotNil() && aButton.validAndVisible();
|
54
|
-
result = aButton.isNotNil() && aButton.isValid() && aButton.isVisible();
|
55
|
-
} else {
|
56
|
-
result = this.optionalIsTrueFunction(target, eventCount, mainWindow);
|
57
|
-
}
|
58
|
-
if (result) {
|
59
|
-
this.statsIsTrueReturnedTrue++;
|
60
|
-
} else {
|
61
|
-
this.statsIsTrueReturnedFalse++;
|
62
|
-
};
|
63
|
-
return result;
|
64
|
-
};
|
65
|
-
|
66
|
-
ButtonHandler.prototype.findButton = function(target) {
|
67
|
-
return this.useNavBar ?
|
68
|
-
target.frontMostApp().mainWindow().navigationBar().buttons()[this.buttonName] :
|
69
|
-
target.frontMostApp().mainWindow().buttons()[this.buttonName];
|
70
|
-
};
|
71
|
-
|
72
|
-
//every checkEvery() number of events our isTrue() method will be queried.
|
73
|
-
ButtonHandler.prototype.checkEvery = function() {
|
74
|
-
return this.checkEveryNumber;
|
75
|
-
};
|
76
|
-
|
77
|
-
// if true then after we handle an event consider the particular Monkey event handled, and don't process the other condition handlers.
|
78
|
-
ButtonHandler.prototype.isExclusive = function() {
|
79
|
-
return true;
|
80
|
-
};
|
81
|
-
|
82
|
-
// Press our button
|
83
|
-
ButtonHandler.prototype.handle = function(target, mainWindow) {
|
84
|
-
this.statsHandleInvokedCount++;
|
85
|
-
var button = this.findButton(target);
|
86
|
-
if (button.isValid() && button.isVisible()) {
|
87
|
-
try{
|
88
|
-
button.tap();
|
89
|
-
} catch(err) {
|
90
|
-
this.statsHandleErrorCount++;
|
91
|
-
UIALogger.logWarning(err);
|
92
|
-
}
|
93
|
-
} else {
|
94
|
-
this.statsHandleNotValidAndVisibleCount++
|
95
|
-
//UIALogger.logWarning(this.toString() + " button is not validAndVisible");
|
96
|
-
};
|
97
|
-
};
|
98
|
-
|
99
|
-
ButtonHandler.prototype.toString = function() {
|
100
|
-
return ["MonkeyTest::ButtonHandler(" + this.buttonName, this.checkEveryNumber, this.useNavBar, ")"].join();
|
101
|
-
};
|
102
|
-
|
103
|
-
ButtonHandler.prototype.logStats = function() {
|
104
|
-
UIALogger.logDebug([this.toString(),
|
105
|
-
"IsTrueInvokedCount", this.statsIsTrueInvokedCount,
|
106
|
-
"IsTrueReturnedTrue", this.statsIsTrueReturnedTrue,
|
107
|
-
"IsTrueReturnedFalse", this.statsIsTrueReturnedFalse,
|
108
|
-
"HandleInvokedCount", this.statsHandleInvokedCount,
|
109
|
-
"HandleNotValidAndVisibleCount", this.statsHandleNotValidAndVisibleCount,
|
110
|
-
"HandleErrorCount", this.statsHandleErrorCount].join());
|
111
|
-
};
|
@@ -1,114 +0,0 @@
|
|
1
|
-
// Copyright (c) 2015 Yahoo inc. (http://www.yahoo-inc.com)
|
2
|
-
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
8
|
-
// furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
11
|
-
// all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
// THE SOFTWARE.
|
20
|
-
|
21
|
-
"use strict";
|
22
|
-
//Conforms to the ConditionHandler protocol in UIAutoMonkey
|
23
|
-
//Usage
|
24
|
-
// var handlers = [ ];
|
25
|
-
// var handlerInterval = 20; //every how many events to process. Can vary by each handler, but often useful to group them
|
26
|
-
// handlers.push(new ButtonHandler("Done", handlerInterval, false)); //every 20 events, press "Done" button if found as a top level button (no nav bar).
|
27
|
-
// ...
|
28
|
-
// config.conditionHandlers = handlers
|
29
|
-
//
|
30
|
-
function WBScrollViewButtonHandler(buttonName, checkEveryNumber, useNavBar, scrollViewIndex, optionalIsTrueFunction) {
|
31
|
-
this.buttonName = buttonName;
|
32
|
-
this.scrollViewIndex = scrollViewIndex;
|
33
|
-
this.checkEveryNumber = checkEveryNumber || 10;
|
34
|
-
if (useNavBar == undefined) {
|
35
|
-
useNavBar = true;
|
36
|
-
};
|
37
|
-
this.useNavBar = useNavBar;
|
38
|
-
this.optionalIsTrueFunction = optionalIsTrueFunction || null;
|
39
|
-
//stats
|
40
|
-
this.statsIsTrueInvokedCount = 0;
|
41
|
-
this.statsIsTrueReturnedTrue = 0;
|
42
|
-
this.statsIsTrueReturnedFalse = 0;
|
43
|
-
this.statsHandleInvokedCount = 0;
|
44
|
-
this.statsHandleNotValidAndVisibleCount = 0;
|
45
|
-
this.statsHandleErrorCount = 0;
|
46
|
-
}
|
47
|
-
|
48
|
-
// return true if we our button is visible
|
49
|
-
WBScrollViewButtonHandler.prototype.isTrue = function(target, eventCount, mainWindow) {
|
50
|
-
this.statsIsTrueInvokedCount++;
|
51
|
-
var result;
|
52
|
-
if (this.optionalIsTrueFunction == null) {
|
53
|
-
var aButton = this.findButton(target);
|
54
|
-
// result = aButton.isNotNil() && aButton.validAndVisible();
|
55
|
-
result = aButton.isNotNil() && aButton.isValid();
|
56
|
-
} else {
|
57
|
-
result = this.optionalIsTrueFunction(target, eventCount, mainWindow);
|
58
|
-
}
|
59
|
-
if (result) {
|
60
|
-
this.statsIsTrueReturnedTrue++;
|
61
|
-
} else {
|
62
|
-
this.statsIsTrueReturnedFalse++;
|
63
|
-
};
|
64
|
-
return result;
|
65
|
-
};
|
66
|
-
|
67
|
-
WBScrollViewButtonHandler.prototype.findButton = function(target) {
|
68
|
-
return this.useNavBar ?
|
69
|
-
target.frontMostApp().mainWindow().navigationBar().buttons()[this.buttonName]:
|
70
|
-
target.frontMostApp().mainWindow().scrollViews()[this.scrollViewIndex].buttons()[this.buttonName];
|
71
|
-
};
|
72
|
-
|
73
|
-
//every checkEvery() number of events our isTrue() method will be queried.
|
74
|
-
WBScrollViewButtonHandler.prototype.checkEvery = function() {
|
75
|
-
return this.checkEveryNumber;
|
76
|
-
};
|
77
|
-
|
78
|
-
// if true then after we handle an event consider the particular Monkey event handled, and don't process the other condition handlers.
|
79
|
-
WBScrollViewButtonHandler.prototype.isExclusive = function() {
|
80
|
-
return true;
|
81
|
-
};
|
82
|
-
|
83
|
-
// Press our button
|
84
|
-
WBScrollViewButtonHandler.prototype.handle = function(target, mainWindow) {
|
85
|
-
this.statsHandleInvokedCount++;
|
86
|
-
var button = this.findButton(target);
|
87
|
-
if (button.isValid()) {
|
88
|
-
try{
|
89
|
-
var x = button.rect().origin.x;
|
90
|
-
var y = button.rect().origin.y;
|
91
|
-
target.tap({x:x, y:y});
|
92
|
-
} catch(err) {
|
93
|
-
this.statsHandleErrorCount++;
|
94
|
-
UIALogger.logWarning(err);
|
95
|
-
}
|
96
|
-
} else {
|
97
|
-
this.statsHandleNotValidAndVisibleCount++
|
98
|
-
//UIALogger.logWarning(this.toString() + " button is not validAndVisible");
|
99
|
-
};
|
100
|
-
};
|
101
|
-
|
102
|
-
WBScrollViewButtonHandler.prototype.toString = function() {
|
103
|
-
return ["MonkeyTest::WBScrollViewButtonHandler(" + this.buttonName, this.checkEveryNumber, this.useNavBar, this.scrollViewIndex, ")"].join();
|
104
|
-
};
|
105
|
-
|
106
|
-
WBScrollViewButtonHandler.prototype.logStats = function() {
|
107
|
-
UIALogger.logDebug([this.toString(),
|
108
|
-
"IsTrueInvokedCount", this.statsIsTrueInvokedCount,
|
109
|
-
"IsTrueReturnedTrue", this.statsIsTrueReturnedTrue,
|
110
|
-
"IsTrueReturnedFalse", this.statsIsTrueReturnedFalse,
|
111
|
-
"HandleInvokedCount", this.statsHandleInvokedCount,
|
112
|
-
"HandleNotValidAndVisibleCount", this.statsHandleNotValidAndVisibleCount,
|
113
|
-
"HandleErrorCount", this.statsHandleErrorCount].join());
|
114
|
-
};
|