testrail-cucumber 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/testrail-cucumber.rb +3 -0
- data/lib/testrail-cucumber/api-client.rb +106 -0
- data/lib/testrail-cucumber/update-testrails.rb +70 -0
- data/lib/testrail-cucumber/version.rb +3 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f29e6ee50c2a1ad6a978c52c71420fba172318a5bd6fbfd82dab674cf382366e
|
4
|
+
data.tar.gz: 8789d7cb2f4fbc3e495010ffc129b4e99c9e8f083cfcc46ad9818978da8d4576
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd98efad13e1c5ccc3d66e5ba7373b2b3a3f94a2638310980c1e6a3821bf440004af3efb54ca3a065a3668153d9ae8308de4a3128d85bbe2c3121f0594ed0a37
|
7
|
+
data.tar.gz: 8adef21d64cca34f66c61f7ffb6353636ea70519711bc96b29740584454c12692f5b128284d2a4f2eda083939cb9e48a353afb73bd0cd0f8ba4f629c474faf05
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# TestRail API binding for Ruby (API v2, available since TestRail 3.0)
|
3
|
+
#
|
4
|
+
# Learn more:
|
5
|
+
#
|
6
|
+
# http://docs.gurock.com/testrail-api2/start
|
7
|
+
# http://docs.gurock.com/testrail-api2/accessing
|
8
|
+
#
|
9
|
+
# Copyright Gurock Software GmbH. See license.md for details.
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'net/http'
|
13
|
+
require 'net/https'
|
14
|
+
require 'uri'
|
15
|
+
require 'json'
|
16
|
+
|
17
|
+
module TestRail
|
18
|
+
class APIClient
|
19
|
+
@url = ''
|
20
|
+
@user = ''
|
21
|
+
@password = ''
|
22
|
+
|
23
|
+
attr_accessor :user
|
24
|
+
attr_accessor :password
|
25
|
+
|
26
|
+
def initialize(base_url)
|
27
|
+
if !base_url.match(/\/$/)
|
28
|
+
base_url += '/'
|
29
|
+
end
|
30
|
+
@url = base_url + 'index.php?/api/v2/'
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Send Get
|
35
|
+
#
|
36
|
+
# Issues a GET request (read) against the API and returns the result
|
37
|
+
# (as Ruby hash).
|
38
|
+
#
|
39
|
+
# Arguments:
|
40
|
+
#
|
41
|
+
# uri The API method to call including parameters
|
42
|
+
# (e.g. get_case/1)
|
43
|
+
#
|
44
|
+
def send_get(uri)
|
45
|
+
_send_request('GET', uri, nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Send POST
|
50
|
+
#
|
51
|
+
# Issues a POST request (write) against the API and returns the result
|
52
|
+
# (as Ruby hash).
|
53
|
+
#
|
54
|
+
# Arguments:
|
55
|
+
#
|
56
|
+
# uri The API method to call including parameters
|
57
|
+
# (e.g. add_case/1)
|
58
|
+
# data The data to submit as part of the request (as
|
59
|
+
# Ruby hash, strings must be UTF-8 encoded)
|
60
|
+
#
|
61
|
+
def send_post(uri, data)
|
62
|
+
_send_request('POST', uri, data)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def _send_request(method, uri, data)
|
67
|
+
url = URI.parse(@url + uri)
|
68
|
+
if method == 'POST'
|
69
|
+
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
70
|
+
request.body = JSON.dump(data)
|
71
|
+
else
|
72
|
+
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
73
|
+
end
|
74
|
+
request.basic_auth(@user, @password)
|
75
|
+
request.add_field('Content-Type', 'application/json')
|
76
|
+
|
77
|
+
conn = Net::HTTP.new(url.host, url.port)
|
78
|
+
if url.scheme == 'https'
|
79
|
+
conn.use_ssl = true
|
80
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
81
|
+
end
|
82
|
+
response = conn.request(request)
|
83
|
+
|
84
|
+
if response.body && !response.body.empty?
|
85
|
+
result = JSON.parse(response.body)
|
86
|
+
else
|
87
|
+
result = {}
|
88
|
+
end
|
89
|
+
|
90
|
+
if response.code != '200'
|
91
|
+
if result && result.key?('error')
|
92
|
+
error = '"' + result['error'] + '"'
|
93
|
+
else
|
94
|
+
error = 'No additional error message received'
|
95
|
+
end
|
96
|
+
raise APIError.new('TestRail API returned HTTP %s (%s)' %
|
97
|
+
[response.code, error])
|
98
|
+
end
|
99
|
+
|
100
|
+
result
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class APIError < StandardError
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative 'api-client'
|
2
|
+
|
3
|
+
module TestrailCucumber
|
4
|
+
class UpdateTestRails
|
5
|
+
attr_accessor :client
|
6
|
+
|
7
|
+
def initialize(scenario)
|
8
|
+
@scenario = scenario
|
9
|
+
|
10
|
+
if File.exist? './testrail_config.yml'
|
11
|
+
@config = YAML.load_file("./testrail_config.yml")['testrail']
|
12
|
+
raise 'TestRail configuration file not loaded successfully' if @config.nil?
|
13
|
+
else
|
14
|
+
raise 'TestRail configuration file is required'
|
15
|
+
end
|
16
|
+
|
17
|
+
setup_testrail_client
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload_result
|
21
|
+
|
22
|
+
response = {}
|
23
|
+
case_id = @scenario.name.split(' ').first.scan(/\d+/).first rescue nil
|
24
|
+
status_id = get_status_id @scenario.status
|
25
|
+
run_id = @config['run_id']
|
26
|
+
|
27
|
+
if case_id && run_id
|
28
|
+
response = client.send_post(
|
29
|
+
"add_result_for_case/#{run_id}/#{case_id}",
|
30
|
+
{ status_id: status_id }
|
31
|
+
)
|
32
|
+
else
|
33
|
+
raise 'unable to get case id or run id'
|
34
|
+
end
|
35
|
+
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_status_ids
|
40
|
+
client.send_get('get_statuses')
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def setup_testrail_client
|
46
|
+
@client = TestRail::APIClient.new(@config['url'])
|
47
|
+
@client.user = @config['user']
|
48
|
+
@client.password = @config['password']
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_status_id(status)
|
52
|
+
case status
|
53
|
+
when :passed
|
54
|
+
1
|
55
|
+
when :blocked
|
56
|
+
2
|
57
|
+
when :untested
|
58
|
+
3
|
59
|
+
when :retest
|
60
|
+
4
|
61
|
+
when :failed
|
62
|
+
5
|
63
|
+
when :undefined
|
64
|
+
raise 'missing step definition'
|
65
|
+
else
|
66
|
+
raise 'unexpected scenario status passed'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testrail-cucumber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prashanth Sams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/testrail-cucumber.rb
|
20
|
+
- lib/testrail-cucumber/api-client.rb
|
21
|
+
- lib/testrail-cucumber/update-testrails.rb
|
22
|
+
- lib/testrail-cucumber/version.rb
|
23
|
+
homepage:
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.7.8
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Sync Automation results with your testrail suite
|
47
|
+
test_files: []
|