Class: MarkTests
- Inherits:
-
Object
- Object
- MarkTests
- Defined in:
- lib/trail_marker/mark_tests.rb
Overview
Executes parsing and posting results to TestRail
Constant Summary collapse
- EXIT_MSG =
"\nYour test results have been marked on TestRails!\n"
- DEFAULT_COMMENT =
"Marked by Automation"
Instance Method Summary collapse
- #check_all_required_values ⇒ Object
- #check_create ⇒ Object
- #create_milestone ⇒ Object
- #create_testrun ⇒ Object
-
#delete_milestone ⇒ Object
USER DOES NOT HAVE PERMISSION.
-
#get_client ⇒ Object
If user name and password (or token) are passed in the command line arguments it would use those instead of the preset values.
-
#initialize(argobj, config_filename) ⇒ MarkTests
constructor
A new instance of MarkTests.
- #is_empty_or_nil?(vale) ⇒ Boolean
-
#markoff(run_ids, pid = nil) ⇒ Object
Parses the XML files and makes API calls to post results to TestRail.
-
#markoff_all_results ⇒ Object
Determine if results are for a run or a plan.
- #markoff_test_case(api_obj, result_hash, run_ids) ⇒ Object
-
#setup ⇒ Object
Initial setup - creates API client and API testrail objects.
- #show_exit_msg ⇒ Object
Constructor Details
#initialize(argobj, config_filename) ⇒ MarkTests
Returns a new instance of MarkTests.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/trail_marker/mark_tests.rb', line 8 def initialize(argobj, config_filename) @argument = argobj cf = ConfigFile.new(config_filename) if !@argument.arg_exists?('-u') || !@argument.arg_exists?('-p') cf.check_create_configfile end @user = @argument.get_arg_value('-u') == '' ? cf.username : @argument.get_arg_value('-u') @token = @argument.get_arg_value('-pw') == '' ? cf.token : @argument.get_arg_value('-pw') @url = @argument.get_arg_value('-url') == '' ? cf.testrail_url : @argument.get_arg_value('-url') @default_comment = @argument.get_arg_value('-com') == '' ? cf.default_comment : @argument.get_arg_value('-com') unless check_all_required_values puts "Missing Required Parameters, exiting." exit 0 end end |
Instance Method Details
#check_all_required_values ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trail_marker/mark_tests.rb', line 25 def check_all_required_values if is_empty_or_nil?(@user) return false end if is_empty_or_nil?(@token) return false end if is_empty_or_nil?(@url) return false end if is_empty_or_nil?(@default_comment) return false end true end |
#check_create ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/trail_marker/mark_tests.rb', line 172 def check_create project_name = @argument.get_arg_value('-p') if @argument.arg_exists?('-cm') milestone_name = @argument.get_arg_value('-cm') @api_testrail.create_milestone(project_name, milestone_name) end run_name = @argument.get_arg_value('-cr') if @argument.arg_exists?('-cr') milestone_name = @argument.get_optional_arg(['-m', '-cm']) suite_name = @argument.get_arg_value('-s') @api_testrail.create_testrun(project_name, milestone_name, run_name, suite_name) end end |
#create_milestone ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/trail_marker/mark_tests.rb', line 143 def create_milestone project_name = @argument.get_arg_value('-p') milestone_name = @argument.get_arg_value('-m') if ! milestone_name.nil? @api_testrail.create_milestone(project_name, milestone_name) end end |
#create_testrun ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/trail_marker/mark_tests.rb', line 162 def create_testrun project_name = @argument.get_arg_value('-p') milestone_name = @argument.get_optional_arg(['-m', '-cm']) testrun_name = @argument.get_arg_value('-cr') if ! testrun_name.nil? @api_testrail.create_testrun(project_name, milestone_name, testrun_name) end end |
#delete_milestone ⇒ Object
USER DOES NOT HAVE PERMISSION. Verify you have super user account or maybe not yet implemented in TestRail. GUI has no delete as well.
154 155 156 157 158 159 160 |
# File 'lib/trail_marker/mark_tests.rb', line 154 def delete_milestone project_name = @argument.get_arg_value('-p') milestone_name = @argument.get_arg_value('-dm') if ! milestone_name.nil? @api_testrail.delete_milestone(project_name, milestone_name) end end |
#get_client ⇒ Object
If user name and password (or token) are passed in the command line arguments it would use those instead of the preset values.
44 45 46 47 48 49 |
# File 'lib/trail_marker/mark_tests.rb', line 44 def get_client client = TestRail::APIClient.new(@url) client.user = @user client.password = @token return client end |
#is_empty_or_nil?(vale) ⇒ Boolean
192 193 194 |
# File 'lib/trail_marker/mark_tests.rb', line 192 def is_empty_or_nil?(vale) vale.to_s.empty? end |
#markoff(run_ids, pid = nil) ⇒ Object
Parses the XML files and makes API calls to post results to TestRail
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/trail_marker/mark_tests.rb', line 85 def markoff(run_ids, pid = nil) project_id = pid.nil? ? @api_testrail.get_project_id(@argument.get_arg_value('-p')) : pid is_dir = @argument.arg_exists?('-x') is_file = @argument.arg_exists?('-f') if is_dir || is_file results_parser = nil #results_file = nil if is_dir results_parser = ResultsParser.new(@argument.get_arg_value('-x')) results_files = results_parser.getAllXMLFiles() else specific_file = @argument.get_arg_value('-f') results_parser = ResultsParser.new(specific_file) results_files = Array.new results_files << specific_file end if results_files.size <= 0 puts "No XML Results found. Please check your directory" exit(0) end results_files.each do |one_file| case_results = results_parser.read_XML_file(one_file) if ! case_results.nil? && case_results.kind_of?(Array) case_results.each do |one_case| testrun_ids = [] testrun_ids += run_ids markoff_test_case(@api_testrail, one_case, testrun_ids) end else puts "No Results found in : #{one_file} (Might be empty)" end end end end |
#markoff_all_results ⇒ Object
Determine if results are for a run or a plan. Calls method to mark results.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/trail_marker/mark_tests.rb', line 64 def markoff_all_results mark_type = 'testrun' runner = @argument.get_optional_arg(['-r', '-cr']) if runner.nil? || runner == "" mark_type = "testplan" runner = @argument.get_optional_arg(['-t', '-ct']) end run_ids = [] project_id = @api_testrail.get_project_id(@argument.get_arg_value('-p')) case mark_type when "testrun" run_name = @argument.get_optional_arg(['-r', '-cr']) run_ids << @api_testrail.get_test_runplan_id(project_id, run_name) when "testplan" plan_name = @argument.get_optional_arg(['-t', '-ct']) run_ids = @api_testrail.get_testplan_run_ids(project_id, plan_name) end markoff(run_ids, project_id) end |
#markoff_test_case(api_obj, result_hash, run_ids) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/trail_marker/mark_tests.rb', line 122 def markoff_test_case(api_obj, result_hash, run_ids) case_id = result_hash[:trail_case].gsub(/[Cc]/, "") test_id = nil run_id = nil puts "=====> #{run_ids}" if run_ids.size > 1 run_ids.each do |rid| tempid = api_obj.get_testid(rid, case_id) if ! tempid.nil? test_id = tempid run_id = rid break end end else run_id = run_ids.pop() end passed = result_hash[:passed] api_obj.markoff_test(case_id, run_id, passed, @default_comment) end |
#setup ⇒ Object
Initial setup - creates API client and API testrail objects
53 54 55 56 57 58 |
# File 'lib/trail_marker/mark_tests.rb', line 53 def setup if @client.nil? || @api_testrail.nil? @client = get_client @api_testrail = ApiTestRail.new(@client) end end |
#show_exit_msg ⇒ Object
186 187 188 189 190 |
# File 'lib/trail_marker/mark_tests.rb', line 186 def show_exit_msg puts "\n#{EXIT_MSG}\n" puts "TestRail Marker exit code: 0" exit 0 end |