smart_monkey 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +57 -0
- data/Troubleshooting.md +61 -0
- data/VERSION +1 -0
- data/bin/smart_monkey +53 -0
- data/lib/bootstrap/css/bootstrap-responsive.css +1109 -0
- data/lib/bootstrap/css/bootstrap-responsive.min.css +9 -0
- data/lib/bootstrap/css/bootstrap.css +6167 -0
- data/lib/bootstrap/css/bootstrap.min.css +9 -0
- data/lib/bootstrap/img/glyphicons-halflings-white.png +0 -0
- data/lib/bootstrap/img/glyphicons-halflings.png +0 -0
- data/lib/bootstrap/js/bootstrap.js +2280 -0
- data/lib/bootstrap/js/bootstrap.min.js +6 -0
- data/lib/ios_device_log/deviceconsole +0 -0
- data/lib/smart_monkey.rb +2 -0
- data/lib/smart_monkey/command_helper.rb +71 -0
- data/lib/smart_monkey/monkey_runner.rb +549 -0
- data/lib/smart_monkey/templates/automation_result.xsl +61 -0
- data/lib/smart_monkey/templates/index.html.erb +77 -0
- data/lib/smart_monkey/templates/result.html.erb +110 -0
- data/lib/smart_monkey/templates/result_view.coffee +160 -0
- data/lib/smart_monkey/templates/result_view.js +250 -0
- data/lib/ui-auto-monkey/UIAutoMonkey.js +470 -0
- data/lib/ui-auto-monkey/custom.js +73 -0
- data/lib/ui-auto-monkey/handler/buttonHandler.js +111 -0
- data/lib/ui-auto-monkey/handler/wbScrollViewButtonHandler.js +114 -0
- data/lib/ui-auto-monkey/tuneup/LICENSE +20 -0
- data/lib/ui-auto-monkey/tuneup/assertions.js +402 -0
- data/lib/ui-auto-monkey/tuneup/image_asserter +26 -0
- data/lib/ui-auto-monkey/tuneup/image_assertion.js +65 -0
- data/lib/ui-auto-monkey/tuneup/image_assertion.rb +102 -0
- data/lib/ui-auto-monkey/tuneup/lang-ext.js +76 -0
- data/lib/ui-auto-monkey/tuneup/screen.js +11 -0
- data/lib/ui-auto-monkey/tuneup/test.js +71 -0
- data/lib/ui-auto-monkey/tuneup/test_runner/abbreviated_console_output.rb +38 -0
- data/lib/ui-auto-monkey/tuneup/test_runner/colored_console_output.rb +27 -0
- data/lib/ui-auto-monkey/tuneup/test_runner/console_output.rb +17 -0
- data/lib/ui-auto-monkey/tuneup/test_runner/preprocessor.rb +25 -0
- data/lib/ui-auto-monkey/tuneup/test_runner/run +343 -0
- data/lib/ui-auto-monkey/tuneup/test_runner/xunit_output.rb +114 -0
- data/lib/ui-auto-monkey/tuneup/tuneup.js +6 -0
- data/lib/ui-auto-monkey/tuneup/tuneup_js.podspec +52 -0
- data/lib/ui-auto-monkey/tuneup/uiautomation-ext.js +965 -0
- data/smart_monkey.gemspec +112 -0
- data/spec/spec_helper.rb +12 -0
- metadata +192 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
3
|
+
<xsl:template match="/">
|
4
|
+
<html>
|
5
|
+
<head>
|
6
|
+
<title>Test Result</title>
|
7
|
+
<link rel="stylesheet" type="text/css" href="../bootstrap.css" />
|
8
|
+
<style TYPE="text/css">
|
9
|
+
<xsl:text disable-output-escaping="yes"><![CDATA[<!-- tr:nth-child(even) { background-color: #d9edf7; } -->]]></xsl:text>
|
10
|
+
</style>
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<h1>UIAutomation Trace</h1>
|
14
|
+
<table class="table table-bordered">
|
15
|
+
<tr>
|
16
|
+
<th>Timestamp</th>
|
17
|
+
<th>Sequence</th>
|
18
|
+
<th>Type</th>
|
19
|
+
<th>Message</th>
|
20
|
+
</tr>
|
21
|
+
<xsl:for-each select="plist/dict/array/dict">
|
22
|
+
<xsl:variable name="Type"><xsl:value-of select="./integer[preceding-sibling::key='Type'][1]"/></xsl:variable>
|
23
|
+
<xsl:variable name="LogType"><xsl:value-of select="./string[preceding-sibling::key='LogType'][1]"/></xsl:variable>
|
24
|
+
<xsl:variable name="Message"><xsl:value-of select="./string[preceding-sibling::key='Message'][1]"/></xsl:variable>
|
25
|
+
<tr>
|
26
|
+
<td>
|
27
|
+
<span style="display:inline-block;white-space:nowrap;">
|
28
|
+
<xsl:value-of select="translate(translate(date, 'T',' '), 'Z','')"/>
|
29
|
+
</span>
|
30
|
+
</td>
|
31
|
+
<td>
|
32
|
+
<span style="display:inline-block;white-space:nowrap;">
|
33
|
+
<xsl:value-of select="position()"/>
|
34
|
+
</span>
|
35
|
+
</td>
|
36
|
+
<td>
|
37
|
+
<span style="display:inline-block;white-space:nowrap;">
|
38
|
+
<xsl:choose>
|
39
|
+
<xsl:when test="integer = 8"><span style="color:blue">Screenshot</span></xsl:when>
|
40
|
+
<xsl:when test="integer = 5"><span style="color:green">Pass</span></xsl:when>
|
41
|
+
<xsl:when test="integer = 4"><span style="color:orange">Message</span></xsl:when>
|
42
|
+
<xsl:when test="integer = 1"><span style="color:black">Default</span></xsl:when>
|
43
|
+
<xsl:when test="integer = 0"><span style="color:gray">Debug</span></xsl:when>
|
44
|
+
<xsl:when test="integer = 7"><span style="color:red">Fail</span></xsl:when>
|
45
|
+
<xsl:when test="integer = 3"><span style="color:red">Error</span></xsl:when>
|
46
|
+
<xsl:otherwise><xsl:value-of select="integer"/></xsl:otherwise>
|
47
|
+
</xsl:choose>
|
48
|
+
</span>
|
49
|
+
</td>
|
50
|
+
<td>
|
51
|
+
<span style="display:inline-block;white-space:nowrap;">
|
52
|
+
<xsl:copy-of select="$Message"/>
|
53
|
+
</span>
|
54
|
+
</td>
|
55
|
+
</tr>
|
56
|
+
</xsl:for-each>
|
57
|
+
</table>
|
58
|
+
</body>
|
59
|
+
</html>
|
60
|
+
</xsl:template>
|
61
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en-US">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>Monkey Test</title>
|
6
|
+
<link rel="stylesheet" type="text/css" href="bootstrap.css"/>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div class="container">
|
10
|
+
<div class="row">
|
11
|
+
<div class="span9 offset1">
|
12
|
+
<h1>Summary</h1>
|
13
|
+
<div>
|
14
|
+
<ul>
|
15
|
+
<li>Hardware: <%= ProductType %>, <%= ProductVersion %>, <%= UniqueDeviceID %></li>
|
16
|
+
<li>Application: <%= Application %> </li>
|
17
|
+
<li>Span: <%= start_time %> ~ <%= end_time %></li>
|
18
|
+
<li>Results: <%= test_count %> Test, <%= ok_count %> Ok, <%= cr_count %> Crash, <%= nr_count %> No Run</li>
|
19
|
+
</ul>
|
20
|
+
</div>
|
21
|
+
<h1>Details</h1>
|
22
|
+
<table class="table table-bordered">
|
23
|
+
<thead>
|
24
|
+
<tr>
|
25
|
+
<th>No</th>
|
26
|
+
<th>Result</th>
|
27
|
+
<th>Duration</th>
|
28
|
+
<th>message</th>
|
29
|
+
</tr>
|
30
|
+
</thead>
|
31
|
+
<tbody>
|
32
|
+
<% for result in result_list %>
|
33
|
+
<% if result[:ok] %>
|
34
|
+
<tr class="success">
|
35
|
+
<td><%= result[:times]+1 %></td>
|
36
|
+
<td>
|
37
|
+
<a href="<%= result[:result_dir] %>/result.html">
|
38
|
+
<span>OK</span>
|
39
|
+
</a>
|
40
|
+
</td>
|
41
|
+
<td><%= result[:end_time].to_i - result[:start_time].to_i%> Sec</td>
|
42
|
+
<td><%= result[:message] %></td>
|
43
|
+
</tr>
|
44
|
+
|
45
|
+
<% elsif result[:crash] %>
|
46
|
+
<tr class="error">
|
47
|
+
<td><%= result[:times]+1 %></td>
|
48
|
+
<td>
|
49
|
+
<a href="<%= result[:result_dir] %>/result.html">
|
50
|
+
<span>Crash</span>
|
51
|
+
</a>
|
52
|
+
</td>
|
53
|
+
<td><%= result[:end_time].to_i - result[:start_time].to_i%> Sec</td>
|
54
|
+
<td><%= result[:message] %></td>
|
55
|
+
</tr>
|
56
|
+
<% else %>
|
57
|
+
<tr class="warning">
|
58
|
+
<td><%= result[:times]+1 %></td>
|
59
|
+
<td>
|
60
|
+
<a href="<%= result[:result_dir] %>/result.html">
|
61
|
+
<span>No Run</span>
|
62
|
+
</a>
|
63
|
+
</td>
|
64
|
+
<td><%= result[:end_time].to_i - result[:start_time].to_i%> Sec</td>
|
65
|
+
<td><%= result[:message] %></td>
|
66
|
+
</tr>
|
67
|
+
<% end %>
|
68
|
+
<% end %>
|
69
|
+
</tbody>
|
70
|
+
</table>
|
71
|
+
</div>
|
72
|
+
</div>
|
73
|
+
</div>
|
74
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
75
|
+
<script src="bootstrap.js"></script>
|
76
|
+
</body>
|
77
|
+
</html>
|
@@ -0,0 +1,110 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en-US">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
|
6
|
+
<script src="result_view.js"></script>
|
7
|
+
<link rel="stylesheet" type="text/css" href="../bootstrap.css"/>
|
8
|
+
<title>MonkeyTest Result</title>
|
9
|
+
<style type="text/css">
|
10
|
+
<!--
|
11
|
+
.warning {
|
12
|
+
color: red;
|
13
|
+
font-size: 20px;
|
14
|
+
}
|
15
|
+
.event_box {
|
16
|
+
position: relative;
|
17
|
+
display: inline;
|
18
|
+
}
|
19
|
+
|
20
|
+
.event_text {
|
21
|
+
font-size: 12px;
|
22
|
+
position: absolute;
|
23
|
+
display: none;
|
24
|
+
width: 300px;
|
25
|
+
height: 300px;
|
26
|
+
padding: 3px;
|
27
|
+
border: #000066 groove thick;
|
28
|
+
background-color: #ffdead;
|
29
|
+
border-radius: 10px; /* CSS3草案 */
|
30
|
+
-webkit-border-radius: 10px; /* Safari,Google Chrome用 */
|
31
|
+
-moz-border-radius: 10px; /* Firefox用 */
|
32
|
+
}
|
33
|
+
|
34
|
+
.event_box:hover .event_text {
|
35
|
+
left: 0px;
|
36
|
+
display: inline;
|
37
|
+
z-index: 10000;
|
38
|
+
}
|
39
|
+
-->
|
40
|
+
</style>
|
41
|
+
</head>
|
42
|
+
<body>
|
43
|
+
<br>
|
44
|
+
<div class="container theme-showcase" role="main">
|
45
|
+
<div class="jumbotron">
|
46
|
+
<% if crashed %>
|
47
|
+
<center>
|
48
|
+
<div class="alert alert-danger" role="alert">
|
49
|
+
<h1>
|
50
|
+
<strong>Crash!</strong>
|
51
|
+
Application crashed during the monkey testing.
|
52
|
+
</h1>
|
53
|
+
</div>
|
54
|
+
</center>
|
55
|
+
<% elsif no_run %>
|
56
|
+
<center>
|
57
|
+
<div class="alert alert-warning" role="alert">
|
58
|
+
<h1>
|
59
|
+
<strong>No run!</strong>
|
60
|
+
Application not start monkey testing.
|
61
|
+
</h1>
|
62
|
+
</div>
|
63
|
+
</center>
|
64
|
+
<% else %>
|
65
|
+
<center>
|
66
|
+
<div class="alert alert-success" role="alert">
|
67
|
+
<h1>
|
68
|
+
<strong>Well done!</strong>
|
69
|
+
None crash happend.
|
70
|
+
</h1>
|
71
|
+
</div>
|
72
|
+
</center>
|
73
|
+
<% end %>
|
74
|
+
|
75
|
+
<p>
|
76
|
+
<center>
|
77
|
+
<a class="btn btn-lg btn-info" role="button" href="console.txt" style="font-size: 18px; text-align:center; height: 20px; width: 100px;">system log</a>
|
78
|
+
<% if uia_trace %>
|
79
|
+
<a class="btn btn-lg btn-primary" role="button" href="./uiautomation.html" style="font-size: 18px; text-align:center; height: 20px; width: 100px;">uiauto trace</a>
|
80
|
+
<% end %>
|
81
|
+
<% if crash_report %>
|
82
|
+
<a class="btn btn-lg btn-danger" role="button" href="<%= crash_report %>" style="font-size: 18px; text-align:center; height: 20px; width: 100px;">crash log</a>
|
83
|
+
<% end %>
|
84
|
+
</center>
|
85
|
+
</p>
|
86
|
+
</div>
|
87
|
+
</div>
|
88
|
+
<hr>
|
89
|
+
|
90
|
+
<% log_list.each_with_index do |_, i| %>
|
91
|
+
<% if i > 0 %>
|
92
|
+
<div class="event_box"><canvas id="log-<%= i %>"; style="border: 1px black solid"></canvas><div class="event_text" id="text-<%= i %>"></div></div>
|
93
|
+
<% end %>
|
94
|
+
<% end %>
|
95
|
+
<script type="text/javascript">
|
96
|
+
$(function() {
|
97
|
+
MonkeyResult().configure({
|
98
|
+
log_list: log_list_json(),
|
99
|
+
view_prefix: 'log',
|
100
|
+
text_prefix: 'text',
|
101
|
+
image_size_rate: 1
|
102
|
+
}).draw();
|
103
|
+
})
|
104
|
+
|
105
|
+
var log_list_json = function() {
|
106
|
+
return <%= log_list_json %>;
|
107
|
+
}
|
108
|
+
</script>
|
109
|
+
</body>
|
110
|
+
</html>
|
@@ -0,0 +1,160 @@
|
|
1
|
+
MonkeyResult = ->
|
2
|
+
that = {}
|
3
|
+
options = null
|
4
|
+
|
5
|
+
that.configure = (opts) ->
|
6
|
+
options = opts
|
7
|
+
options.image_size_rate = opts.image_size_rate || 1
|
8
|
+
that
|
9
|
+
|
10
|
+
that.draw = ->
|
11
|
+
ir = options.image_size_rate
|
12
|
+
for log, i in options.log_list
|
13
|
+
do (log, i) ->
|
14
|
+
text_div = $('#'+options.text_prefix+'-'+i)
|
15
|
+
text_div.html(log.message + "<hr>"+log.timestamp)
|
16
|
+
img = new Image()
|
17
|
+
img.addEventListener "load", ->
|
18
|
+
element = $('#'+options.view_prefix+'-'+i)
|
19
|
+
canvas = element[0]
|
20
|
+
canvas.width = img.width * ir
|
21
|
+
canvas.height = img.height * ir
|
22
|
+
context = canvas.getContext('2d')
|
23
|
+
context.scale(1,1)
|
24
|
+
context.clearRect(0,0,canvas.width, canvas.height)
|
25
|
+
context.drawImage(img, 0, 0, canvas.width, canvas.height)
|
26
|
+
target = DrawTarget(canvas: canvas, context: context, image_size_rate: ir, index: i)
|
27
|
+
eval(log.message)
|
28
|
+
img.src = log.screen_image + '.png'
|
29
|
+
|
30
|
+
return that
|
31
|
+
|
32
|
+
DrawTarget = (opts) ->
|
33
|
+
that = {}
|
34
|
+
options = opts
|
35
|
+
canvas = options.canvas
|
36
|
+
context = options.context
|
37
|
+
ir = options.image_size_rate
|
38
|
+
context.strokeStyle = "#f00"
|
39
|
+
context.lineWidth = 2
|
40
|
+
arc_radius = 20
|
41
|
+
|
42
|
+
that.tapWithOptions = (p1, info) ->
|
43
|
+
console.log(opts.index, p1, info)
|
44
|
+
pos_to_number(p1)
|
45
|
+
|
46
|
+
tc = 1*info.touchCount
|
47
|
+
for num in [0..(tc-1)]
|
48
|
+
o = x: (context.lineWidth + 2)*(num - (tc-1)/2), y: 0
|
49
|
+
draw_arc({x: (p1.x*ir + o.x)/ir, y: (p1.y*ir + o.y)/ir}, r: 0.1)
|
50
|
+
|
51
|
+
for num in [0..(1*info.tapCount-1)]
|
52
|
+
draw_arc(p1, r: (arc_radius*ir + (1+context.lineWidth)*num)/ir)
|
53
|
+
|
54
|
+
that.pinchCloseFromToForDuration = (p1, p2, info) ->
|
55
|
+
pos_to_number(p) for p in [p1, p2]
|
56
|
+
draw_arc(p1)
|
57
|
+
draw_arc(p2)
|
58
|
+
#
|
59
|
+
center = x: (p1.x+p2.x)/2, y: (p1.y+p2.y)/2
|
60
|
+
draw_arrow(p1, center)
|
61
|
+
draw_arrow(p2, center)
|
62
|
+
|
63
|
+
that.pinchOpenFromToForDuration = (p1, p2, info) ->
|
64
|
+
pos_to_number(p) for p in [p1, p2]
|
65
|
+
draw_arc(p1)
|
66
|
+
draw_arc(p2)
|
67
|
+
#
|
68
|
+
center = x: (p1.x+p2.x)/2, y: (p1.y+p2.y)/2
|
69
|
+
draw_arrow(center, p1)
|
70
|
+
draw_arrow(center, p2)
|
71
|
+
|
72
|
+
that.dragFromToForDuration = (p1, p2, info) ->
|
73
|
+
pos_to_number(p) for p in [p1, p2]
|
74
|
+
console.log(opts.index, p1, p2, info)
|
75
|
+
draw_arc(p1)
|
76
|
+
draw_arc(p2)
|
77
|
+
draw_arrow(p1, p2)
|
78
|
+
|
79
|
+
that.flickFromTo = (p1, p2, info) ->
|
80
|
+
pos_to_number(p) for p in [p1, p2]
|
81
|
+
console.log(opts.index, p1, p2, info)
|
82
|
+
draw_arc(p1)
|
83
|
+
draw_arrow(p1, p2)
|
84
|
+
|
85
|
+
that.lockForDuration = (duration) ->
|
86
|
+
draw_text("Lock Screen #{Math.floor(duration * 100)/100} Secs.")
|
87
|
+
|
88
|
+
that.deactivateAppForDuration = (duration) ->
|
89
|
+
draw_text("Deactivate #{Math.floor(duration * 100)/100} Secs.")
|
90
|
+
|
91
|
+
that.setDeviceOrientation = (orientation) ->
|
92
|
+
draw_text("Orientation to #{orientation_name(orientation)}")
|
93
|
+
|
94
|
+
that.shake = ->
|
95
|
+
draw_text("Shake!")
|
96
|
+
|
97
|
+
that.clickVolumeUp = ->
|
98
|
+
draw_text("clickVolumeUp!")
|
99
|
+
|
100
|
+
that.clickVolumeDown = ->
|
101
|
+
draw_text("clickVolumeDown!")
|
102
|
+
|
103
|
+
draw_text = (text, opts={}) ->
|
104
|
+
context.font = "10px 'MS Pゴシック'"
|
105
|
+
context.lineWidth = 1
|
106
|
+
context.strokeStyle = "green"
|
107
|
+
context.beginPath()
|
108
|
+
context.fillRect(canvas.width*0.1, 20, canvas.width*0.8, 40)
|
109
|
+
context.stroke()
|
110
|
+
context.strokeText(text, canvas.width*0.13, 42)
|
111
|
+
|
112
|
+
|
113
|
+
orientation_name = (orientation) ->
|
114
|
+
# http://www.testmachine.ch/javadoc/constant-values.html#ch.sukha.testmachine.client.IosDebuggingInterface.UIA_DEVICE_ORIENTATION_FACEDOWN
|
115
|
+
switch 1 * orientation
|
116
|
+
when 0 then "UNKNOWN"
|
117
|
+
when 1 then "PORTRAIT"
|
118
|
+
when 2 then "PORTRAIT_UPSIDEDOWN"
|
119
|
+
when 3 then "LANDSCAPELEFT"
|
120
|
+
when 4 then "LANDSCAPERIGHT"
|
121
|
+
when 5 then "FACEUP"
|
122
|
+
when 6 then "FACEDOWN"
|
123
|
+
else "UNDEF"
|
124
|
+
|
125
|
+
pos_to_number = (p) ->
|
126
|
+
p.x = 1 * p.x
|
127
|
+
p.y = 1 * p.y
|
128
|
+
p
|
129
|
+
|
130
|
+
draw_arc = (p, opts={}) ->
|
131
|
+
radius = opts.r || arc_radius
|
132
|
+
context.beginPath()
|
133
|
+
context.arc(p.x * ir, p.y * ir, radius * ir, 0, Math.PI*2)
|
134
|
+
context.stroke()
|
135
|
+
|
136
|
+
draw_arrow = (p1, p2, opts={}) ->
|
137
|
+
vx = p2.x - p1.x
|
138
|
+
vy = p2.y - p1.y
|
139
|
+
v = Math.sqrt(vx*vx + vy*vy)
|
140
|
+
ux = vx/v
|
141
|
+
uy = vy/v
|
142
|
+
opts.w ||= 8
|
143
|
+
opts.h ||= 12
|
144
|
+
opts.h2 ||= 5
|
145
|
+
lp = {x: p2.x - uy * opts.w - ux * opts.h, y: p2.y + ux * opts.w - uy * opts.h}
|
146
|
+
rp = {x: p2.x + uy * opts.w - ux * opts.h, y: p2.y - ux * opts.w - uy * opts.h}
|
147
|
+
mp = {x: p2.x - ux * opts.h2, y: p2.y - uy * opts.h2}
|
148
|
+
context.beginPath()
|
149
|
+
context.moveTo(p1.x * ir, p1.y * ir)
|
150
|
+
context.lineTo(mp.x * ir, mp.y * ir)
|
151
|
+
context.lineTo(lp.x * ir, lp.y * ir)
|
152
|
+
context.lineTo(p2.x * ir, p2.y * ir)
|
153
|
+
context.lineTo(rp.x * ir, rp.y * ir)
|
154
|
+
context.lineTo(mp.x * ir, mp.y * ir)
|
155
|
+
context.stroke()
|
156
|
+
|
157
|
+
return that
|
158
|
+
|
159
|
+
window.MonkeyResult = MonkeyResult
|
160
|
+
|
@@ -0,0 +1,250 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
(function() {
|
3
|
+
var DrawTarget, MonkeyResult;
|
4
|
+
|
5
|
+
MonkeyResult = function() {
|
6
|
+
var options, that;
|
7
|
+
that = {};
|
8
|
+
options = null;
|
9
|
+
that.configure = function(opts) {
|
10
|
+
options = opts;
|
11
|
+
options.image_size_rate = opts.image_size_rate || 1;
|
12
|
+
return that;
|
13
|
+
};
|
14
|
+
that.draw = function() {
|
15
|
+
var i, ir, log, _i, _len, _ref, _results, _size;
|
16
|
+
ir = options.image_size_rate;
|
17
|
+
_ref = options.log_list;
|
18
|
+
_results = [];
|
19
|
+
_size = JSON.parse(_ref[0].screen_size);
|
20
|
+
|
21
|
+
for (i = _i = 1, _len = _ref.length; _i < _len; i = ++_i) {
|
22
|
+
log = _ref[i];
|
23
|
+
_results.push((function(log, i) {
|
24
|
+
var img, text_div;
|
25
|
+
text_div = $('#' + options.text_prefix + '-' + i);
|
26
|
+
text_div.html(log.message + "<hr>" + log.timestamp);
|
27
|
+
img = new Image();
|
28
|
+
img.addEventListener("load", function() {
|
29
|
+
var canvas, context, element, target;
|
30
|
+
element = $('#' + options.view_prefix + '-' + i);
|
31
|
+
canvas = element[0];
|
32
|
+
// canvas.width = img.width * ir /2;
|
33
|
+
// canvas.height = img.height * ir /2;
|
34
|
+
canvas.width = _size.width * ir ;
|
35
|
+
canvas.height = _size.height * ir ;
|
36
|
+
context = canvas.getContext('2d');
|
37
|
+
context.scale(1, 1);
|
38
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
39
|
+
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
40
|
+
target = DrawTarget({
|
41
|
+
canvas: canvas,
|
42
|
+
context: context,
|
43
|
+
image_size_rate: ir,
|
44
|
+
index: i
|
45
|
+
});
|
46
|
+
return eval(log.message);
|
47
|
+
});
|
48
|
+
return img.src = log.screen_image + '.png';
|
49
|
+
})(log, i));
|
50
|
+
}
|
51
|
+
return _results;
|
52
|
+
};
|
53
|
+
return that;
|
54
|
+
};
|
55
|
+
|
56
|
+
DrawTarget = function(opts) {
|
57
|
+
var arc_radius, canvas, context, draw_arc, draw_arrow, draw_text, ir, options, orientation_name, pos_to_number, that;
|
58
|
+
that = {};
|
59
|
+
options = opts;
|
60
|
+
canvas = options.canvas;
|
61
|
+
context = options.context;
|
62
|
+
ir = options.image_size_rate;
|
63
|
+
context.strokeStyle = "#f00";
|
64
|
+
context.lineWidth = 2;
|
65
|
+
arc_radius = 20;
|
66
|
+
that.tapWithOptions = function(p1, info) {
|
67
|
+
var num, o, tc, _i, _j, _ref, _ref1, _results;
|
68
|
+
console.log("++++++++++++++++++++++"+opts.index, p1, info);
|
69
|
+
pos_to_number(p1);
|
70
|
+
tc = 1 * info.touchCount;
|
71
|
+
for (num = _i = 0, _ref = tc - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; num = 0 <= _ref ? ++_i : --_i) {
|
72
|
+
o = {
|
73
|
+
x: (context.lineWidth + 2) * (num - (tc - 1) / 2),
|
74
|
+
y: 0
|
75
|
+
};
|
76
|
+
draw_arc({
|
77
|
+
x: (p1.x * ir + o.x) / ir,
|
78
|
+
y: (p1.y * ir + o.y) / ir
|
79
|
+
}, {
|
80
|
+
r: 0.1
|
81
|
+
});
|
82
|
+
}
|
83
|
+
_results = [];
|
84
|
+
for (num = _j = 0, _ref1 = 1 * info.tapCount - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; num = 0 <= _ref1 ? ++_j : --_j) {
|
85
|
+
_results.push(draw_arc(p1, {
|
86
|
+
r: (arc_radius * ir + (1 + context.lineWidth) * num) / ir
|
87
|
+
}));
|
88
|
+
}
|
89
|
+
return _results;
|
90
|
+
};
|
91
|
+
that.pinchCloseFromToForDuration = function(p1, p2, info) {
|
92
|
+
var center, p, _i, _len, _ref;
|
93
|
+
_ref = [p1, p2];
|
94
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
95
|
+
p = _ref[_i];
|
96
|
+
pos_to_number(p);
|
97
|
+
}
|
98
|
+
draw_arc(p1);
|
99
|
+
draw_arc(p2);
|
100
|
+
center = {
|
101
|
+
x: (p1.x + p2.x) / 2,
|
102
|
+
y: (p1.y + p2.y) / 2
|
103
|
+
};
|
104
|
+
draw_arrow(p1, center);
|
105
|
+
return draw_arrow(p2, center);
|
106
|
+
};
|
107
|
+
that.pinchOpenFromToForDuration = function(p1, p2, info) {
|
108
|
+
var center, p, _i, _len, _ref;
|
109
|
+
_ref = [p1, p2];
|
110
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
111
|
+
p = _ref[_i];
|
112
|
+
pos_to_number(p);
|
113
|
+
}
|
114
|
+
draw_arc(p1);
|
115
|
+
draw_arc(p2);
|
116
|
+
center = {
|
117
|
+
x: (p1.x + p2.x) / 2,
|
118
|
+
y: (p1.y + p2.y) / 2
|
119
|
+
};
|
120
|
+
draw_arrow(center, p1);
|
121
|
+
return draw_arrow(center, p2);
|
122
|
+
};
|
123
|
+
that.dragFromToForDuration = function(p1, p2, info) {
|
124
|
+
var p, _i, _len, _ref;
|
125
|
+
_ref = [p1, p2];
|
126
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
127
|
+
p = _ref[_i];
|
128
|
+
pos_to_number(p);
|
129
|
+
}
|
130
|
+
console.log(opts.index, p1, p2, info);
|
131
|
+
draw_arc(p1);
|
132
|
+
draw_arc(p2);
|
133
|
+
return draw_arrow(p1, p2);
|
134
|
+
};
|
135
|
+
that.flickFromTo = function(p1, p2, info) {
|
136
|
+
var p, _i, _len, _ref;
|
137
|
+
_ref = [p1, p2];
|
138
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
139
|
+
p = _ref[_i];
|
140
|
+
pos_to_number(p);
|
141
|
+
}
|
142
|
+
console.log(opts.index, p1, p2, info);
|
143
|
+
draw_arc(p1);
|
144
|
+
return draw_arrow(p1, p2);
|
145
|
+
};
|
146
|
+
that.lockForDuration = function(duration) {
|
147
|
+
return draw_text("Lock Screen " + (Math.floor(duration * 100) / 100) + " Secs.");
|
148
|
+
};
|
149
|
+
that.deactivateAppForDuration = function(duration) {
|
150
|
+
return draw_text("Deactivate " + (Math.floor(duration * 100) / 100) + " Secs.");
|
151
|
+
};
|
152
|
+
that.setDeviceOrientation = function(orientation) {
|
153
|
+
return draw_text("Orientation to " + (orientation_name(orientation)));
|
154
|
+
};
|
155
|
+
that.shake = function() {
|
156
|
+
return draw_text("Shake!");
|
157
|
+
};
|
158
|
+
that.clickVolumeUp = function() {
|
159
|
+
return draw_text("clickVolumeUp!");
|
160
|
+
};
|
161
|
+
that.clickVolumeDown = function() {
|
162
|
+
return draw_text("clickVolumeDown!");
|
163
|
+
};
|
164
|
+
draw_text = function(text, opts) {
|
165
|
+
if (opts == null) {
|
166
|
+
opts = {};
|
167
|
+
}
|
168
|
+
context.font = "10px '微软雅黑'";
|
169
|
+
context.lineWidth = 1;
|
170
|
+
context.strokeStyle = "green";
|
171
|
+
context.beginPath();
|
172
|
+
context.fillRect(canvas.width * 0.1, 20, canvas.width * 0.8, 40);
|
173
|
+
context.stroke();
|
174
|
+
return context.strokeText(text, canvas.width * 0.13, 42);
|
175
|
+
};
|
176
|
+
orientation_name = function(orientation) {
|
177
|
+
switch (1 * orientation) {
|
178
|
+
case 0:
|
179
|
+
return "UNKNOWN";
|
180
|
+
case 1:
|
181
|
+
return "PORTRAIT";
|
182
|
+
case 2:
|
183
|
+
return "PORTRAIT_UPSIDEDOWN";
|
184
|
+
case 3:
|
185
|
+
return "LANDSCAPELEFT";
|
186
|
+
case 4:
|
187
|
+
return "LANDSCAPERIGHT";
|
188
|
+
case 5:
|
189
|
+
return "FACEUP";
|
190
|
+
case 6:
|
191
|
+
return "FACEDOWN";
|
192
|
+
default:
|
193
|
+
return "UNDEF";
|
194
|
+
}
|
195
|
+
};
|
196
|
+
pos_to_number = function(p) {
|
197
|
+
p.x = 1 * p.x;
|
198
|
+
p.y = 1 * p.y;
|
199
|
+
return p;
|
200
|
+
};
|
201
|
+
draw_arc = function(p, opts) {
|
202
|
+
var radius;
|
203
|
+
if (opts == null) {
|
204
|
+
opts = {};
|
205
|
+
}
|
206
|
+
radius = opts.r || arc_radius;
|
207
|
+
context.beginPath();
|
208
|
+
context.arc(p.x * ir, p.y * ir, radius * ir, 0, Math.PI * 2);
|
209
|
+
return context.stroke();
|
210
|
+
};
|
211
|
+
draw_arrow = function(p1, p2, opts) {
|
212
|
+
var lp, mp, rp, ux, uy, v, vx, vy;
|
213
|
+
if (opts == null) {
|
214
|
+
opts = {};
|
215
|
+
}
|
216
|
+
vx = p2.x - p1.x;
|
217
|
+
vy = p2.y - p1.y;
|
218
|
+
v = Math.sqrt(vx * vx + vy * vy);
|
219
|
+
ux = vx / v;
|
220
|
+
uy = vy / v;
|
221
|
+
opts.w || (opts.w = 8);
|
222
|
+
opts.h || (opts.h = 12);
|
223
|
+
opts.h2 || (opts.h2 = 5);
|
224
|
+
lp = {
|
225
|
+
x: p2.x - uy * opts.w - ux * opts.h,
|
226
|
+
y: p2.y + ux * opts.w - uy * opts.h
|
227
|
+
};
|
228
|
+
rp = {
|
229
|
+
x: p2.x + uy * opts.w - ux * opts.h,
|
230
|
+
y: p2.y - ux * opts.w - uy * opts.h
|
231
|
+
};
|
232
|
+
mp = {
|
233
|
+
x: p2.x - ux * opts.h2,
|
234
|
+
y: p2.y - uy * opts.h2
|
235
|
+
};
|
236
|
+
context.beginPath();
|
237
|
+
context.moveTo(p1.x * ir, p1.y * ir);
|
238
|
+
context.lineTo(mp.x * ir, mp.y * ir);
|
239
|
+
context.lineTo(lp.x * ir, lp.y * ir);
|
240
|
+
context.lineTo(p2.x * ir, p2.y * ir);
|
241
|
+
context.lineTo(rp.x * ir, rp.y * ir);
|
242
|
+
context.lineTo(mp.x * ir, mp.y * ir);
|
243
|
+
return context.stroke();
|
244
|
+
};
|
245
|
+
return that;
|
246
|
+
};
|
247
|
+
|
248
|
+
window.MonkeyResult = MonkeyResult;
|
249
|
+
|
250
|
+
}).call(this);
|