report_builder 1.5 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e040f4e0aab45099f7c665d0ff4ccf69f49f348
4
- data.tar.gz: 95c2949aa0d294f0dbfe677243d0386f90d9414a
3
+ metadata.gz: 5c203c35fcd9bfc7ed493b7df0b572bb3a37f68d
4
+ data.tar.gz: f80022db0429e1e153ca2ac615cde80430c6170c
5
5
  SHA512:
6
- metadata.gz: 2ac1cbd9679f7fb626c54a1932e8882d862cc0dddf2300a2ae87ae72b128a929a5e90122dc17ae774ca9d0bb848231d95b064ddfca6b4c0a43a5f59276a52073
7
- data.tar.gz: b0e8ecb77d1d4af4608a1a26f2f0cf2fc42f3b2afee74929385ce372708631425b060551a88f3dc9b42f659bc3086d9feb3976be7fee2aeb13bbb933fa35e5c2
6
+ metadata.gz: e709a3f18543fcccc29d318d598dcf73edd81d08366a3d068fa102cc2b61821514d7e0ca8474b934d6c4f141a8b7df931d95fc4c839934bddee1b2b58c4b3ef8
7
+ data.tar.gz: 46158e9e9a8226ff37751f15e417977ec92e17ba2f90db7962cf3bc3a000969c56893bcc5c45cda2a22bfaa1b7777dde9495dac0c0a1abe831b0d0af48ce5752
@@ -3,9 +3,16 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
 
6
- ## [Unreleased](https://github.com/rajatthareja/ReportBuilder/compare/v1.5...master)
6
+ ## [Unreleased](https://github.com/rajatthareja/ReportBuilder/compare/v1.6...master)
7
7
 
8
- ## [1.5](https://github.com/rajatthareja/ReportBuilder/compare/v1.4...v1.5) - 2017-03-03
8
+
9
+ ## [1.6](https://github.com/rajatthareja/ReportBuilder/compare/v1.5...v1.6) - 2018-03-29
10
+ ### Changed
11
+ - Removed duplicate flaky scenarios
12
+ ### Added
13
+ - Configuration Options Setter and Getter
14
+
15
+ ## [1.5](https://github.com/rajatthareja/ReportBuilder/compare/v1.4...v1.5) - 2018-03-03
9
16
  ### Added
10
17
  - Voice Commands
