cucumber-formatter 1.1.0 → 1.1.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/cucumber_formatter.rb +71 -29
- data/lib/database.rb +45 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6034bdd263ebe1f6316a9dd15d4db9d4365a40ae
|
4
|
+
data.tar.gz: 775c63f2ae7e5e76ffd77296792a556d643d5f39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9513eb0b028a8c266c5bf340170775dfae6d3feb44c55e3421f0fd018f3c8675e04ce841f6b3d4a74519a6a6d3efbd35a5129aed93862b5a8285a22d732c6cca
|
7
|
+
data.tar.gz: 7b704830ad057a6c9df06bb1049bad66199d3682aa20c287b9cbae22cc6768ab13dee9ec33b202bd60f146b21682af2c7c87edf8be60c58b9dadc2bc22480aa8
|
data/lib/cucumber_formatter.rb
CHANGED
@@ -28,10 +28,14 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISE
|
|
28
28
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
29
|
=end
|
30
30
|
|
31
|
+
require_relative 'database.rb'
|
32
|
+
|
31
33
|
class CucumberFormatter
|
32
34
|
|
33
35
|
def initialize(step_mother, io, options)
|
34
36
|
puts "Initializing CucumberMetrics ...\n\n\n"
|
37
|
+
|
38
|
+
@db_avail = true
|
35
39
|
end
|
36
40
|
|
37
41
|
def before_feature(feature)
|
@@ -40,7 +44,12 @@ class CucumberFormatter
|
|
40
44
|
|
41
45
|
@scenario = feature.feature_elements[@scenario_counter]
|
42
46
|
@scenario_counter += 1
|
43
|
-
|
47
|
+
begin
|
48
|
+
save_str_start_time if @db_avail
|
49
|
+
rescue => e
|
50
|
+
puts "Error saving start time: #{e.message}"
|
51
|
+
@db_avail = false
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
# the first set of background steps don't call this method (cucumber 1.3.19) - instead
|
@@ -48,7 +57,12 @@ class CucumberFormatter
|
|
48
57
|
def before_feature_element(scenario)
|
49
58
|
unless @background
|
50
59
|
@scenario = scenario
|
51
|
-
|
60
|
+
begin
|
61
|
+
save_str_start_time if @db_avail
|
62
|
+
rescue => e
|
63
|
+
puts "Error saving start time: #{e.message}"
|
64
|
+
@db_avail = false
|
65
|
+
end
|
52
66
|
end
|
53
67
|
end
|
54
68
|
|
@@ -66,7 +80,12 @@ class CucumberFormatter
|
|
66
80
|
|
67
81
|
sql = "INSERT INTO scenario_steps (scenario_test_run_id, name, elapsed_time, created_at, updated_at)
|
68
82
|
VALUES (#{@str_id}, \'#{step_name}\', #{(@end_time - @start_time).round}, now(), now())"
|
69
|
-
|
83
|
+
begin
|
84
|
+
Database.query(sql) if @db_avail && step_name != nil
|
85
|
+
rescue => e
|
86
|
+
puts "There was an error saving the step: #{e.message}"
|
87
|
+
@db_avail = false
|
88
|
+
end
|
70
89
|
end
|
71
90
|
|
72
91
|
#finish saving the test run
|
@@ -75,10 +94,21 @@ class CucumberFormatter
|
|
75
94
|
|
76
95
|
sql = "UPDATE scenario_test_runs SET elapsed_time = #{Time.now - @scenario_time_start}, passed = #{passed},
|
77
96
|
updated_at = now() WHERE id = #{@str_id}"
|
78
|
-
|
97
|
+
|
98
|
+
begin
|
99
|
+
Database.query(sql) if @db_avail
|
100
|
+
rescue => e
|
101
|
+
puts "There was an error saving the elapsed time: #{e.message}"
|
102
|
+
@db_avail = false
|
103
|
+
end
|
79
104
|
|
80
105
|
if scenario.failed?
|
81
|
-
|
106
|
+
begin
|
107
|
+
save_links(scenario) if @db_avail
|
108
|
+
rescue => e
|
109
|
+
puts "There was an error saving the links to the failed scenario: #{e.message}"
|
110
|
+
@db_avail = false
|
111
|
+
end
|
82
112
|
end
|
83
113
|
#reset step counter when scenario is finished
|
84
114
|
@step_counter = 0
|
@@ -86,6 +116,16 @@ class CucumberFormatter
|
|
86
116
|
@background = false
|
87
117
|
end
|
88
118
|
|
119
|
+
def after_feature(scenario)
|
120
|
+
@scenario_counter = nil
|
121
|
+
end
|
122
|
+
|
123
|
+
def after_features(scenario)
|
124
|
+
unless @db_avail
|
125
|
+
puts "\n\nThe metrics data may be missing or incomplete because there were problems with the database."
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
89
129
|
private
|
90
130
|
|
91
131
|
def save_str_start_time
|
@@ -96,8 +136,6 @@ class CucumberFormatter
|
|
96
136
|
@end_time = Time.now
|
97
137
|
machine_name = Socket.gethostname
|
98
138
|
|
99
|
-
@dbm ||= dbm
|
100
|
-
|
101
139
|
if @scenario == nil
|
102
140
|
fail "The scenario did not run"
|
103
141
|
end
|
@@ -116,7 +154,7 @@ class CucumberFormatter
|
|
116
154
|
tags.each do |t|
|
117
155
|
sql = "INSERT INTO scenario_tags (scenario_test_run_id, tag_name, created_at, updated_at)
|
118
156
|
VALUES (#{@str_id}, \'#{t}\', now(), now())"
|
119
|
-
|
157
|
+
Database.query(sql)
|
120
158
|
end
|
121
159
|
end
|
122
160
|
|
@@ -125,8 +163,12 @@ class CucumberFormatter
|
|
125
163
|
sql = "INSERT INTO scenario_test_runs (scenario_id, test_run_at, test_environment_id,
|
126
164
|
browser_id, machine_name, created_at, updated_at)
|
127
165
|
VALUES (#{@scenario_id}, now(), #{@env_id}, #{@browser_id}, \'#{machine_name}\', now(), now())"
|
128
|
-
|
129
|
-
|
166
|
+
Database.query(sql)
|
167
|
+
|
168
|
+
sql = "SELECT MAX(id) as max_id FROM scenario_test_runs"
|
169
|
+
Database.query(sql).each do |r|
|
170
|
+
@str_id = r["max_id"]
|
171
|
+
end
|
130
172
|
end
|
131
173
|
|
132
174
|
# get the step name; keep track of the counter through the scenario
|
@@ -148,7 +190,7 @@ class CucumberFormatter
|
|
148
190
|
|
149
191
|
@scenario_id = 0
|
150
192
|
sql = "SELECT id FROM scenarios WHERE scenario_name LIKE \'#{trimmed_scenario_title}\'"
|
151
|
-
results =
|
193
|
+
results = Database.query(sql)
|
152
194
|
results.each do |r|
|
153
195
|
@scenario_id = r["id"]
|
154
196
|
end
|
@@ -157,41 +199,50 @@ class CucumberFormatter
|
|
157
199
|
if @scenario_id == 0
|
158
200
|
sql = "INSERT INTO scenarios (scenario_name, created_at, updated_at)
|
159
201
|
VALUES (\'#{trimmed_scenario_title}\', now(), now())"
|
160
|
-
|
202
|
+
Database.query(sql)
|
161
203
|
|
162
|
-
|
204
|
+
sql = "SELECT MAX(id) as max_id FROM scenarios"
|
205
|
+
Database.query(sql).each do |r|
|
206
|
+
@scenario_id = r["max_id"]
|
207
|
+
end
|
163
208
|
end
|
164
209
|
end
|
165
210
|
|
166
211
|
def get_environment_id
|
167
212
|
@env_id = 0
|
168
213
|
sql = "SELECT id FROM test_environments WHERE env_name like \'#{TESTENV}\'"
|
169
|
-
results =
|
214
|
+
results = Database.query(sql)
|
170
215
|
results.each do |r|
|
171
216
|
@env_id = r["id"]
|
172
217
|
end
|
173
218
|
|
174
219
|
if @env_id == 0
|
175
220
|
sql = "INSERT INTO test_environments (env_name, created_at, updated_at) VALUES(\'#{TESTENV}\', now(), now())"
|
176
|
-
|
221
|
+
Database.query(sql)
|
177
222
|
|
178
|
-
|
223
|
+
sql = "SELECT MAX(id) as max_id FROM test_environments"
|
224
|
+
Database.query(sql).each do |r|
|
225
|
+
@env_id = r["max_id"]
|
226
|
+
end
|
179
227
|
end
|
180
228
|
end
|
181
229
|
|
182
230
|
def get_browser_id
|
183
231
|
@browser_id = 0
|
184
232
|
sql = "SELECT id FROM browsers WHERE browser_name like \'#{BROWSER}\'"
|
185
|
-
results =
|
233
|
+
results = Database.query(sql)
|
186
234
|
results.each do |r|
|
187
235
|
@browser_id = r["id"]
|
188
236
|
end
|
189
237
|
|
190
238
|
if @browser_id == 0
|
191
239
|
sql = "INSERT INTO browsers (browser_name, created_at, updated_at) VALUES(\'#{BROWSER}\', now(), now())"
|
192
|
-
|
240
|
+
Database.query(sql)
|
193
241
|
|
194
|
-
|
242
|
+
sql = "SELECT MAX(id) as max_id FROM browsers"
|
243
|
+
Database.query(sql).each do |r|
|
244
|
+
@browser_id = r["max_id"]
|
245
|
+
end
|
195
246
|
end
|
196
247
|
end
|
197
248
|
|
@@ -209,16 +260,7 @@ class CucumberFormatter
|
|
209
260
|
VALUES(#{@str_id}, \'#{failed_step.gsub('\'', '')}\', \'#{scenario.feature.title.gsub('\'', '')}\',
|
210
261
|
\'#{scenario.title.gsub('\'', '')}\', \'#{scenario.feature.file.gsub('\'', '')}\', now(), now())"
|
211
262
|
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
# connect to database with credentials in metrics yml file
|
216
|
-
def dbm
|
217
|
-
database = OpenStruct.new(YAML.load_file(METRICS_CONFIG_FILE))
|
218
|
-
Mysql2::Client.new(:host => database.metrics_db['host'],
|
219
|
-
:username => database.metrics_db['username'],
|
220
|
-
:password => database.metrics_db['password'],
|
221
|
-
:database => database.metrics_db['database'])
|
263
|
+
Database.query(sql)
|
222
264
|
end
|
223
265
|
|
224
266
|
def extract_tags
|
data/lib/database.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'mysql2'
|
2
|
+
|
3
|
+
class Database
|
4
|
+
|
5
|
+
def self.query(sql)
|
6
|
+
looping = true
|
7
|
+
counter = 0
|
8
|
+
results = nil
|
9
|
+
|
10
|
+
self.connect
|
11
|
+
|
12
|
+
while looping
|
13
|
+
begin
|
14
|
+
results = @client.query(sql)
|
15
|
+
looping = false
|
16
|
+
rescue => e
|
17
|
+
counter += 1
|
18
|
+
if counter >= 5
|
19
|
+
@client.close
|
20
|
+
fail "There was an error with the database connection or the query: #{e}"
|
21
|
+
end
|
22
|
+
sleep 2
|
23
|
+
self.connect
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
self.disconnect
|
28
|
+
results
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.connect
|
34
|
+
database = OpenStruct.new(YAML.load_file(METRICS_CONFIG_FILE))
|
35
|
+
@client = Mysql2::Client.new(:host => database.metrics_db['host'],
|
36
|
+
:username => database.metrics_db['username'],
|
37
|
+
:password => database.metrics_db['password'],
|
38
|
+
:database => database.metrics_db['database'])
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.disconnect
|
42
|
+
@client.close
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hartill
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/cucumber_formatter.rb
|
34
|
+
- lib/database.rb
|
34
35
|
homepage: https://github.com/SalesforceEng/cucumber-metrics
|
35
36
|
licenses:
|
36
37
|
- BSD 3-clause
|