nxgreport 0.7.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nxgreport.rb +3 -547
- data/lib/nxgreport/nxgcore.rb +217 -0
- data/lib/nxgreport/nxgcss.rb +323 -0
- data/lib/nxgreport/nxghtml.rb +196 -0
- data/lib/nxgreport/nxgjs.rb +233 -0
- data/lib/nxgreport/version.rb +3 -0
- metadata +43 -12
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'nxgreport/nxghtml.rb'
|
3
|
+
|
4
|
+
class NxgCore
|
5
|
+
class NxgReport
|
6
|
+
|
7
|
+
include NxgHTML
|
8
|
+
|
9
|
+
def initialize(data_provider)
|
10
|
+
@data_provider = data_provider
|
11
|
+
@data_provider[:pass] = 0
|
12
|
+
@data_provider[:fail] = 0
|
13
|
+
@data_provider[:total] = 0
|
14
|
+
@data_provider[:open_on_completion] = false
|
15
|
+
@data_provider[:features] = Array.new()
|
16
|
+
@data_provider[:title] = ""
|
17
|
+
@data_provider[:report_path] = ""
|
18
|
+
@start_time = Time.now.to_f
|
19
|
+
@test_start_time = Time.now.to_f
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup(location: "./NxgReport.html", title: "$NxgReport")
|
23
|
+
@data_provider[:report_path] = location.empty? ? "./NxgReport.html" : location
|
24
|
+
@data_provider[:title] = title
|
25
|
+
end
|
26
|
+
|
27
|
+
def open_upon_execution(value: true)
|
28
|
+
return if !value
|
29
|
+
|
30
|
+
@data_provider[:open_on_completion] = value
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_environment(name: "")
|
34
|
+
return if name.empty?()
|
35
|
+
|
36
|
+
@data_provider[:environment] = name
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_app_version(no: "")
|
40
|
+
return if no.empty?()
|
41
|
+
|
42
|
+
version_no = no.downcase.gsub("app", "").gsub("version", "").strip
|
43
|
+
@data_provider[:app_version] = "App Version #{version_no}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_release(name: "")
|
47
|
+
return if name.empty?()
|
48
|
+
|
49
|
+
@data_provider[:release_name] = name
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_os(name: "")
|
53
|
+
return if name.empty?()
|
54
|
+
|
55
|
+
@data_provider[:os] = name
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_device(name: "")
|
59
|
+
return if name.empty?()
|
60
|
+
|
61
|
+
@data_provider[:device] = name
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_execution(date: "")
|
65
|
+
return if date.empty?()
|
66
|
+
|
67
|
+
@data_provider[:execution_date] = date
|
68
|
+
end
|
69
|
+
|
70
|
+
def set_execution_time()
|
71
|
+
time_diff_in_mins = 0
|
72
|
+
time_diff_in_secs = 0
|
73
|
+
|
74
|
+
@data_provider[:features].each do |feature|
|
75
|
+
feature["tests"].each do |test|
|
76
|
+
time_diff_in_secs += test["time"]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
time_diff_in_mins = ((time_diff_in_secs) / 60).to_i
|
81
|
+
|
82
|
+
if time_diff_in_mins >= 60
|
83
|
+
time_diff_in_hrs = (time_diff_in_mins / 60.to_f).round(2)
|
84
|
+
@data_provider[:execution_time] = "#{time_diff_in_hrs} #{time_diff_in_hrs == 1 ? "hour" : "hours"}"
|
85
|
+
else
|
86
|
+
@data_provider[:execution_time] = "#{time_diff_in_mins} mins"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def log_test(feature_name: "", test_name:"", test_status: "", tag: "", comments: "", execution_time: 0)
|
91
|
+
if feature_name.nil?() || feature_name.strip.empty?()
|
92
|
+
log("Feature name cannot be empty.")
|
93
|
+
return
|
94
|
+
end
|
95
|
+
|
96
|
+
if test_status.nil?() || test_status.strip.empty?()
|
97
|
+
log("Test status cannot be empty.")
|
98
|
+
return
|
99
|
+
end
|
100
|
+
|
101
|
+
if test_name.nil?() || test_name.strip.empty?()
|
102
|
+
log("Test name cannot be empty.")
|
103
|
+
return
|
104
|
+
end
|
105
|
+
|
106
|
+
f_name = feature_name.strip
|
107
|
+
t_name = test_name.strip
|
108
|
+
t_pass = test_status.strip.downcase.include?('pass') ? true : false
|
109
|
+
t_comments = comments.strip
|
110
|
+
|
111
|
+
if !feature_exists?(f_name)
|
112
|
+
new_feature = {
|
113
|
+
"name" => f_name,
|
114
|
+
"total" => 0,
|
115
|
+
"pass" => 0,
|
116
|
+
"fail" => 0,
|
117
|
+
"tests" => Array.new()
|
118
|
+
}
|
119
|
+
@data_provider[:features].push(new_feature)
|
120
|
+
end
|
121
|
+
|
122
|
+
update_feature(f_name, t_name, t_pass, t_comments, get_execution_time(execution_time), tag)
|
123
|
+
@data_provider[:total] += 1
|
124
|
+
@data_provider[t_pass ? :pass : :fail] += 1
|
125
|
+
end
|
126
|
+
|
127
|
+
def build()
|
128
|
+
@data_provider[:report_path] = generate_report_path() if @data_provider[:report_path].empty?()
|
129
|
+
@data_provider[:title] = "$NxgReport" if @data_provider[:title].empty?()
|
130
|
+
folder_check()
|
131
|
+
set_execution_time()
|
132
|
+
write()
|
133
|
+
if @data_provider[:open_on_completion]
|
134
|
+
system("open #{@data_provider[:report_path]}") if File.file?(@data_provider[:report_path])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Private methods
|
139
|
+
|
140
|
+
def update_feature(f_name, t_name, t_pass, t_comments, t_execution_time, t_tag)
|
141
|
+
@data_provider[:features].each do |feature|
|
142
|
+
if feature["name"].eql?(f_name)
|
143
|
+
feature["total"]+=1
|
144
|
+
feature[t_pass ? "pass" : "fail"]+=1
|
145
|
+
feature["tests"].push({
|
146
|
+
"name" => t_name,
|
147
|
+
"testPass" => t_pass,
|
148
|
+
"comments" => t_comments,
|
149
|
+
"time" => t_execution_time,
|
150
|
+
"tag" => t_tag
|
151
|
+
})
|
152
|
+
return
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def feature_exists?(feature_name)
|
158
|
+
@data_provider[:features].each do |feature|
|
159
|
+
return true if feature["name"].eql?(feature_name)
|
160
|
+
end
|
161
|
+
return false
|
162
|
+
end
|
163
|
+
|
164
|
+
def log(message)
|
165
|
+
puts("🤖- #{message}")
|
166
|
+
end
|
167
|
+
|
168
|
+
def folder_check()
|
169
|
+
folder = File.dirname(@data_provider[:report_path])
|
170
|
+
FileUtils.mkdir_p(folder) unless File.directory?(folder)
|
171
|
+
end
|
172
|
+
|
173
|
+
def clean()
|
174
|
+
File.delete(@data_provider[:report_path]) if File.file?(@data_provider[:report_path])
|
175
|
+
end
|
176
|
+
|
177
|
+
def write()
|
178
|
+
clean()
|
179
|
+
if @data_provider[:features].length == 0
|
180
|
+
log("No tests logged, cannot build empty report.")
|
181
|
+
return
|
182
|
+
end
|
183
|
+
template = File.new(@data_provider[:report_path], 'w')
|
184
|
+
template.puts(html(@data_provider))
|
185
|
+
template.close()
|
186
|
+
end
|
187
|
+
|
188
|
+
def generate_report_path()
|
189
|
+
report_filename = @data_provider.key?(:release_name) ? @data_provider[:release_name] : "NxgReport"
|
190
|
+
report_filename += "-#{@data_provider[:device]}" if @data_provider.key?(:device)
|
191
|
+
report_filename += "-#{@data_provider[:os]}" if @data_provider.key?(:os)
|
192
|
+
report_filename += "-#{@data_provider[:app_version]}" if @data_provider.key?(:app_version)
|
193
|
+
report_filename += "-#{@data_provider[:environment]}" if @data_provider.key?(:environment)
|
194
|
+
report_filename = report_filename.gsub(/[^0-9a-z-]/i, '')
|
195
|
+
return "./#{report_filename}.html"
|
196
|
+
end
|
197
|
+
|
198
|
+
def get_execution_time(execution_time)
|
199
|
+
if execution_time != 0
|
200
|
+
@test_start_time = Time.now.to_f
|
201
|
+
return execution_time.round()
|
202
|
+
end
|
203
|
+
@test_end_time = Time.now.to_f
|
204
|
+
execution_time = (@test_end_time - @test_start_time).round()
|
205
|
+
@test_start_time = Time.now.to_f
|
206
|
+
return execution_time
|
207
|
+
end
|
208
|
+
|
209
|
+
private :log, :clean, :write, :update_feature, :folder_check
|
210
|
+
end
|
211
|
+
|
212
|
+
private_constant :NxgReport
|
213
|
+
|
214
|
+
def instance(data_provider: Hash.new())
|
215
|
+
NxgReport.new(data_provider)
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
|
2
|
+
module NxgCss
|
3
|
+
|
4
|
+
def has_environment_settings(data_provider)
|
5
|
+
data_provider.key?(:environment) || data_provider.key?(:app_version) || data_provider.key?(:release_name) || data_provider.key?(:os) || data_provider.key?(:device) || data_provider.key?(:execution_date)
|
6
|
+
end
|
7
|
+
|
8
|
+
def css(data_provider)
|
9
|
+
"<style>
|
10
|
+
:root {
|
11
|
+
--font: \"Open Sans\", sans-serif;
|
12
|
+
--primary-gradient: linear-gradient(to bottom right, #ff644e, #cb3018);
|
13
|
+
--background-color: #f4f4f4;
|
14
|
+
--primary-color: #fff;
|
15
|
+
--secondary-color: #fff;
|
16
|
+
--primary-font-color: #424242;
|
17
|
+
--green: rgb(19, 143, 19);
|
18
|
+
--red: rgb(214, 7, 7);
|
19
|
+
--blue: rgb(0, 89, 255);
|
20
|
+
--red-bg: #ff073925;
|
21
|
+
}
|
22
|
+
|
23
|
+
[theme=\"dark\"] {
|
24
|
+
--background-color: #252525;
|
25
|
+
--primary-color: #2e2e2e;
|
26
|
+
--secondary-color: #fff;
|
27
|
+
--primary-font-color: #f9fafccb;
|
28
|
+
--green: #15ce40;
|
29
|
+
--red: #ff073a;
|
30
|
+
--blue: #2cbcff;
|
31
|
+
--red-bg: #ff07392c;
|
32
|
+
}
|
33
|
+
|
34
|
+
* {
|
35
|
+
font-family: var(--font);
|
36
|
+
color: var(--primary-font-color);
|
37
|
+
transition: color 0.5s ease;
|
38
|
+
transition: background-color 0.5s ease;
|
39
|
+
}
|
40
|
+
|
41
|
+
#app {
|
42
|
+
background-color: var(--background-color);
|
43
|
+
margin: auto;
|
44
|
+
}
|
45
|
+
|
46
|
+
#header {
|
47
|
+
display: grid;
|
48
|
+
grid-template-columns: 8fr 1fr;
|
49
|
+
text-align: center;
|
50
|
+
background: var(--primary-gradient);
|
51
|
+
}
|
52
|
+
|
53
|
+
#app-title,
|
54
|
+
#theme-icon {
|
55
|
+
color: var(--background-color);
|
56
|
+
}
|
57
|
+
|
58
|
+
#sidebar {
|
59
|
+
width: 0;
|
60
|
+
height: 100%;
|
61
|
+
position: fixed;
|
62
|
+
z-index: 2;
|
63
|
+
top: 0;
|
64
|
+
left: 0;
|
65
|
+
overflow-x: hidden;
|
66
|
+
transition: 1s ease;
|
67
|
+
display: flex;
|
68
|
+
place-items: center;
|
69
|
+
background: var(--primary-gradient);
|
70
|
+
}
|
71
|
+
|
72
|
+
#sidebar-div {
|
73
|
+
margin: auto;
|
74
|
+
display: grid;
|
75
|
+
grid-template-rows: 1fr auto;
|
76
|
+
place-items: center;
|
77
|
+
}
|
78
|
+
|
79
|
+
#sidebar-catergories {
|
80
|
+
width: 80%;
|
81
|
+
display: flex;
|
82
|
+
flex-wrap: wrap;
|
83
|
+
justify-content: center;
|
84
|
+
transition: opacity 0.5s ease-in-out;
|
85
|
+
transition-delay: 0.5s;
|
86
|
+
opacity: 0;
|
87
|
+
margin-top: 25px;
|
88
|
+
}
|
89
|
+
|
90
|
+
#sidebar-catergories > div {
|
91
|
+
background-color: var(--background-color);
|
92
|
+
border-radius: 1em;
|
93
|
+
margin: 0.5em 0.2em;
|
94
|
+
padding: 0.2em 0.5em;
|
95
|
+
-webkit-box-shadow: -3px 0px 5px -3px rgba(216, 216, 216, 0.75);
|
96
|
+
-moz-box-shadow: -3px 0px 5px -3px rgba(216, 216, 216, 0.75);
|
97
|
+
box-shadow: -3px 0px 5px -3px rgba(216, 216, 216, 0.75);
|
98
|
+
}
|
99
|
+
|
100
|
+
#sidebar-catergories > div > h6 {
|
101
|
+
color: var(--primary-font-color);
|
102
|
+
font-weight: normal;
|
103
|
+
font-size: 0.8em;
|
104
|
+
}
|
105
|
+
|
106
|
+
#sidebar-overlay-test-info {
|
107
|
+
font-size: 16px;
|
108
|
+
margin: 0.5em 0;
|
109
|
+
}
|
110
|
+
|
111
|
+
#sidebar-overlay {
|
112
|
+
width: 60%;
|
113
|
+
height: 100%;
|
114
|
+
z-index: 1;
|
115
|
+
position: fixed;
|
116
|
+
top: 0;
|
117
|
+
left: 0;
|
118
|
+
visibility: hidden;
|
119
|
+
display: flex;
|
120
|
+
transition: margin-left 1s ease;
|
121
|
+
overflow-y: auto;
|
122
|
+
background-color: var(--background-color);
|
123
|
+
}
|
124
|
+
|
125
|
+
#sidebar-overlay-grid {
|
126
|
+
display: grid;
|
127
|
+
grid-template-rows: auto;
|
128
|
+
padding: 1em;
|
129
|
+
margin: 0 1em;
|
130
|
+
width: 100%;
|
131
|
+
height: fit-content;
|
132
|
+
}
|
133
|
+
|
134
|
+
#sidebar-title-wrap {
|
135
|
+
display: grid;
|
136
|
+
grid-template-columns: 1fr auto;
|
137
|
+
place-items: center;
|
138
|
+
}
|
139
|
+
|
140
|
+
#sidebar-overlay-test-info {
|
141
|
+
display: flex;
|
142
|
+
place-items: center;
|
143
|
+
flex-wrap: wrap;
|
144
|
+
}
|
145
|
+
|
146
|
+
#sidebar-title {
|
147
|
+
margin: 0 0.2em 0 0;
|
148
|
+
}
|
149
|
+
|
150
|
+
#sidebar-title,
|
151
|
+
#sidebar-status {
|
152
|
+
color: var(--secondary-color);
|
153
|
+
transition: opacity 0.5s ease-in-out;
|
154
|
+
transition-delay: 0.5s;
|
155
|
+
opacity: 0;
|
156
|
+
}
|
157
|
+
|
158
|
+
#test-title {
|
159
|
+
margin: 0;
|
160
|
+
}
|
161
|
+
|
162
|
+
#test-execution-time {
|
163
|
+
font-size: 0.7em;
|
164
|
+
font-weight: bold;
|
165
|
+
background: var(--primary-gradient);
|
166
|
+
color: white;
|
167
|
+
padding: 0.2em 0.5em;
|
168
|
+
border-radius: 0.5em;
|
169
|
+
margin-left: 0.5em;
|
170
|
+
}
|
171
|
+
|
172
|
+
h2,
|
173
|
+
h3,
|
174
|
+
h4,
|
175
|
+
h5,
|
176
|
+
h6 {
|
177
|
+
text-align: center;
|
178
|
+
margin: auto;
|
179
|
+
}
|
180
|
+
|
181
|
+
#error-message {
|
182
|
+
flex-basis: 100%;
|
183
|
+
margin: 1em 1.5em 0 1.5em;
|
184
|
+
display: table-cell;
|
185
|
+
vertical-align: middle;
|
186
|
+
background-color: var(--primary-color);
|
187
|
+
padding: 1em;
|
188
|
+
border-radius: 1em;
|
189
|
+
font-size: 0.8em;
|
190
|
+
}
|
191
|
+
|
192
|
+
#body-wrap {
|
193
|
+
display: grid;
|
194
|
+
grid-template-rows: auto auto 1fr;
|
195
|
+
height: 100vh;
|
196
|
+
width: 100vw;
|
197
|
+
}
|
198
|
+
|
199
|
+
#theme-switch {
|
200
|
+
width: 5em;
|
201
|
+
height: 5em;
|
202
|
+
background-color: Transparent;
|
203
|
+
background-repeat: no-repeat;
|
204
|
+
border: none;
|
205
|
+
cursor: pointer;
|
206
|
+
overflow: hidden;
|
207
|
+
outline: none;
|
208
|
+
margin: 0;
|
209
|
+
margin-right: 1em;
|
210
|
+
position: relative;
|
211
|
+
top: 50%;
|
212
|
+
-ms-transform: translateY(-50%);
|
213
|
+
transform: translateY(-50%);
|
214
|
+
}
|
215
|
+
|
216
|
+
.params-container {
|
217
|
+
display: flex;
|
218
|
+
flex-wrap: wrap;
|
219
|
+
justify-content: space-between;
|
220
|
+
text-align: center;
|
221
|
+
padding: 1em 2em;
|
222
|
+
}
|
223
|
+
|
224
|
+
.param-wrap {
|
225
|
+
display: flex;
|
226
|
+
place-items: center;
|
227
|
+
}
|
228
|
+
|
229
|
+
.pi {
|
230
|
+
font-size: 1.5em;
|
231
|
+
padding-right: 0.5em;
|
232
|
+
}
|
233
|
+
|
234
|
+
#pt {
|
235
|
+
font-size: 0.9em;
|
236
|
+
}
|
237
|
+
|
238
|
+
#filter {
|
239
|
+
cursor: pointer;
|
240
|
+
border-radius: 1em;
|
241
|
+
width: 5em;
|
242
|
+
padding: 0.2em 1em;
|
243
|
+
background-color: var(--primary-color);
|
244
|
+
}
|
245
|
+
|
246
|
+
.features-grid {
|
247
|
+
display: grid;
|
248
|
+
grid-template-columns: 1fr 1fr 1fr;
|
249
|
+
grid-auto-rows: 70px;
|
250
|
+
grid-gap: 0.5em;
|
251
|
+
padding: 0.5em 2em;
|
252
|
+
}
|
253
|
+
|
254
|
+
.module {
|
255
|
+
display: grid;
|
256
|
+
place-items: center;
|
257
|
+
grid-template-columns: 3fr 1fr 1fr 1fr;
|
258
|
+
border-radius: 0.7rem;
|
259
|
+
padding: 10px 10px;
|
260
|
+
background-color: var(--primary-color);
|
261
|
+
cursor: pointer;
|
262
|
+
}
|
263
|
+
|
264
|
+
.total,
|
265
|
+
.pass,
|
266
|
+
.fail {
|
267
|
+
display: grid;
|
268
|
+
width: 100%;
|
269
|
+
height: 100%;
|
270
|
+
place-items: center;
|
271
|
+
}
|
272
|
+
|
273
|
+
.total > * {
|
274
|
+
color: var(--blue);
|
275
|
+
}
|
276
|
+
|
277
|
+
.banner {
|
278
|
+
margin: auto;
|
279
|
+
text-align: center;
|
280
|
+
}
|
281
|
+
|
282
|
+
.banner-text {
|
283
|
+
font-size: 5em;
|
284
|
+
}
|
285
|
+
|
286
|
+
#footer {
|
287
|
+
font-size: 0.7rem;
|
288
|
+
text-align: center;
|
289
|
+
margin-bottom: 0.5em;
|
290
|
+
padding: 3em 3em 1em 3em;
|
291
|
+
}
|
292
|
+
|
293
|
+
@media (min-width: 600px) and (max-width: 1400px) {
|
294
|
+
.pi {
|
295
|
+
font-size: 1em;
|
296
|
+
padding-right: 0.5em;
|
297
|
+
}
|
298
|
+
|
299
|
+
#pt {
|
300
|
+
font-size: 0.8em;
|
301
|
+
}
|
302
|
+
|
303
|
+
.funcname {
|
304
|
+
font-size: 0.9em;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
.green-font,
|
309
|
+
.pass > * {
|
310
|
+
color: var(--green);
|
311
|
+
}
|
312
|
+
|
313
|
+
.red-font,
|
314
|
+
.fail > * {
|
315
|
+
color: var(--red);
|
316
|
+
}
|
317
|
+
|
318
|
+
.red-bg {
|
319
|
+
background-color: var(--red-bg);
|
320
|
+
}
|
321
|
+
</style>"
|
322
|
+
end
|
323
|
+
end
|