11
18
  - Tabs name
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ReportBuilder
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/report_builder.svg)](https://badge.fury.io/rb/report_builder)
3
+ [![Gem Version](https://img.shields.io/gem/v/report_builder.svg)](https://badge.fury.io/rb/report_builder)
4
4
  [![Build status](https://travis-ci.org/rajatthareja/ReportBuilder.svg?branch=master)](https://travis-ci.org/rajatthareja/ReportBuilder)
5
5
  [![Windows Build status](https://ci.appveyor.com/api/projects/status/s5jx2ji3wdg294u6/branch/master?svg=true)](https://ci.appveyor.com/project/rajatthareja/reportbuilder)
6
6
  [![Join the chat at https://gitter.im/rajatthareja/ReportBuilder](https://badges.gitter.im/rajatthareja/ReportBuilder.svg)](https://gitter.im/rajatthareja/ReportBuilder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -56,27 +56,48 @@ gem install report_builder
56
56
 
57
57
  # Ex 1:
58
58
  ReportBuilder.configure do |config|
59
- config.json_path = 'cucumber_sample/logs'
59
+ config.input_path = 'results/cucumber_json'
60
60
  config.report_path = 'my_test_report'
61
- config.report_types = [:json, :html]
61
+ config.report_types = [:retry, :html]
62
62
  config.report_title = 'My Test Results'
63
- config.include_images = false
64
63
  config.additional_info = {browser: 'Chrome', environment: 'Stage 5'}
65
64
  end
66
65
 
67
66
  ReportBuilder.build_report
68
67
 
69
68
  # Ex 2:
69
+ ReportBuilder.input_path = 'results/cucumber_json'
70
+ ReportBuilder.report_path = 'my_test_report'
71
+ ReportBuilder.report_types = [:retry, :html]
72
+ ReportBuilder.report_title = 'My Test Results'
73
+ ReportBuilder.additional_info = {Browser: 'Chrome', Environment: 'Stage 5'}
74
+
75
+ ReportBuilder.build_report
76
+
77
+ # Ex 3:
70
78
  options = {
71
- json_path: 'cucumber_sample/logs',
72
- report_path: 'my_test_report',
73
- report_types: ['json', 'html'],
79
+ input_path: 'results/cucumber_json',
80
+ report_path: 'my_test_report',
81
+ report_types: ['retry', 'html'],
74
82
  report_title: 'My Test Results',
75
- include_images: false,
76
- additional_info: {'browser' => 'Chrome', 'environment' => 'Stage 5'}
83
+ additional_info: {'Browser' => 'Chrome', 'Environment' => 'Stage 5'}
77
84
  }
78
85
 
79
86
  ReportBuilder.build_report options
87
+
88
+ # Ex 4:
89
+ ReportBuilder.input_path = 'results/cucumber_json'
90
+
91
+ ReportBuilder.configure do |config|
92
+ config.report_path = 'my_test_report'
93
+ config.report_types = [:json, :html]
94
+ end
95
+
96
+ options = {
97
+ report_title: 'My Test Results'
98
+ }
99
+
100
+ ReportBuilder.build_report options
80
101
 
81
102
  ```
82
103
 
@@ -85,7 +106,7 @@ gem install report_builder
85
106
  ```ruby
86
107
 
87
108
  ReportBuilder.configure do |config|
88
- config.json_path = {
109
+ config.input_path = {
89
110
  'Group A' => ['path/of/json/files/dir1', 'path/of/json/files/dir2'],
90
111
  'Group B' => ['path/of/json/file1', 'path/of/json/file2'],
91
112
  'Group C' => 'path/of/json/files/dir'}
@@ -126,30 +147,19 @@ ReportBuilder.build_report
126
147
 
127
148
  ```
128
149
 
129
- ### Rake Example:
130
-
131
- Add in Rakefile
150
+ ### Hook Example:
132
151
 
133
152
  ```ruby
134
153
 
135
- require 'report_builder'
154
+ require 'report_builder'
136
155
 
137
- desc 'Sample rake task to build report'
138
- task :report_builder, [:json_path, :report_path] do |t, args|
139
- args.with_defaults(:json_path => nil, :report_path => 'test_report')
140
- options = {:json_path => args.json_path, :report_path => args.report_path}
141
- ReportBuilder.build_report options
142
- end
143
-
144
- ```
145
-
146
- Then run rake task report_builder
147
-
148
- ```bash
149
-
150
- rake report_builder
151
- rake report_builder['path/of/json/files/dir']
152
- rake report_builder['path/of/json/files/dir','report_file']
156
+ at_exit do
157
+ ReportBuilder.configure do |config|
158
+ config.input_path = 'results/cucumber_json'
159
+ config.report_path = 'results/report'
160
+ end
161
+ ReportBuilder.build_report
162
+ end
153
163
 
154
164
  ```
155
165
 
@@ -158,6 +168,9 @@ Use voice commands for easy navigation and search
158
168
  * show ( overview | features | summary | errors )
159
169
  * search { Keywords }
160
170
 
171
+ ## Report Builder Java API
172
+ [Report Builder Java](http://reportbuilderjava.rajatthareja.com)
173
+
161
174
  ## Contributing
162
175
 
163
176
  We're open to any contribution. It has to be tested properly though.
@@ -3,23 +3,14 @@
3
3
  require 'optparse'
4
4
  require 'report_builder'
5
5
 
6
- options = {
7
- :json_path => nil,
8
- :report_path => 'test_report',
9
- :report_types => [:html],
10
- :report_title => 'Test Results',
11
- :include_images => true,
12
- :voice_commands => false,
13
- :color => 'brown',
14
- :additional_info => {}
15
- }
6
+ options = { }
16
7
 
17
8
  opt_parser = OptionParser.new do |opts|
18
9
  opts.banner = "Usage: \n report_builder [options]"
19
10
  opts.separator 'Configuration options:'
20
11
 
21
12
  opts.on('-s', '--source x,y,z', Array, 'List of json path or files') do |list|
22
- options[:json_path] = list
13
+ options[:input_path] = list
23
14
  end
24
15
 
25
16
  opts.on('-o', '--out [PATH]NAME', String, 'Report path with name without extension') do |report_path|
@@ -4,15 +4,32 @@ require_relative 'report_builder/builder'
4
4
  # ReportBuilder Main module
5
5
  #
6
6
  module ReportBuilder
7
+
8
+ ##
9
+ # ReportBuilder options
10
+ #
11
+ def self.options
12
+ @options ||= {
13
+ input_path: Dir.pwd,
14
+ report_types: [:html],
15
+ report_title: 'Test Results',
16
+ include_images: true,
17
+ voice_commands: false,
18
+ additional_info: {},
19
+ report_path: 'test_report',
20
+ color: 'brown'
21
+ }
22
+ end
23
+
7
24
  ##
8
25
  # Configure ReportBuilder
9
26
  #
10
27
  # Example:
11
28
  #
12
29
  # ReportBuilder.configure do |config|
13
- # config.json_path = 'cucumber_sample/logs'
30
+ # config.input_path = 'cucumber_sample/logs'
14
31
  # config.report_path = 'my_test_report'
15
- # config.report_types = [:JSON, :HTML]
32
+ # config.report_types = [:RETRY, :HTML]
16
33
  # config.report_title = 'My Test Results'
17
34
  # config.include_images = true
18
35
  # config.voice_commands = true
@@ -20,37 +37,23 @@ module ReportBuilder
20
37
  # end
21
38
  #
22
39
  def self.configure
23
- defaults = builder.default_options
24
- yield defaults if block_given?
25
- builder.options = defaults.marshal_dump
26
- end
27
-
28
- ##
29
- # Set single option
30
- #
31
- # @param [String] option
32
- # @param [Object] value
33
- #
34
- # Example:
35
- #
36
- # ReportBuilder.set_option('include_images', false)
37
- #
38
- def self.set_option(option, value)
39
- builder.options ||= builder.default_options.marshal_dump
40
- builder.options[option] = value
40
+ options
41
+ more_options = OpenStruct.new
42
+ yield more_options if block_given?
43
+ @options.merge! more_options.marshal_dump
41
44
  end
42
45
 
43
46
  ##
44
47
  # Build Report
45
48
  #
46
- # @param [Hash] options override the default and configured options.
49
+ # @param [Hash] more_options override the default and configured options.
47
50
  #
48
51
  # Example:
49
52
  #
50
53
  # options = {
51
54
  # json_path: 'cucumber_sample/logs',
52
55
  # report_path: 'my_test_report',
53
- # report_types: ['json', 'html'],
56
+ # report_types: ['retry', 'html'],
54
57
  # report_title: 'My Test Results',
55
58
  # include_images: true,
56
59
  # voice_commands: true,
@@ -60,11 +63,367 @@ module ReportBuilder
60
63
  #
61
64
  # ReportBuilder.build_report options
62
65
  #
63
- def self.build_report(options = nil)
64
- builder.build_report(options)
66
+ def self.build_report(more_options = {})
67
+ options
68
+ if more_options.is_a? String
69
+ @options[:input_path] = more_options
70
+ elsif more_options.is_a? Hash
71
+ @options.merge! more_options
72
+ end
73
+ @options[:input_path] = @options[:json_path] if @options[:json_path]
74
+ @options[:report_types] = [@options[:report_types]] unless @options[:report_types].is_a? Array
75
+ @options[:report_types].map!(&:to_s).map!(&:upcase)
76
+ Builder.new.build_report
77
+ end
78
+
79
+ ##
80
+ # Set Report Builder input json files path / array of json files or path / hash of json files or path
81
+ #
82
+ # @param [String/Array/Hash] json_path input json files path / array of json files or path / hash of json files or path
83
+ #
84
+ # Example:
85
+ #
86
+ # ReportBuilder.json_path = 'my_project/cucumber_json'
87
+ #
88
+ def self.json_path=(json_path)
89
+ options
90
+ @options[:input_path] = json_path
91
+ end
92
+
93
+ ##
94
+ # Returns Report Builder input json files path / array of json files or path / hash of json files or path
95
+ #
96
+ # @return [String/Array/Hash] json_path input json files path / array of json files or path / hash of json files or path
97
+ #
98
+ def self.json_path
99
+ options[:input_path]
100
+ end
101
+
102
+ ##
103
+ # Set Report Builder input json files path / array of json files or path / hash of json files or path
104
+ #
105
+ # @param [String/Array/Hash] input_path input json files path / array of json files or path / hash of json files or path
106
+ #
107
+ # Example:
108
+ #
109
+ # ReportBuilder.input_path = 'my_project/cucumber_json'
110
+ #
111
+ def self.input_path=(input_path)
112
+ options
113
+ @options[:input_path] = input_path
114
+ end
115
+
116
+ ##
117
+ # Returns Report Builder input json files path / array of json files or path / hash of json files or path
118
+ #
119
+ # @return [String/Array/Hash] input_path input json files path / array of json files or path / hash of json files or path
120
+ #
121
+ def self.input_path
122
+ options[:input_path]
123
+ end
124
+
125
+ ##
126
+ # Set Report Builder report_types :json, :html, :retry (output file types)
127
+ #
128
+ # @param [Array] report_types :json, :html, :retry (output file types)
129
+ #
130
+ # Example:
131
+ #
132
+ # ReportBuilder.report_types = [:html, :retry]
133
+ #
134
+ def self.report_types=(report_types)
135
+ options
136
+ @options[:report_types] = report_types.is_a? Array ? report_types : [report_types]
137
+ end
138
+
139
+ ##
140
+ # Returns Report Builder report_types :json, :html, :retry (output file types)
141
+ #
142
+ # @return [Array] report_types :json, :html, :retry (output file types)
143
+ #
144
+ def self.report_types
145
+ options[:report_types]
146
+ end
147
+
148
+ ##
149
+ # Set Report Builder HTML report title
150
+ #
151
+ # @param [String] report_title HTML report title
152
+ #
153
+ # Example:
154
+ #
155
+ # ReportBuilder.report_title = 'My Report'
156
+ #
157
+ def self.report_title=(report_title)
158
+ options
159
+ @options[:report_title] = report_title if report_title.is_a? String
160
+ end
161
+
162
+ ##
163
+ # Returns Report Builder HTML report title
164
+ #
165
+ # @return [String] report_title HTML report title
166
+ #
167
+ def self.report_title
168
+ options[:report_title]
169
+ end
170
+
171
+ ##
172
+ # Set Report Builder include or excluding embedded images
173
+ #
174
+ # @param [Boolean] include_images include or excluding embedded images
175
+ #
176
+ # Example:
177
+ #
178
+ # ReportBuilder.include_images = false
179
+ #
180
+ def self.include_images=(include_images)
181
+ options
182
+ @options[:include_images] = include_images if !!include_images == include_images
183
+ end
184
+
185
+ ##
186
+ # Returns Report Builder include or excluding embedded images
187
+ #
188
+ # @return [Boolean] include_images include or excluding embedded images
189
+ #
190
+ def self.include_images
191
+ options[:include_images]
192
+ end
193
+
194
+ ##
195
+ # Set Report Builder enable or disable voice commands
196
+ #
197
+ # @param [Boolean] voice_commands enable or disable voice commands
198
+ #
199
+ # Example:
200
+ #
201
+ # ReportBuilder.voice_commands = true
202
+ #
203
+ def self.voice_commands=(voice_commands)
204
+ options
205
+ @options[:voice_commands] = voice_commands if !!voice_commands == voice_commands
206
+ end
207
+
208
+ ##
209
+ # Returns Report Builder enable or disable voice commands
210
+ #
211
+ # @return [Boolean] voice_commands enable or disable voice commands
212
+ #
213
+ def self.voice_commands
214
+ options[:voice_commands]
215
+ end
216
+
217
+ ##
218
+ # Set Report Builder additional info for report summary
219
+ #
220
+ # @param [Hash] additional_info additional info for report summary
221
+ #
222
+ # Example:
223
+ #
224
+ # ReportBuilder.additional_info = {'Environment' => 'Abc Environment', 'Browser' => 'Chrome'}
225
+ #
226
+ def self.additional_info=(additional_info)
227
+ options
228
+ @options[:additional_info] = additional_info if additional_info.is_a? Hash
229
+ end
230
+
231
+ ##
232
+ # Returns Report Builder additional info for report summary
233
+ #
234
+ # @return [Hash] additional_info additional info for report summary
235
+ #
236
+ def self.additional_info
237
+ options[:additional_info]
238
+ end
239
+
240
+ ##
241
+ # Set Report Builder reports output file path with file name without extension
242
+ #
243
+ # @param [String] report_path reports output file path with file name without extension
244
+ #
245
+ # Example:
246
+ #
247
+ # ReportBuilder.report_path = 'reports/report'
248
+ #
249
+ def self.report_path=(report_path)
250
+ options
251
+ options[:report_path] = report_path if report_path.is_a? String
252
+ end
253
+
254
+ ##
255
+ # Returns Report Builder reports output file path with file name without extension
256
+ #
257
+ # @return [String] report_path reports output file path with file name without extension
258
+ #
259
+ def self.report_path
260
+ options[:report_path]
261
+ end
262
+
263
+ ##
264
+ # Set Report Builder json report output file path with file name without extension
265
+ #
266
+ # @param [String] json_report_path json report output file path with file name without extension
267
+ #
268
+ # Example:
269
+ #
270
+ # ReportBuilder.json_report_path = 'reports/report'
271
+ #
272
+ def self.json_report_path=(json_report_path)
273
+ options
274
+ @options[:json_report_path] = json_report_path if json_report_path.is_a? String
275
+ end
276
+
277
+ ##
278
+ # Returns Report Builder json report output file path with file name without extension
279
+ #
280
+ # @return [String] json_report_path json report output file path with file name without extension
281
+ #
282
+ def self.json_report_path
283
+ options[:json_report_path] || options[:report_path]
284
+ end
285
+
286
+ ##
287
+ # Set Report Builder html report output file path with file name without extension
288
+ #
289
+ # @param [String] html_report_path html report output file path with file name without extension
290
+ #
291
+ # Example:
292
+ #
293
+ # ReportBuilder.html_report_path = 'reports/report'
294
+ #
295
+ def self.html_report_path=(html_report_path)
296
+ options
297
+ @options[:html_report_path] = html_report_path if html_report_path.is_a? String
298
+ end
299
+
300
+ ##
301
+ # Returns Report Builder html report output file path with file name without extension
302
+ #
303
+ # @return [String] html_report_path html report output file path with file name without extension
304
+ #
305
+ def self.html_report_path
306
+ options[:html_report_path] || options[:report_path]
65
307
  end
66
308
 
67
- def self.builder
68
- @builder ||= Builder.new
309
+ ##
310
+ # Set Report Builder retry report output file path with file name without extension
311
+ #
312
+ # @param [String] retry_report_path retry report output file path with file name without extension
313
+ #
314
+ # Example:
315
+ #
316
+ # ReportBuilder.retry_report_path = 'reports/report'
317
+ #
318
+ def self.retry_report_path=(retry_report_path)
319
+ options
320
+ @options[:retry_report_path] = retry_report_path if retry_report_path.is_a? String
321
+ end
322
+
323
+ ##
324
+ # Returns Report Builder retry report output file path with file name without extension
325
+ #
326
+ # @return [String] retry_report_path retry report output file path with file name without extension
327
+ #
328
+ def self.retry_report_path
329
+ options[:retry_report_path] || options[:report_path]
330
+ end
331
+
332
+ ##
333
+ # Set Report Builder additional CSS string or CSS file path or CSS file url for customizing html report
334
+ #
335
+ # @param [String] additional_css additional CSS string or CSS file path or CSS file url for customizing html report
336
+ #
337
+ # Example:
338
+ #
339
+ # ReportBuilder.additional_css = 'css/style.css'
340
+ #
341
+ def self.additional_css=(additional_css)
342
+ options
343
+ @options[:additional_css] = additional_css if additional_css.is_a? String
344
+ end
345
+
346
+ ##
347
+ # Returns Report Builder additional CSS string or CSS file path or CSS file url for customizing html report
348
+ #
349
+ # @return [String] additional_css additional CSS string or CSS file path or CSS file url for customizing html report
350
+ #
351
+ def self.additional_css
352
+ options[:additional_css]
353
+ end
354
+
355
+ ##
356
+ # Set Report Builder additional JS string or JS file path or JS file url for customizing html report
357
+ #
358
+ # @param [String] additional_js additional JS string or JS file path or JS file url for customizing html report
359
+ #
360
+ # Example:
361
+ #
362
+ # ReportBuilder.json_report_path = 'js/script.js'
363
+ #
364
+ def self.additional_js=(additional_js)
365
+ options
366
+ @options[:additional_js=] = additional_js if additional_js.is_a? String
367
+ end
368
+
369
+ ##
370
+ # Returns Report Builder additional JS string or JS file path or JS file url for customizing html report
371
+ #
372
+ # @return [String] additional_js additional JS string or JS file path or JS file url for customizing html report
373
+ #
374
+ def self.additional_js
375
+ options[:additional_js]
376
+ end
377
+
378
+ ##
379
+ # Set Report Builder report color, Ex: indigo, cyan, purple, grey, lime etc.
380
+ #
381
+ # @param [String] color report color, Ex: indigo, cyan, purple, grey, lime etc.
382
+ #
383
+ # Example:
384
+ #
385
+ # ReportBuilder.color = 'cucumber_sample/logs'
386
+ #
387
+ def self.color=(color)
388
+ options
389
+ @options[:color] = color if color.is_a? String
390
+ end
391
+
392
+ ##
393
+ # Returns Report Builder report color, Ex: indigo, cyan, purple, grey, lime etc.
394
+ #
395
+ # @return [String] color report color, Ex: indigo, cyan, purple, grey, lime etc.
396
+ #
397
+ def self.color
398
+ options[:color]
399
+ end
400
+
401
+ ##
402
+ # Set Report Builder Options
403
+ #
404
+ # @param [String] option
405
+ # @param [String] value
406
+ #
407
+ # Example:
408
+ #
409
+ # ReportBuilder.set('title', 'My Features')
410
+ #
411
+ def self.set_option(option, value)
412
+ options
413
+ @options[option.to_sym] = value
414
+ end
415
+
416
+ ##
417
+ # Set Report Builder Options
418
+ #
419
+ # @param [String] option
420
+ # @param [String] value
421
+ #
422
+ # Example:
423
+ #
424
+ # ReportBuilder.set('title', 'My Features')
425
+ #
426
+ def self.set(option, value)
427
+ set_option(option, value)
69
428
  end
70
429
  end
@@ -7,30 +7,26 @@ require 'ostruct'
7
7
  require 'report_builder/core-ext/hash'
8
8
 
9
9
  module ReportBuilder
10
+
10
11
  ##
11
12
  # ReportBuilder Main class
12
13
  #
13
14
  class Builder
14
15
 
15
- attr_accessor :options
16
-
17
16
  ##
18
17
  # ReportBuilder Main method
19
18
  #
20
- def build_report(opts = nil)
21
- options = self.options || default_options.marshal_dump
22
- options.merge! opts if opts.is_a? Hash
19
+ def build_report
20
+ options = ReportBuilder.options
23
21
 
24
- fail 'Error:: Invalid report_types. Use: [:json, :html]' unless options[:report_types].is_a? Array
25
- options[:report_types].map!(&:to_s).map!(&:upcase)
26
-
27
- options[:input_path] ||= options[:json_path] || Dir.pwd
28
22
  groups = get_groups options[:input_path]
29
23
 
30
24
  json_report_path = options[:json_report_path] || options[:report_path]
31
- File.open(json_report_path + '.json', 'w') do |file|
32
- file.write JSON.pretty_generate(groups.size > 1 ? groups : groups.first['features'])
33
- end if options[:report_types].include? 'JSON'
25
+ if options[:report_types].include? 'JSON'
26
+ File.open(json_report_path + '.json', 'w') do |file|
27
+ file.write JSON.pretty_generate(groups.size > 1 ? groups : groups.first['features'])
28
+ end
29
+ end
34
30
 
35
31
  if options[:additional_css] and Pathname.new(options[:additional_css]).file?
36
32
  options[:additional_css] = File.read(options[:additional_css])
@@ -41,44 +37,29 @@ module ReportBuilder
41
37
  end
42
38
 
43
39
  html_report_path = options[:html_report_path] || options[:report_path]
44
- File.open(html_report_path + '.html', 'w') do |file|
45
- file.write get(groups.size > 1 ? 'group_report' : 'report').result(binding).gsub(' ', '').gsub("\n\n", '')
46
- end if options[:report_types].include? 'HTML'
40
+ if options[:report_types].include? 'HTML'
41
+ File.open(html_report_path + '.html', 'w') do |file|
42
+ file.write get(groups.size > 1 ? 'group_report' : 'report').result(binding).gsub(' ', '').gsub("\n\n", '')
43
+ end
44
+ end
47
45
 
48
46
  retry_report_path = options[:retry_report_path] || options[:report_path]
49
- File.open(retry_report_path + '.retry', 'w') do |file|
50
- groups.each do |group|
51
- group['features'].each do |feature|
52
- if feature['status'] == 'broken'
53
- feature['elements'].each {|scenario| file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'}
47
+ if options[:report_types].include? 'RETRY'
48
+ File.open(retry_report_path + '.retry', 'w') do |file|
49
+ groups.each do |group|
50
+ group['features'].each do |feature|
51
+ if feature['status'] == 'broken'
52
+ feature['elements'].each do |scenario|
53
+ file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'
54
+ end
55
+ end
54
56
  end
55
57
  end
56
58
  end
57
- end if options[:report_types].include? 'RETRY'
59
+ end
58
60
  [json_report_path, html_report_path, retry_report_path]
59
61
  end
60
62
 
61
- ##
62
- # ReportBuilder default configuration
63
- #
64
- def default_options
65
- OpenStruct.new(json_path: nil,
66
- input_path: nil,
67
- report_types: [:html],
68
- report_title: 'Test Results',
69
- include_images: true,
70
- voice_commands: false,
71
- additional_info: {},
72
- report_path: 'test_report',
73
- json_report_path: nil,
74
- html_report_path: nil,
75
- retry_report_path: nil,
76
- additional_css: nil,
77
- additional_js: nil,
78
- color: 'brown'
79
- )
80
- end
81
-
82
63
  private
83
64
 
84
65
  def get(template)
@@ -94,11 +75,11 @@ module ReportBuilder
94
75
  puts "Error:: No file(s) found at #{group_path}" if files.empty?
95
76
  groups << {'name' => group_name, 'features' => get_features(files)} rescue next
96
77
  end
97
- fail 'Error:: Invalid Input File(s). Please provide valid cucumber JSON output file(s)' if groups.empty?
78
+ raise 'Error:: Invalid Input File(s). Please provide valid cucumber JSON output file(s)' if groups.empty?
98
79
  else
99
80
  files = get_files input_path
100
- fail "Error:: No file(s) found at #{input_path}" if files.empty?
101
- groups << {'features' => get_features(files)} rescue fail('Error:: Invalid Input File(s). Please provide valid cucumber JSON output file(s)')
81
+ raise "Error:: No file(s) found at #{input_path}" if files.empty?
82
+ groups << {'features' => get_features(files)} rescue raise('Error:: Invalid Input File(s). Please provide valid cucumber JSON output file(s)')
102
83
  end
103
84
  groups
104
85
  end
@@ -128,63 +109,91 @@ module ReportBuilder
128
109
  end
129
110
 
130
111
  def get_features(files)
131
- files.each_with_object([]) {|file, features|
112
+ files.each_with_object([]) do |file, features|
132
113
  data = File.read(file)
133
114
  next if data.empty?
134
- features << JSON.parse(data) rescue next
135
- }.flatten.group_by {|feature|
136
- feature['uri']+feature['id']+feature['line'].to_s
137
- }.values.each_with_object([]) {|group, features|
115
+ begin
116
+ features << JSON.parse(data)
117
+ rescue StandardError
118
+ puts 'Warning:: Invalid Input File ' + file
119
+ next
120
+ end
121
+ end.flatten.group_by do |feature|
122
+ feature['uri'] + feature['id'] + feature['line'].to_s
123
+ end.values.each_with_object([]) do |group, features|
138
124
  features << group.first.except('elements').merge('elements' => group.map {|feature| feature['elements']}.flatten)
139
- }.sort_by! {|feature| feature['name']}.each {|feature|
125
+ end.sort_by! do |feature|
126
+ feature['name']
127
+ end.each do |feature|
140
128
  if feature['elements'][0]['type'] == 'background'
141
129
  (0..feature['elements'].size-1).step(2) do |i|
142
130
  feature['elements'][i]['steps'] ||= []
143
- feature['elements'][i]['steps'].each {|step| step['name']+=(' ('+feature['elements'][i]['keyword']+')')}
131
+ feature['elements'][i]['steps'].each {|step| step['name'] += (' (' + feature['elements'][i]['keyword'] + ')')}
144
132
  if feature['elements'][i+1]
145
133
  feature['elements'][i+1]['steps'] = feature['elements'][i]['steps'] + feature['elements'][i+1]['steps']
146
134
  feature['elements'][i+1]['before'] = feature['elements'][i]['before'] if feature['elements'][i]['before']
147
135
  end
148
136
  end
149
- feature['elements'].reject! {|element| element['type'] == 'background'}
137
+ feature['elements'].reject! do |element|
138
+ element['type'] == 'background'
139
+ end
150
140
  end
151
- feature['elements'].each {|scenario|
141
+ feature['elements'].each do |scenario|
152
142
  scenario['before'] ||= []
153
- scenario['before'].each {|before|
143
+ scenario['before'].each do |before|
154
144
  before['result']['duration'] ||= 0
155
145
  before.merge! 'status' => before['result']['status'], 'duration' => before['result']['duration']
156
- }
146
+ end
157
147
  scenario['steps'] ||= []
158
- scenario['steps'].each {|step|
148
+ scenario['steps'].each do |step|
159
149
  step['result']['duration'] ||= 0
160
150
  duration = step['result']['duration']
161
151
  status = step['result']['status']
162
- step['after'].each {|after|
163
- after['result']['duration'] ||= 0
164
- duration += after['result']['duration']
165
- status = 'failed' if after['result']['status'] == 'failed'
166
- after['embeddings'].map! { |embedding|
152
+ if step['after']
153
+ step['after'].each do |after|
154
+ after['result']['duration'] ||= 0
155
+ duration += after['result']['duration']
156
+ status = 'failed' if after['result']['status'] == 'failed'
157
+ if after['embeddings']
158
+ after['embeddings'].map! do |embedding|
159
+ decode_embedding(embedding)
160
+ end
161
+ end
162
+ after.merge! 'status' => after['result']['status'], 'duration' => after['result']['duration']
163
+ end
164
+ end
165
+ if step['embeddings']
166
+ step['embeddings'].map! do |embedding|
167
167
  decode_embedding(embedding)
168
- } if after['embeddings']
169
- after.merge! 'status' => after['result']['status'], 'duration' => after['result']['duration']
170
- } if step['after']
171
- step['embeddings'].map! { |embedding|
172
- decode_embedding(embedding)
173
- } if step['embeddings']
168
+ end
169
+ end
174
170
  step.merge! 'status' => status, 'duration' => duration
175
- }
171
+ end
176
172
  scenario['after'] ||= []
177
- scenario['after'].each {|after|
173
+ scenario['after'].each do |after|
178
174
  after['result']['duration'] ||= 0
179
- after['embeddings'].map! { |embedding|
180
- decode_embedding(embedding)
181
- } if after['embeddings']
175
+ if after['embeddings']
176
+ after['embeddings'].map! do |embedding|
177
+ decode_embedding(embedding)
178
+ end
179
+ end
182
180
  after.merge! 'status' => after['result']['status'], 'duration' => after['result']['duration']
183
- }
181
+ end
184
182
  scenario.merge! 'status' => scenario_status(scenario), 'duration' => total_time(scenario['before']) + total_time(scenario['steps']) + total_time(scenario['after'])
185
- }
183
+ end
184
+ feature['elements'] = feature['elements'].group_by do |scenario|
185
+ scenario['id']
186
+ end.values.map do |scenario_group|
187
+ scenario = scenario_group.find do |scenario|
188
+ scenario['status'] == 'passed'
189
+ end || scenario_group.first
190
+ if scenario_group.size > 1
191
+ scenario['name'] += " (x#{scenario_group.size})"
192
+ end
193
+ scenario
194
+ end
186
195
  feature.merge! 'status' => feature_status(feature), 'duration' => total_time(feature['elements'])
187
- }
196
+ end
188
197
  end
189
198
 
190
199
  def feature_status(feature)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'report_builder'
3
- s.version = '1.5'
3
+ s.version = '1.6'
4
4
  s.bindir = 'bin'
5
5
  s.summary = 'ReportBuilder'
6
6
  s.description = 'Ruby gem to merge Cucumber JSON reports and build mobile-friendly HTML Test Report, JSON report and retry file.'
@@ -7,7 +7,7 @@
7
7
  </div>
8
8
  </footer>
9
9
 
10
- <script type="text/javascript" src="https://cdn.rawgit.com/rajatthareja/ReportBuilder/v1.5/js/report.builder.min.js"></script>
10
+ <script type="text/javascript" src="https://cdn.rawgit.com/rajatthareja/ReportBuilder/v1.6/js/report.builder.min.js"></script>
11
11
 
12
12
  <% if options[:voice_commands] %>
13
13
  <script src="//cdnjs.cloudflare.com/ajax/libs/annyang/2.6.0/annyang.min.js"></script>
@@ -8,7 +8,7 @@
8
8
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
9
9
  <link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
10
10
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" media="screen,projection"/>
11
- <link href="https://cdn.rawgit.com/rajatthareja/ReportBuilder/v1.5/css/report.builder.min.css" rel="stylesheet">
11
+ <link href="https://cdn.rawgit.com/rajatthareja/ReportBuilder/v1.6/css/report.builder.min.css" rel="stylesheet">
12
12
 
13
13
  <% if options[:additional_css] %>
14
14
  <% if options[:additional_css] =~ /^http(|s):\/\/.*\.css$/ %>
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: report_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.5'
4
+ version: '1.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajat Thareja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-03 00:00:00.000000000 Z
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - <
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - <
38
+ - - "<"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - <
45
+ - - "<"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - <
52
+ - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.0'
55
55
  description: Ruby gem to merge Cucumber JSON reports and build mobile-friendly HTML
@@ -98,18 +98,18 @@ require_paths:
98
98
  - lib
99
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: 1.9.1
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - '>='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements:
110
110
  - Cucumber >= 2.1.0 test results in JSON format
111
111
  rubyforge_project:
112
- rubygems_version: 2.4.6
112
+ rubygems_version: 2.6.14
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: ReportBuilder