itriagetestrail 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/itriagetestrail.rb +411 -1
- data/lib/itriagetestrail/version.rb +1 -1
- metadata +1 -2
- data/lib/itriagetestrail/helpers.rb +0 -405
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf91591aef40e30e0e07cbdd4d67d92672052a48
|
4
|
+
data.tar.gz: 9b06e2ad6ff898a76e7698aaa5534e71d859e56d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8066804b33b5bdb0f06e7aebcf8eb2c8341084b5202eda9ce0e064de6d229932defac95b4a960158681dfb12663b435f7e8f6a6f0c6761099abe427bdaf8a5a7
|
7
|
+
data.tar.gz: 73f687aa9bd611fc4c82f9b87c58ce7a9fe30530e5ccd39898a9a386098e53fe9033894bb9b4b57474c225e8db472d5122dd81b54a994fb339a9d20332dfaa25
|
data/lib/itriagetestrail.rb
CHANGED
@@ -2,14 +2,424 @@ require_relative 'itriagetestrail/version'
|
|
2
2
|
require_relative 'itriagetestrail/testrail_binding'
|
3
3
|
|
4
4
|
require_relative 'itriagetestrail/pool'
|
5
|
-
require_relative 'itriagetestrail/helpers'
|
6
5
|
|
7
6
|
require 'tzinfo'
|
8
7
|
|
9
8
|
module Itriagetestrail
|
9
|
+
module Projects
|
10
|
+
# populate projects instance variable with all projects objects in the testrail site
|
11
|
+
def projects
|
12
|
+
@projects ||= @client.send_get("get_projects")
|
13
|
+
end
|
14
|
+
|
15
|
+
def project_by_name(name)
|
16
|
+
res = -1
|
17
|
+
projects.each do |project|
|
18
|
+
res = project if project['name'] == name
|
19
|
+
end
|
20
|
+
res
|
21
|
+
end
|
22
|
+
|
23
|
+
# return the project object for a given project id
|
24
|
+
def project_by_id(id)
|
25
|
+
res = -1
|
26
|
+
projects.each do |project|
|
27
|
+
res = project if project['id'] == id.to_i
|
28
|
+
end
|
29
|
+
res
|
30
|
+
end
|
31
|
+
|
32
|
+
# set the project_id by a requested project from config/environment variable
|
33
|
+
def set_project
|
34
|
+
requested_id = @testrail_config[:projectId]
|
35
|
+
case requested_id
|
36
|
+
when nil, ''
|
37
|
+
# a project id was not provided, fetch it from TestRail by project name
|
38
|
+
res = project_by_name(@testrail_config[:projectName])
|
39
|
+
if res == -1
|
40
|
+
@execute = false
|
41
|
+
return
|
42
|
+
end
|
43
|
+
@project_id = res['id']
|
44
|
+
@suite_mode = res['suite_mode']
|
45
|
+
else
|
46
|
+
# use the requested project id
|
47
|
+
@project_id = requested_id
|
48
|
+
@suite_mode = project_by_id(@project_id)['suite_mode']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module Suites
|
54
|
+
# TestRail Suites
|
55
|
+
def testrail_suites
|
56
|
+
case @suite_mode
|
57
|
+
when 2,3
|
58
|
+
@suites = @client.send_get("get_suites/#{@project_id}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def testrail_suite_id(suite_name)
|
63
|
+
res = -1
|
64
|
+
@suites.each do |suite|
|
65
|
+
res = suite['id'] if suite['name'] == suite_name
|
66
|
+
end
|
67
|
+
res
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_testrail_suite(suite_name)
|
71
|
+
body = { name: suite_name }
|
72
|
+
res = @client.send_post("add_suite/#{@project_id}", body)
|
73
|
+
testrail_suite = res['id']
|
74
|
+
|
75
|
+
#re-establish suites
|
76
|
+
testrail_suites
|
77
|
+
|
78
|
+
testrail_suite
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
module Milestones
|
83
|
+
|
84
|
+
# Establish the milestone name based on origin passed in,
|
85
|
+
# usually origin represents a branch or environment
|
86
|
+
def normalize_milestone
|
87
|
+
case @testrail_config[:origin]
|
88
|
+
when 'prd', 'production', 'origin/production'
|
89
|
+
'Production'
|
90
|
+
when 'stg', 'staging', 'origin/staging'
|
91
|
+
'Staging'
|
92
|
+
when 'dev', 'development', 'origin/development'
|
93
|
+
'Development'
|
94
|
+
when 'local', ''
|
95
|
+
'Local'
|
96
|
+
when 'master', 'origin/master'
|
97
|
+
if @testrail_config[:masterMilestone].nil? || @testrail_config[:masterMilestone].empty?
|
98
|
+
'Master'
|
99
|
+
else
|
100
|
+
@testrail_config[:masterMilestone]
|
101
|
+
end
|
102
|
+
else
|
103
|
+
'Dev Branch'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# returns timestamp for begining of first day of current quarter
|
108
|
+
def milestone_period_start
|
109
|
+
time_zone = TZInfo::Timezone.get('America/Denver')
|
110
|
+
current_year = time_zone.now.year
|
111
|
+
month = time_zone.now.mon
|
112
|
+
|
113
|
+
# determine which quarter we are in
|
114
|
+
if month <= 3
|
115
|
+
time_zone.utc_to_local(Time.utc(current_year, 1, 1))
|
116
|
+
elsif month <= 6
|
117
|
+
time_zone.utc_to_local(Time.utc(current_year, 4, 1))
|
118
|
+
elsif month <= 9
|
119
|
+
time_zone.utc_to_local(Time.utc(current_year, 7, 1))
|
120
|
+
else
|
121
|
+
time_zone.utc_to_local(Time.utc(current_year, 10, 1))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# determine the due date (end of quarter) for a new milestone being added
|
126
|
+
def milestone_due_date
|
127
|
+
time_zone = TZInfo::Timezone.get('America/Denver')
|
128
|
+
current_year = time_zone.now.year
|
129
|
+
month = time_zone.now.mon
|
130
|
+
|
131
|
+
# determine which quarter we are in
|
132
|
+
if month <= 3
|
133
|
+
Time.utc(current_year, 3, 31).strftime('%s')
|
134
|
+
elsif month <= 6
|
135
|
+
Time.utc(current_year, 6, 30).strftime('%s')
|
136
|
+
elsif month <= 9
|
137
|
+
Time.utc(current_year, 9, 30).strftime('%s')
|
138
|
+
else
|
139
|
+
Time.new(current_year, 12, 31).strftime('%s')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# returns the id for a requested milestone by name, or creates one if the milestone does not exist
|
144
|
+
def fetch_milestone(requested_milestone_name)
|
145
|
+
milestones = @client.send_get("get_milestones/#{@project_id}")
|
146
|
+
res = -1
|
147
|
+
milestones.each do |milestone|
|
148
|
+
res = milestone['id'] if milestone['name'] == requested_milestone_name
|
149
|
+
end
|
150
|
+
|
151
|
+
if res == -1
|
152
|
+
# We need to add the milestone to TestRail
|
153
|
+
|
154
|
+
body = {
|
155
|
+
name: requested_milestone_name,
|
156
|
+
due_on: milestone_due_date
|
157
|
+
}
|
158
|
+
|
159
|
+
res = @client.send_post("add_milestone/#{@project_id}", body)['id']
|
160
|
+
end
|
161
|
+
res
|
162
|
+
end
|
163
|
+
|
164
|
+
# return a standardized name for a milestone to be archived
|
165
|
+
def milestone_archive_name(milestone_name, date)
|
166
|
+
year = date.year
|
167
|
+
month = date.mon
|
168
|
+
|
169
|
+
if month <= 3
|
170
|
+
"#{milestone_name} #{year}-Q1"
|
171
|
+
elsif month <= 6
|
172
|
+
"#{milestone_name} #{year}-Q2"
|
173
|
+
elsif month <= 9
|
174
|
+
"#{milestone_name} #{year}-Q3"
|
175
|
+
else
|
176
|
+
"#{milestone_name} #{year}-Q4"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# return all the runs associated with an existing milestone
|
181
|
+
def milestone_runs(milestone_name)
|
182
|
+
# use the matching milestone id for project
|
183
|
+
milestone_id = fetch_milestone(milestone_name)
|
184
|
+
|
185
|
+
# fetch all test runs associated with the milestone id for project
|
186
|
+
@client.send_get("get_runs/#{@project_id}&milestone_id=#{milestone_id}&is_completed=1") || []
|
187
|
+
end
|
188
|
+
|
189
|
+
# testrail call to rename a milestone (for archiving)
|
190
|
+
def rename_milestone(id, new_name)
|
191
|
+
# todo: rename milestone with previous_milestone
|
192
|
+
body = { name: new_name }
|
193
|
+
res = @client.send_post("update_milestone/#{id}", body)['id']
|
194
|
+
end
|
195
|
+
|
196
|
+
# this archives a milestone at the turn of a quarter and creates a new one in its place
|
197
|
+
def reset_milestone(milestone_name)
|
198
|
+
runs = milestone_runs(milestone_name)
|
199
|
+
if runs.size > 0
|
200
|
+
last_run_time = Time.at(runs.last['completed_on'])
|
201
|
+
if last_run_time < milestone_period_start
|
202
|
+
rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
|
203
|
+
@milestone_id = fetch_milestone(@milestone_name)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
module Sections
|
210
|
+
# TestRail Sections
|
211
|
+
def testrail_sections
|
212
|
+
case @suite_mode
|
213
|
+
when 2,3
|
214
|
+
@suite_id = testrail_suite_id(@suite_name)
|
215
|
+
@sections = @client.send_get("get_sections/#{@project_id}&suite_id=#{@suite_id}")
|
216
|
+
else
|
217
|
+
@sections = @client.send_get("get_sections/#{@project_id}")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def testrail_section_id(section_title)
|
222
|
+
res = -1
|
223
|
+
@sections.each do |section|
|
224
|
+
res = section['id'] if section['name'] == section_title
|
225
|
+
end
|
226
|
+
res
|
227
|
+
end
|
228
|
+
|
229
|
+
def add_testrail_section(section_title)
|
230
|
+
if @suite_name
|
231
|
+
body = {
|
232
|
+
name: section_title,
|
233
|
+
suite_id: testrail_suite_id(@suite_name)
|
234
|
+
}
|
235
|
+
else
|
236
|
+
body = {
|
237
|
+
name: section_title
|
238
|
+
}
|
239
|
+
end
|
240
|
+
|
241
|
+
res = @client.send_post("add_section/#{@project_id}", body)
|
242
|
+
|
243
|
+
testrail_section = res['id']
|
244
|
+
|
245
|
+
# re-establish sections
|
246
|
+
testrail_sections
|
247
|
+
|
248
|
+
testrail_section
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
module TestCases
|
253
|
+
# TestRail Cases
|
254
|
+
def testrail_ids
|
255
|
+
case @suite_mode
|
256
|
+
when 2,3
|
257
|
+
@test_cases = @client.send_get("get_cases/#{@project_id}&suite_id=#{@suite_id}&type_id=3")
|
258
|
+
else
|
259
|
+
@test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3")
|
260
|
+
end
|
261
|
+
|
262
|
+
@test_case_ids = []
|
263
|
+
|
264
|
+
@test_cases.each { |test_case| @test_case_ids << test_case['id'] }
|
265
|
+
end
|
266
|
+
|
267
|
+
def testrail_test_case_id(external_id)
|
268
|
+
res = -1
|
269
|
+
@test_cases.each do |test_case|
|
270
|
+
if test_case['custom_external_case_id'] == external_id
|
271
|
+
res = test_case['id']
|
272
|
+
end
|
273
|
+
end
|
274
|
+
res
|
275
|
+
end
|
276
|
+
|
277
|
+
def associate_result(external_id)
|
278
|
+
test_case_id = testrail_test_case_id(external_id)
|
279
|
+
# store the test case id with the local result
|
280
|
+
@results[:results].each do |result|
|
281
|
+
next unless result[:external_id] == external_id
|
282
|
+
@external_results[:results] << { case_id: test_case_id,
|
283
|
+
status_id: result['status_id'],
|
284
|
+
comment: result['comment'] }
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
# add the test case if it doesn't exist
|
289
|
+
def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
|
290
|
+
body = {
|
291
|
+
title: scenario_title,
|
292
|
+
custom_external_case_id: external_id,
|
293
|
+
custom_steps: scenario_steps,
|
294
|
+
type_id: 3
|
295
|
+
}
|
296
|
+
|
297
|
+
@client.send_post("add_case/#{section_id}", body)
|
298
|
+
|
299
|
+
# refresh test case ids
|
300
|
+
testrail_ids
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_name
|
304
|
+
label = ''
|
305
|
+
label += "App Version:#{@app_version}" unless @app_version.nil? || @app_version == ''
|
306
|
+
label += " Jenkins Build:#{@jenkins_build}" unless @jenkins_build .nil? || @jenkins_build == ''
|
307
|
+
label.strip!
|
308
|
+
label = 'Regression' if label == ''
|
309
|
+
label + ' (' + @time_zone.now.strftime('%-I:%M %p') + ')'
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
module TestRuns
|
314
|
+
def extend_testrail_run
|
315
|
+
# Reset test scope to include all cases
|
316
|
+
body = { include_all: true }
|
317
|
+
@client.send_post("update_run/#{@run_id}", body)
|
318
|
+
end
|
319
|
+
|
320
|
+
def existing_cases_from_description
|
321
|
+
# Grabs from testrail run description
|
322
|
+
run = @client.send_get("get_run/#{@run_id}")
|
323
|
+
@description = run["description"]
|
324
|
+
@description.nil? ? [] : @description.split(",")
|
325
|
+
end
|
326
|
+
|
327
|
+
def existing_cases_from_run
|
328
|
+
|
329
|
+
tests = @client.send_get("get_tests/#{@run_id}&status_id=1,2,4,5") || []
|
330
|
+
|
331
|
+
cases = []
|
332
|
+
|
333
|
+
tests.each do |test|
|
334
|
+
|
335
|
+
cases << test["case_id"]
|
336
|
+
|
337
|
+
end
|
338
|
+
cases
|
339
|
+
end
|
340
|
+
|
341
|
+
# open a test run to submit test results
|
342
|
+
def add_testrail_run
|
343
|
+
body = {
|
344
|
+
name: test_name,
|
345
|
+
description: '',
|
346
|
+
include_all: true,
|
347
|
+
milestone_id: @milestone_id
|
348
|
+
}
|
349
|
+
|
350
|
+
unless @testrail_config[:include_all] || true
|
351
|
+
body[:include_all] = false
|
352
|
+
body[:case_ids] = @test_case_ids
|
353
|
+
end
|
354
|
+
|
355
|
+
case @suite_mode
|
356
|
+
when 2,3
|
357
|
+
body[:suite_id] = @suite_id
|
358
|
+
end
|
359
|
+
res = @client.send_post("add_run/#{@project_id}", body)
|
360
|
+
@run_id = res['id']
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
module TestResults
|
365
|
+
def send_results_to_testrail
|
366
|
+
return unless @results[:results].size != 0
|
367
|
+
# copy what is in the results
|
368
|
+
@submitted[:results] << @results[:results]
|
369
|
+
|
370
|
+
begin
|
371
|
+
send = { results: @results[:results] }
|
372
|
+
res = @client.send_post("add_results_for_cases/#{@run_id}", send)
|
373
|
+
clear_results
|
374
|
+
rescue StandardError => e
|
375
|
+
raise e
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
def update_test_suite(scenario_title, external_id, scenario_steps)
|
380
|
+
feature = external_id.split(';')[0].split('#')[0]
|
381
|
+
|
382
|
+
# if the testrail case does not exist, update cases
|
383
|
+
if testrail_test_case_id(external_id) == -1
|
384
|
+
|
385
|
+
section_id = testrail_section_id(feature)
|
386
|
+
|
387
|
+
# if the testrail section does not exist, update sections
|
388
|
+
section_id = add_testrail_section(feature) if section_id == -1
|
389
|
+
|
390
|
+
add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
|
391
|
+
sleep 1
|
392
|
+
end
|
393
|
+
# store the case id associated with the external_id
|
394
|
+
associate_result(external_id)
|
395
|
+
end
|
396
|
+
|
397
|
+
def store_result(scenario_title, external_id, scenario_steps, status_id, comment)
|
398
|
+
update_test_suite scenario_title, external_id, scenario_steps
|
399
|
+
|
400
|
+
case_id = testrail_test_case_id(external_id)
|
401
|
+
@results[:results] << {
|
402
|
+
case_id: case_id,
|
403
|
+
scenario_title: scenario_title,
|
404
|
+
external_id: external_id,
|
405
|
+
scenario_steps: scenario_steps,
|
406
|
+
status_id: status_id,
|
407
|
+
comment: comment,
|
408
|
+
custom_branch_name: @testrail_config[:origin]
|
409
|
+
}
|
410
|
+
end
|
411
|
+
end
|
10
412
|
|
11
413
|
class TestRailInterface
|
12
414
|
|
415
|
+
include Projects
|
416
|
+
include Suites
|
417
|
+
include Milestones
|
418
|
+
include Sections
|
419
|
+
include TestCases
|
420
|
+
include TestRuns
|
421
|
+
include TestResults
|
422
|
+
|
13
423
|
attr_accessor :client
|
14
424
|
attr_accessor :sections
|
15
425
|
attr_accessor :test_cases
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itriagetestrail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- a801069
|
@@ -59,7 +59,6 @@ extensions: []
|
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
61
|
- lib/itriagetestrail.rb
|
62
|
-
- lib/itriagetestrail/helpers.rb
|
63
62
|
- lib/itriagetestrail/pool.rb
|
64
63
|
- lib/itriagetestrail/testrail_binding.rb
|
65
64
|
- lib/itriagetestrail/trcucumber13.rb
|
@@ -1,405 +0,0 @@
|
|
1
|
-
module Itriagetestrail
|
2
|
-
module Projects
|
3
|
-
# populate projects instance variable with all projects objects in the testrail site
|
4
|
-
def projects
|
5
|
-
@projects ||= @client.send_get("get_projects")
|
6
|
-
end
|
7
|
-
|
8
|
-
def project_by_name(name)
|
9
|
-
res = -1
|
10
|
-
projects.each do |project|
|
11
|
-
res = project if project['name'] == name
|
12
|
-
end
|
13
|
-
res
|
14
|
-
end
|
15
|
-
|
16
|
-
# return the project object for a given project id
|
17
|
-
def project_by_id(id)
|
18
|
-
res = -1
|
19
|
-
projects.each do |project|
|
20
|
-
res = project if project['id'] == id.to_i
|
21
|
-
end
|
22
|
-
res
|
23
|
-
end
|
24
|
-
|
25
|
-
# set the project_id by a requested project from config/environment variable
|
26
|
-
def set_project
|
27
|
-
requested_id = @testrail_config[:projectId]
|
28
|
-
case requested_id
|
29
|
-
when nil, ''
|
30
|
-
# a project id was not provided, fetch it from TestRail by project name
|
31
|
-
res = project_by_name(@testrail_config[:projectName])
|
32
|
-
if res == -1
|
33
|
-
@execute = false
|
34
|
-
return
|
35
|
-
end
|
36
|
-
@project_id = res['id']
|
37
|
-
@suite_mode = res['suite_mode']
|
38
|
-
else
|
39
|
-
# use the requested project id
|
40
|
-
@project_id = requested_id
|
41
|
-
@suite_mode = project_by_id(@project_id)['suite_mode']
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
module Suites
|
47
|
-
# TestRail Suites
|
48
|
-
def testrail_suites
|
49
|
-
case @suite_mode
|
50
|
-
when 2,3
|
51
|
-
@suites = @client.send_get("get_suites/#{@project_id}")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def testrail_suite_id(suite_name)
|
56
|
-
res = -1
|
57
|
-
@suites.each do |suite|
|
58
|
-
res = suite['id'] if suite['name'] == suite_name
|
59
|
-
end
|
60
|
-
res
|
61
|
-
end
|
62
|
-
|
63
|
-
def add_testrail_suite(suite_name)
|
64
|
-
body = { name: suite_name }
|
65
|
-
res = @client.send_post("add_suite/#{@project_id}", body)
|
66
|
-
testrail_suite = res['id']
|
67
|
-
|
68
|
-
#re-establish suites
|
69
|
-
testrail_suites
|
70
|
-
|
71
|
-
testrail_suite
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
module Milestones
|
76
|
-
|
77
|
-
# Establish the milestone name based on origin passed in,
|
78
|
-
# usually origin represents a branch or environment
|
79
|
-
def normalize_milestone
|
80
|
-
case @testrail_config[:origin]
|
81
|
-
when 'prd', 'production', 'origin/production'
|
82
|
-
'Production'
|
83
|
-
when 'stg', 'staging', 'origin/staging'
|
84
|
-
'Staging'
|
85
|
-
when 'dev', 'development', 'origin/development'
|
86
|
-
'Development'
|
87
|
-
when 'local', ''
|
88
|
-
'Local'
|
89
|
-
when 'master', 'origin/master'
|
90
|
-
if @testrail_config[:masterMilestone].nil? || @testrail_config[:masterMilestone].empty?
|
91
|
-
'Master'
|
92
|
-
else
|
93
|
-
@testrail_config[:masterMilestone]
|
94
|
-
end
|
95
|
-
else
|
96
|
-
'Dev Branch'
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# returns timestamp for begining of first day of current quarter
|
101
|
-
def milestone_period_start
|
102
|
-
time_zone = TZInfo::Timezone.get('America/Denver')
|
103
|
-
current_year = time_zone.now.year
|
104
|
-
month = time_zone.now.mon
|
105
|
-
|
106
|
-
# determine which quarter we are in
|
107
|
-
if month <= 3
|
108
|
-
time_zone.utc_to_local(Time.utc(current_year, 1, 1))
|
109
|
-
elsif month <= 6
|
110
|
-
time_zone.utc_to_local(Time.utc(current_year, 4, 1))
|
111
|
-
elsif month <= 9
|
112
|
-
time_zone.utc_to_local(Time.utc(current_year, 7, 1))
|
113
|
-
else
|
114
|
-
time_zone.utc_to_local(Time.utc(current_year, 10, 1))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# determine the due date (end of quarter) for a new milestone being added
|
119
|
-
def milestone_due_date
|
120
|
-
time_zone = TZInfo::Timezone.get('America/Denver')
|
121
|
-
current_year = time_zone.now.year
|
122
|
-
month = time_zone.now.mon
|
123
|
-
|
124
|
-
# determine which quarter we are in
|
125
|
-
if month <= 3
|
126
|
-
Time.utc(current_year, 3, 31).strftime('%s')
|
127
|
-
elsif month <= 6
|
128
|
-
Time.utc(current_year, 6, 30).strftime('%s')
|
129
|
-
elsif month <= 9
|
130
|
-
Time.utc(current_year, 9, 30).strftime('%s')
|
131
|
-
else
|
132
|
-
Time.new(current_year, 12, 31).strftime('%s')
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# returns the id for a requested milestone by name, or creates one if the milestone does not exist
|
137
|
-
def fetch_milestone(requested_milestone_name)
|
138
|
-
milestones = @client.send_get("get_milestones/#{@project_id}")
|
139
|
-
res = -1
|
140
|
-
milestones.each do |milestone|
|
141
|
-
res = milestone['id'] if milestone['name'] == requested_milestone_name
|
142
|
-
end
|
143
|
-
|
144
|
-
if res == -1
|
145
|
-
# We need to add the milestone to TestRail
|
146
|
-
|
147
|
-
body = {
|
148
|
-
name: requested_milestone_name,
|
149
|
-
due_on: milestone_due_date
|
150
|
-
}
|
151
|
-
|
152
|
-
res = @client.send_post("add_milestone/#{@project_id}", body)['id']
|
153
|
-
end
|
154
|
-
res
|
155
|
-
end
|
156
|
-
|
157
|
-
# return a standardized name for a milestone to be archived
|
158
|
-
def milestone_archive_name(milestone_name, date)
|
159
|
-
year = date.year
|
160
|
-
month = date.mon
|
161
|
-
|
162
|
-
if month <= 3
|
163
|
-
"#{milestone_name} #{year}-Q1"
|
164
|
-
elsif month <= 6
|
165
|
-
"#{milestone_name} #{year}-Q2"
|
166
|
-
elsif month <= 9
|
167
|
-
"#{milestone_name} #{year}-Q3"
|
168
|
-
else
|
169
|
-
"#{milestone_name} #{year}-Q4"
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# return all the runs associated with an existing milestone
|
174
|
-
def milestone_runs(milestone_name)
|
175
|
-
# use the matching milestone id for project
|
176
|
-
milestone_id = fetch_milestone(milestone_name)
|
177
|
-
|
178
|
-
# fetch all test runs associated with the milestone id for project
|
179
|
-
@client.send_get("get_runs/#{@project_id}&milestone_id=#{milestone_id}&is_completed=1") || []
|
180
|
-
end
|
181
|
-
|
182
|
-
# testrail call to rename a milestone (for archiving)
|
183
|
-
def rename_milestone(id, new_name)
|
184
|
-
# todo: rename milestone with previous_milestone
|
185
|
-
body = { name: new_name }
|
186
|
-
res = @client.send_post("update_milestone/#{id}", body)['id']
|
187
|
-
end
|
188
|
-
|
189
|
-
# this archives a milestone at the turn of a quarter and creates a new one in its place
|
190
|
-
def reset_milestone(milestone_name)
|
191
|
-
runs = milestone_runs(milestone_name)
|
192
|
-
if runs.size > 0
|
193
|
-
last_run_time = Time.at(runs.last['completed_on'])
|
194
|
-
if last_run_time < milestone_period_start
|
195
|
-
rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
|
196
|
-
@milestone_id = fetch_milestone(@milestone_name)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
module Sections
|
203
|
-
# TestRail Sections
|
204
|
-
def testrail_sections
|
205
|
-
case @suite_mode
|
206
|
-
when 2,3
|
207
|
-
@suite_id = testrail_suite_id(@suite_name)
|
208
|
-
@sections = @client.send_get("get_sections/#{@project_id}&suite_id=#{@suite_id}")
|
209
|
-
else
|
210
|
-
@sections = @client.send_get("get_sections/#{@project_id}")
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def testrail_section_id(section_title)
|
215
|
-
res = -1
|
216
|
-
@sections.each do |section|
|
217
|
-
res = section['id'] if section['name'] == section_title
|
218
|
-
end
|
219
|
-
res
|
220
|
-
end
|
221
|
-
|
222
|
-
def add_testrail_section(section_title)
|
223
|
-
if @suite_name
|
224
|
-
body = {
|
225
|
-
name: section_title,
|
226
|
-
suite_id: testrail_suite_id(@suite_name)
|
227
|
-
}
|
228
|
-
else
|
229
|
-
body = {
|
230
|
-
name: section_title
|
231
|
-
}
|
232
|
-
end
|
233
|
-
|
234
|
-
res = @client.send_post("add_section/#{@project_id}", body)
|
235
|
-
|
236
|
-
testrail_section = res['id']
|
237
|
-
|
238
|
-
# re-establish sections
|
239
|
-
testrail_sections
|
240
|
-
|
241
|
-
testrail_section
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
module TestCases
|
246
|
-
# TestRail Cases
|
247
|
-
def testrail_ids
|
248
|
-
case @suite_mode
|
249
|
-
when 2,3
|
250
|
-
@test_cases = @client.send_get("get_cases/#{@project_id}&suite_id=#{@suite_id}&type_id=3")
|
251
|
-
else
|
252
|
-
@test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3")
|
253
|
-
end
|
254
|
-
|
255
|
-
@test_case_ids = []
|
256
|
-
|
257
|
-
@test_cases.each { |test_case| @test_case_ids << test_case['id'] }
|
258
|
-
end
|
259
|
-
|
260
|
-
def testrail_test_case_id(external_id)
|
261
|
-
res = -1
|
262
|
-
@test_cases.each do |test_case|
|
263
|
-
if test_case['custom_external_case_id'] == external_id
|
264
|
-
res = test_case['id']
|
265
|
-
end
|
266
|
-
end
|
267
|
-
res
|
268
|
-
end
|
269
|
-
|
270
|
-
def associate_result(external_id)
|
271
|
-
test_case_id = testrail_test_case_id(external_id)
|
272
|
-
# store the test case id with the local result
|
273
|
-
@results[:results].each do |result|
|
274
|
-
next unless result[:external_id] == external_id
|
275
|
-
@external_results[:results] << { case_id: test_case_id,
|
276
|
-
status_id: result['status_id'],
|
277
|
-
comment: result['comment'] }
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
# add the test case if it doesn't exist
|
282
|
-
def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
|
283
|
-
body = {
|
284
|
-
title: scenario_title,
|
285
|
-
custom_external_case_id: external_id,
|
286
|
-
custom_steps: scenario_steps,
|
287
|
-
type_id: 3
|
288
|
-
}
|
289
|
-
|
290
|
-
@client.send_post("add_case/#{section_id}", body)
|
291
|
-
|
292
|
-
# refresh test case ids
|
293
|
-
testrail_ids
|
294
|
-
end
|
295
|
-
|
296
|
-
def test_name
|
297
|
-
label = ''
|
298
|
-
label += "App Version:#{@app_version}" unless @app_version.nil? || @app_version == ''
|
299
|
-
label += " Jenkins Build:#{@jenkins_build}" unless @jenkins_build .nil? || @jenkins_build == ''
|
300
|
-
label.strip!
|
301
|
-
label = 'Regression' if label == ''
|
302
|
-
label + ' (' + @time_zone.now.strftime('%-I:%M %p') + ')'
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
module TestRuns
|
307
|
-
def extend_testrail_run
|
308
|
-
# Reset test scope to include all cases
|
309
|
-
body = { include_all: true }
|
310
|
-
@client.send_post("update_run/#{@run_id}", body)
|
311
|
-
end
|
312
|
-
|
313
|
-
def existing_cases_from_description
|
314
|
-
# Grabs from testrail run description
|
315
|
-
run = @client.send_get("get_run/#{@run_id}")
|
316
|
-
@description = run["description"]
|
317
|
-
@description.nil? ? [] : @description.split(",")
|
318
|
-
end
|
319
|
-
|
320
|
-
def existing_cases_from_run
|
321
|
-
|
322
|
-
tests = @client.send_get("get_tests/#{@run_id}&status_id=1,2,4,5") || []
|
323
|
-
|
324
|
-
cases = []
|
325
|
-
|
326
|
-
tests.each do |test|
|
327
|
-
|
328
|
-
cases << test["case_id"]
|
329
|
-
|
330
|
-
end
|
331
|
-
cases
|
332
|
-
end
|
333
|
-
|
334
|
-
# open a test run to submit test results
|
335
|
-
def add_testrail_run
|
336
|
-
body = {
|
337
|
-
name: test_name,
|
338
|
-
description: '',
|
339
|
-
include_all: true,
|
340
|
-
milestone_id: @milestone_id
|
341
|
-
}
|
342
|
-
|
343
|
-
unless @testrail_config[:include_all] || true
|
344
|
-
body[:include_all] = false
|
345
|
-
body[:case_ids] = @test_case_ids
|
346
|
-
end
|
347
|
-
|
348
|
-
case @suite_mode
|
349
|
-
when 2,3
|
350
|
-
body[:suite_id] = @suite_id
|
351
|
-
end
|
352
|
-
res = @client.send_post("add_run/#{@project_id}", body)
|
353
|
-
@run_id = res['id']
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
module TestResults
|
358
|
-
def send_results_to_testrail
|
359
|
-
return unless @results[:results].size != 0
|
360
|
-
# copy what is in the results
|
361
|
-
@submitted[:results] << @results[:results]
|
362
|
-
|
363
|
-
begin
|
364
|
-
send = { results: @results[:results] }
|
365
|
-
res = @client.send_post("add_results_for_cases/#{@run_id}", send)
|
366
|
-
clear_results
|
367
|
-
rescue StandardError => e
|
368
|
-
raise e
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
def update_test_suite(scenario_title, external_id, scenario_steps)
|
373
|
-
feature = external_id.split(';')[0].split('#')[0]
|
374
|
-
|
375
|
-
# if the testrail case does not exist, update cases
|
376
|
-
if testrail_test_case_id(external_id) == -1
|
377
|
-
|
378
|
-
section_id = testrail_section_id(feature)
|
379
|
-
|
380
|
-
# if the testrail section does not exist, update sections
|
381
|
-
section_id = add_testrail_section(feature) if section_id == -1
|
382
|
-
|
383
|
-
add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
|
384
|
-
sleep 1
|
385
|
-
end
|
386
|
-
# store the case id associated with the external_id
|
387
|
-
associate_result(external_id)
|
388
|
-
end
|
389
|
-
|
390
|
-
def store_result(scenario_title, external_id, scenario_steps, status_id, comment)
|
391
|
-
update_test_suite scenario_title, external_id, scenario_steps
|
392
|
-
|
393
|
-
case_id = testrail_test_case_id(external_id)
|
394
|
-
@results[:results] << {
|
395
|
-
case_id: case_id,
|
396
|
-
scenario_title: scenario_title,
|
397
|
-
external_id: external_id,
|
398
|
-
scenario_steps: scenario_steps,
|
399
|
-
status_id: status_id,
|
400
|
-
comment: comment,
|
401
|
-
custom_branch_name: @testrail_config[:origin]
|
402
|
-
}
|
403
|
-
end
|
404
|
-
end
|
405
|
-
end
|