tms-cli 0.0.pre.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../testrail/testrail'
4
+ require_relative '../testrail/testcase'
5
+
6
+ module Tms
7
+ module Flutter
8
+ module_function
9
+
10
+ include Testcase
11
+
12
+ # This method will collect test title, refs, and test status from json report
13
+ # and then validate the test title and refs
14
+ # On Flutter, the data able to get from json object 'testResults'
15
+ def import_data(client, project_id, suite_id, section_id, report_data_hash, tr_version)
16
+ report_data_hash['testResults'].map do |test_results|
17
+ test_results['testResults'].map do |test_result|
18
+ title = test_result['title'].tr('"', "'")[0..249]
19
+ next if title.eql? 'placeholder'
20
+
21
+ if title.include?(':')
22
+ group_name = title.split(':')[0].split(' ')
23
+ group_name.pop
24
+ tc_name = title.split(':')[1].strip
25
+ test_title = "[#{group_name.join(' ')}] #{tc_name}"
26
+ refs = title.split(':')[0].split(' ').last.strip
27
+ else
28
+ test_title = title
29
+ refs = ''
30
+ end
31
+ test_status = test_result['status']
32
+ test_status_id = Testcase.get_status_id(test_status)
33
+ error_comment = test_result['failureMessages']
34
+
35
+ Testcase.validate_testcase(client, section_id, test_title, test_status_id, refs, tr_version, error_comment)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../testrail/testrail'
4
+ require_relative '../testrail/testcase'
5
+
6
+ module Tms
7
+ module Golang
8
+ module_function
9
+
10
+ include Testcase
11
+
12
+ def import_data(client, project_id, suite_id, section_id, report_data_hash, tr_version)
13
+ report_data_hash.map do |test_result|
14
+ next if test_result['Elapsed'].nil? || test_result['Test'].nil?
15
+
16
+ next if test_result['Test'].split('/').size.eql?(1)
17
+
18
+ test_title = test_result['Test'].split('/').last.gsub('_', ' ').split(':')
19
+ refs = ''
20
+ test_status = test_result['Action']
21
+ if test_title.size.eql?(1)
22
+ tc_title = test_title.first.strip
23
+ else
24
+ tc_title = test_title.last.strip
25
+ tmp_refs = test_title.first.strip
26
+ refs = tmp_refs if Testcase.validate_refs(tmp_refs)
27
+ end
28
+
29
+ case test_status
30
+ when 'pass'
31
+ test_status = test_status.gsub('pass', 'passed')
32
+ error_comment = ''
33
+ when 'fail'
34
+ test_status = test_status.gsub('fail', 'failed')
35
+ report_data_hash.map do |err|
36
+ next unless (err['Test'].to_s.include? test_result['Test']) && err['Output'].to_s.include?('Error:')
37
+ error_comment = err['Output'].split('Error:').last.gsub('\\', ' ')
38
+ end
39
+ end
40
+
41
+ test_status_id = Testcase.get_status_id(test_status)
42
+
43
+ Testcase.validate_testcase(client, section_id, tc_title, test_status_id, refs, tr_version, error_comment)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../testrail/testrail'
4
+ require_relative '../testrail/testcase'
5
+
6
+ module Tms
7
+ module Jest
8
+ module_function
9
+
10
+ include Testcase
11
+
12
+ def import_data(client, project_id, suite_id, section_id, report_data_hash, tr_version)
13
+ if !report_data_hash['testResults'][0]['assertionResults'].nil?
14
+ jest_from_cli(client, section_id, report_data_hash, tr_version)
15
+ else
16
+ jest_from_module(client, section_id, report_data_hash, tr_version)
17
+ end
18
+ end
19
+
20
+ def jest_from_cli(client, section_id, report_data_hash, tr_version)
21
+ report_data_hash['testResults'].map do |test_results|
22
+ test_results['assertionResults'].map do |test_result|
23
+ refs = ''
24
+ if test_result['ancestorTitles'].size == 1
25
+ refs_validation = test_result['ancestorTitles'][0].include?(':') && test_result['ancestorTitles'][0].include?('-')
26
+ refs = test_result['ancestorTitles'][0].split(':')[0].strip if refs_validation
27
+ else
28
+ tmp_ref = []
29
+ test_result['ancestorTitles'].map do |str|
30
+ tmp_ref.push(str.split(':')[0].strip) if str.include?(':') && str.split(':')[0].strip.include?('-')
31
+ end
32
+ refs = if tmp_ref.size == 1
33
+ tmp_ref[0]
34
+ elsif tmp_ref.size > 1
35
+ tmp_ref.uniq.join(',')
36
+ end
37
+ end
38
+
39
+ test_title = test_result['title'].tr('"', "'")
40
+ test_title = test_result['fullName'] if test_title == ''
41
+ test_title = test_title.gsub("\n", '').gsub(/[{}<>=]/, '')[0..249]
42
+ test_status = test_result['status']
43
+ error_comment = test_result['failureMessages']
44
+ test_status_id = Testcase.get_status_id(test_status)
45
+
46
+ Testcase.validate_testcase(client, section_id, test_title, test_status_id, refs, tr_version, error_comment)
47
+ end
48
+ end
49
+ end
50
+
51
+ def jest_from_module(client, section_id, report_data_hash, tr_version)
52
+ report_data_hash['testResults'].map do |test_results|
53
+ test_results['testResults'].map do |result|
54
+ refs = ''
55
+ if result['ancestorTitles'].size == 1
56
+ refs_validation = result['ancestorTitles'][0].include?(':') && result['ancestorTitles'][0].include?('-')
57
+ refs = result['ancestorTitles'][0].split(':')[0].strip if refs_validation
58
+ else
59
+ tmp_ref = []
60
+ result['ancestorTitles'].map do |str|
61
+ tmp_ref.push(str.split(':')[0].strip) if str.include?(':') && Testcase.validate_refs(str.split(':')[0].strip)
62
+ end
63
+ refs = if tmp_ref.size == 1
64
+ tmp_ref[0]
65
+ elsif tmp_ref.size > 1
66
+ tmp_ref.uniq.join(',')
67
+ end
68
+ end
69
+ test_title = result['title'].tr('"', "'")
70
+ test_title = test_result['fullName'] if test_title == ''
71
+ test_title = test_title.gsub("\n", '').gsub(/[{}<>=]/, '')[0..249]
72
+ test_status = result['status']
73
+ test_status_id = Testcase.get_status_id(test_status)
74
+ error_comment = result['failureMessages']
75
+
76
+ Testcase.validate_testcase(client, section_id, test_title, test_status_id, refs, tr_version, error_comment)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../testrail/testrail'
4
+ require_relative '../testrail/testcase'
5
+ require 'nokogiri'
6
+
7
+ module Tms
8
+ module JUnit
9
+ module_function
10
+
11
+ include Testcase
12
+
13
+ def convert_to_hash(xml_file)
14
+ # Parse the XML file using Nokogiri
15
+ doc = Nokogiri::XML(File.open(xml_file))
16
+
17
+ # Create a new array
18
+ results = []
19
+
20
+ # Iterate over the <testcase> elements in the XML document
21
+ doc.xpath("//testcase").each do |testcase|
22
+ # New Hashmap
23
+ test_result = {}
24
+
25
+ # Extract the test case name and add it to the hash map
26
+ suite_name = testcase.attributes["classname"]
27
+ test_name = testcase.attributes["name"].value
28
+
29
+ # Get jira id in the test class name if any
30
+ # Pattern: keyid_testname (ex: intnl_778_validateRegistrationPage)
31
+ # Can't use "-" in the test class name of kotlin
32
+ # TODO: Get better implemantation and support multiple jira id
33
+ parts = test_name.split("_")
34
+
35
+ if parts.length > 2
36
+ test_result["jiraId"] = "#{parts[0]}-#{parts[1]}"
37
+ test_name = parts[2]
38
+ end
39
+
40
+ test_result["name"] = "#{suite_name} #{test_name}"
41
+
42
+ # Default value for test status
43
+ test_result["status"] = "passed"
44
+
45
+ # Iterate over the child elements of the <testcase> element
46
+ # and add their contents to the hash map
47
+ testcase.children.each do |child|
48
+ # Remap status according to child element
49
+ if child.name == "failure"
50
+ test_result["status"] = "failed"
51
+ test_result[child.name] = child.text
52
+ elsif child.name == "skipped"
53
+ test_result["status"] = "pending"
54
+ end
55
+ end
56
+
57
+ results.push(test_result)
58
+ end
59
+
60
+ return results
61
+ end
62
+
63
+ def import_data(client, project_id, suite_id, section_id, xml_file, tr_version)
64
+ report_data_hash = self.convert_to_hash(xml_file)
65
+ report_data_hash.map do |result|
66
+ test_title = result['name']
67
+ test_status = result['status']
68
+ test_status_id = Testcase.get_status_id(test_status)
69
+ error_comment = result['failure'] || ''
70
+ refs = result['jiraId'] || ''
71
+
72
+ Testcase.validate_testcase(client, section_id, test_title, test_status_id, refs, tr_version, error_comment)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../testrail/testrail'
4
+ require_relative '../testrail/testcase'
5
+
6
+ module Tms
7
+ module Rspec
8
+ module_function
9
+
10
+ include Testcase
11
+
12
+ def import_data(client, project_id, suite_id, section_id, report_data_hash, tr_version)
13
+ report_data_hash['examples'].map do |test_result|
14
+ full_description = test_result['full_description']
15
+ next if full_description.split(' ').nil? || full_description.split(' ').size < 2
16
+
17
+ refs = ''
18
+ tmp_ref = full_description.split(' ')[1].strip.gsub(':', '')
19
+ if tmp_ref.split(',').size > 1
20
+ tmp = []
21
+ tmp_ref.split(',').each do |ref|
22
+ tmp.push(ref) if Testcase.validate_refs(ref)
23
+ end
24
+ refs = tmp.uniq.join(',')
25
+ else
26
+ refs = tmp_ref if Testcase.validate_refs(tmp_ref)
27
+ end
28
+ test_title = full_description.gsub(refs, '').tr('"', "'")[0..249].gsub(/\p{So}/, '').strip
29
+ test_status = test_result['status']
30
+ test_status_id = Testcase.get_status_id(test_status)
31
+ error_comment = test_result['exception']
32
+ Testcase.validate_testcase(client, section_id, test_title, test_status_id, refs, tr_version, error_comment)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'jira-ruby'
2
+ require 'rest-client'
3
+
4
+ module Tms
5
+ module JiraAPI
6
+ module_function
7
+
8
+ def jira_auth
9
+ {
10
+ username: ENV['ATLASSIAN_EMAIL'],
11
+ password: ENV['ATLASSIAN_TOKEN'],
12
+ site: 'https://tutuplapak.atlassian.net',
13
+ context_path: '',
14
+ auth_type: :basic,
15
+ read_timeout: 120
16
+ }
17
+ end
18
+
19
+ def get_issue_details(issue_key)
20
+ client = JIRA::Client.new(jira_auth)
21
+ client.Issue.find(issue_key)
22
+ end
23
+
24
+ def get_attachment_content(attachment_url)
25
+ client = JIRA::Client.new(jira_auth)
26
+
27
+ response = RestClient::Request.execute(
28
+ method: :get,
29
+ url: attachment_url,
30
+ headers: {
31
+ Authorization: "Basic #{Base64.strict_encode64("#{jira_auth[:username]}:#{jira_auth[:password]}")}"
32
+ }
33
+ )
34
+ response.body
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,48 @@
1
+ module JiraIssues
2
+ module_function
3
+
4
+ def get_hash_ac(ac_field)
5
+ # Join each row and remove extra spaces
6
+ markdown_table = ac_field.gsub(/\n\s*/, '')
7
+
8
+ # Extract headers
9
+ headers = markdown_table.split("||")[0..4].reject(&:empty?).map { |element| element.gsub("*", "") }
10
+
11
+ # Split the table into rows based on "*[" as delimiter of each line
12
+ rows = markdown_table.split("|*[")
13
+
14
+ # Create an array to store the hash representation of each row
15
+ table_data = []
16
+
17
+ # Process each row and convert it to a hash
18
+ rows.each_with_index do |row, index|
19
+ row_values = row.split(/\|(?!width=)/)
20
+
21
+ next if row_values.empty?
22
+
23
+ # Ensure each row has the symbol | five times
24
+ row_values = row_values[0..4]
25
+
26
+ row_hash = Hash[headers.zip(row_values)]
27
+ table_data << row_hash
28
+ end
29
+
30
+ # Return the hash AC
31
+ return table_data.drop(1)
32
+ end
33
+
34
+ def hash_to_feature(hash, ref)
35
+ test_title = hash["Title"]
36
+ project_name = test_title.split("][").first.gsub(/\s+/, '_')
37
+ steps = hash["Steps"].split(/(?=\*Given\*|\*When\*|\*Then\*|\*And\*)/).map(&:strip)
38
+ steps.map! { |step| step.gsub(/\*(Given|When|Then|And)\*/, '\1') }
39
+
40
+ has_attachments = !hash["Attachments"].nil? && !hash["Attachments"].empty?
41
+
42
+ feature_file = "@#{ref}\nFeature: #{test_title[/\bAC.*\b/]}\n\t"
43
+ feature_file += "@#{ref} \n\tScenario: #{test_title[/\bAC.*\b/]}\n\t\t"
44
+ feature_file += steps.join("\n\t\t")
45
+
46
+ return feature_file, project_name
47
+ end
48
+ end