bauxite 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,174 @@
1
+ #--
2
+ # Copyright (c) 2014 Patricio Zavolinsky
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+ #++
22
+
23
+ # Echo logger.
24
+ #
25
+ # This logger outputs the raw action text for every action executed.
26
+ #
27
+ # Note that this logger does not include execution status information
28
+ # (i.e. action succeeded, failed or was skipped).
29
+ #
30
+ class Bauxite::Loggers::HtmlLogger < Bauxite::Loggers::NullLogger
31
+
32
+ # Constructs a new null logger instance.
33
+ #
34
+ def initialize(options)
35
+ super(options)
36
+ @data = []
37
+ @file = options[:html] || 'test.html'
38
+ end
39
+
40
+ # Logs the specified string.
41
+ #
42
+ # +type+, if specified, should be one of +:error+, +:warning+,
43
+ # +:info+ (default), +:debug+.
44
+ #
45
+ def log(s, type = :info)
46
+ end
47
+
48
+ # Echoes the raw action text.
49
+ def log_cmd(action)
50
+ ret = yield
51
+ ensure
52
+ status = case ret; when nil; :error; when false; :skip; else :ok; end
53
+
54
+ test_name = action.ctx.variables['__TEST__'] || 'Main'
55
+ test = @data.find { |t| t[:name] == test_name }
56
+ unless test
57
+ test = { :name => test_name, :actions => [] }
58
+ @data << test
59
+ end
60
+
61
+ capture = action.ctx.variables['__CAPTURE__']
62
+ if capture == @last_capture
63
+ capture = nil
64
+ else
65
+ @last_capture = capture
66
+ end
67
+
68
+ test[:actions] << {
69
+ :cmd => action.cmd,
70
+ :args => action.args(true),
71
+ :action => action,
72
+ :status => status,
73
+ :capture => capture
74
+ }
75
+
76
+ ret
77
+ end
78
+
79
+ # Completes the log execution.
80
+ #
81
+ def finalize(ctx)
82
+ output = ctx.variables['__OUTPUT__'] || ''
83
+
84
+ html = "<!DOCTYPE html>
85
+ <html>
86
+ <head>
87
+ <style type='text/css'>
88
+ body { font: 10pt sans-serif; }
89
+ .action div { display: inline-block; }
90
+ .cmd { width: 100px }
91
+ .status { width: 100px; float: right; text-align: center; font-weight: bold }
92
+ .test { background-color: #DFDFFF; margin-top: 20px }
93
+ .ok .status { background-color: #DFFFDF }
94
+ .error .status { background-color: #FFDFDF }
95
+ .skip .status { background-color: #FFDFFF }
96
+ .capture { border: 1px solid black }
97
+ .capture img { max-width: 100% }
98
+ .odd { background-color: #EEEEEE }
99
+ .summary th { background-color: #DFDFFF; text-align: left }
100
+ .summary td { cursor: pointer; }
101
+
102
+ </style>
103
+ <script type='text/javascript'>
104
+ function show(target) {
105
+ var e = document.getElementById(target+'_content');
106
+ window.location.href = '#'+target;
107
+ }
108
+ </script>
109
+ </head>
110
+ <body>"
111
+
112
+ if ctx.tests.any?
113
+ html << _d(2, "<h1>Test Summary</h1>")
114
+ html << _d(2, "<table class='summary'>")
115
+ html << _d(3, "<tr><th>Name</th><th>Time</th><th>Status</th><th>Error</th></tr>")
116
+
117
+ ctx.tests.each_with_index do |t,idx|
118
+ error = t[:error]
119
+ error = error ? error.message : ''
120
+ html << _d(3, "<tr class='#{t[:status].downcase} #{(idx % 2) == 1 ? 'odd' : 'even'}' onclick='show(\"#{t[:name]}\")'>")
121
+ html << _d(4, "<td>#{t[:name]}</td><td>#{t[:time].round(2)}</td><td class='status'>#{t[:status]}</td><td>#{error}</td>")
122
+ html << _d(3, "</tr>")
123
+ end
124
+
125
+ html << _d(2, "</table>")
126
+ end
127
+
128
+ html << _d(2, "<h1>Test Details</h1>")
129
+ @data.each do |test|
130
+ name = test[:name]
131
+ status = test[:actions].find { |a| a[:status] == :error } ? :error : :ok
132
+ html << _d(2, "<a name='#{name}'></a>")
133
+ html << _d(2, "<div class='test #{status}'>#{name}<div class='status'>#{status.upcase}</div></div>")
134
+ html << _d(2, "<div id='#{name}_content' class='test-content'>")
135
+
136
+ test[:actions].each_with_index do |action,idx|
137
+ html << _d(3, "<div class='action #{action[:status]} #{(idx % 2) == 1 ? 'odd' : 'even'}'>")
138
+ html << _d(4, "<div class='cmd'>#{action[:cmd]}</div>")
139
+ html << _d(4, "<div class='args'>#{action[:args].join(' ')}</div>")
140
+ html << _d(4, "<div class='status'>#{action[:status].upcase}</div>")
141
+ html << _d(3, "</div>")
142
+ capture = action[:capture]
143
+ if capture
144
+ html << _d(3, "<div class='capture'>#{_img(output, capture)}</div>")
145
+ end
146
+ end
147
+
148
+ item = ctx.tests.find { |t| t[:name] == name }
149
+ if item and item[:error]
150
+ capture = item[:error].variables['__CAPTURE__']
151
+ if capture
152
+ html << _d(3, "<div class='capture'>#{_img(output, capture)}</div>")
153
+ end
154
+ end
155
+
156
+ html << _d(2, "</div>")
157
+ end
158
+ html << "
159
+ </body>
160
+ </html>"
161
+ file = @file
162
+ file = File.join(output, file) if output != ''
163
+ File.open(file, 'w') { |f| f.write html }
164
+ end
165
+
166
+ private
167
+ def _d(depth, s)
168
+ "\n"+depth.times.inject('') { |s,i| s + "\t" } + s
169
+ end
170
+ def _img(output, path)
171
+ path = path[output.size+1..-1] unless output == ''
172
+ "<img src='#{path}'/>"
173
+ end
174
+ end
data/lib/bauxite.rb CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  #--
24
24
  module Bauxite
25
- VERSION = "0.6.1"
25
+ VERSION = "0.6.2"
26
26
  end
27
27
  #++
28
28
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bauxite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Zavolinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -65,6 +65,7 @@ files:
65
65
  - doc/Bauxite/Loggers/CompositeLogger.html
66
66
  - doc/Bauxite/Loggers/EchoLogger.html
67
67
  - doc/Bauxite/Loggers/FileLogger.html
68
+ - doc/Bauxite/Loggers/HtmlLogger.html
68
69
  - doc/Bauxite/Loggers/NullLogger.html
69
70
  - doc/Bauxite/Loggers/TerminalLogger.html
70
71
  - doc/Bauxite/Loggers/XtermLogger.html
@@ -155,6 +156,7 @@ files:
155
156
  - lib/bauxite/loggers/composite.rb
156
157
  - lib/bauxite/loggers/echo.rb
157
158
  - lib/bauxite/loggers/file.rb
159
+ - lib/bauxite/loggers/html.rb
158
160
  - lib/bauxite/loggers/terminal.rb
159
161
  - lib/bauxite/loggers/xterm.rb
160
162
  - lib/bauxite/parsers/csv.rb