Class: OnlyofficeTestrailWrapper::TestrailRun
- Inherits:
-
TestrailApiObject
- Object
- TestrailApiObject
- OnlyofficeTestrailWrapper::TestrailRun
- Defined in:
- lib/onlyoffice_testrail_wrapper/testrail_run.rb
Overview
Class for working with TestRun in TestRail
Instance Attribute Summary collapse
-
#assignedto_id ⇒ Integer
Id of user to thom test assigned.
-
#created_on ⇒ Integer
readonly
Time since epoch on which run created.
-
#description ⇒ String
Description of test run.
-
#failed_count ⇒ Integer
Count of failed tests.
-
#id ⇒ Integer
Id of test run.
-
#include_all_cases ⇒ Bool
Parameter of including all test cases.
-
#is_completed ⇒ True, False
readonly
Is current run completed.
-
#milestone_id ⇒ Integer
Id of milestone.
-
#name ⇒ String
Name of test Run.
-
#passed_count ⇒ Integer
Count of passed tests.
-
#project_id ⇒ Integer
Id of project.
-
#retest_count ⇒ Integer
Count of retest tests.
-
#suite_id ⇒ Integer
Id of test suite.
-
#test_results ⇒ Array
Array of arrays of TestResults.
-
#tests_names ⇒ Object
Returns the value of attribute tests_names.
-
#untested_count ⇒ Integer
Count of untested tests.
-
#url ⇒ Array, String
readonly
attr_accessor :case_ids.
Instance Method Summary collapse
- #add_result_by_case_id(result, case_id, comment = '', version = '') ⇒ Object
- #close ⇒ Object
- #delete ⇒ Object
-
#duration ⇒ Float
Calculate duration of all tests in current spec in hours.
-
#get_incomplete_tests ⇒ Array, TestCaseTestrail
Get all incomplete test (With status ‘Untested’ or ‘Rerun’).
- #get_test_by_id(id) ⇒ Object
- #get_test_by_name(name) ⇒ Object
-
#get_tests ⇒ Array, TestCaseTestrail
Get all tests.
-
#initialize(name = '', description = '', suite_id = nil, id = nil, params = {}) ⇒ TestRunTestRail
constructor
Default constructor.
- #parent_suite ⇒ Object
- #pull_tests_results ⇒ Object
- #test(name_or_id) ⇒ Object
- #update(name = @name, description = @description) ⇒ Object
Methods inherited from TestrailApiObject
#init_from_hash, #name_id_pairs
Constructor Details
#initialize(name = '', description = '', suite_id = nil, id = nil, params = {}) ⇒ TestRunTestRail
Default constructor
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 51 def initialize(name = '', description = '', suite_id = nil, id = nil, params = {}) super() @id = id @name = name @description = description @suite_id = suite_id @tests_names = {} @test_results = [] @is_completed = params[:is_completed] end |
Instance Attribute Details
#assignedto_id ⇒ Integer
Returns Id of user to thom test assigned.
22 23 24 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 22 def assignedto_id @assignedto_id end |
#created_on ⇒ Integer (readonly)
Returns time since epoch on which run created.
41 42 43 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 41 def created_on @created_on end |
#description ⇒ String
Returns Description of test run.
18 19 20 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 18 def description @description end |
#failed_count ⇒ Integer
Returns Count of failed tests.
26 27 28 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 26 def failed_count @failed_count end |
#id ⇒ Integer
Returns Id of test run.
12 13 14 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 12 def id @id end |
#include_all_cases ⇒ Bool
Returns parameter of including all test cases.
24 25 26 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 24 def include_all_cases @include_all_cases end |
#is_completed ⇒ True, False (readonly)
Returns is current run completed.
43 44 45 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 43 def is_completed @is_completed end |
#milestone_id ⇒ Integer
Returns Id of milestone.
20 21 22 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 20 def milestone_id @milestone_id end |
#name ⇒ String
Returns Name of test Run.
10 11 12 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 10 def name @name end |
#passed_count ⇒ Integer
Returns Count of passed tests.
32 33 34 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 32 def passed_count @passed_count end |
#project_id ⇒ Integer
Returns Id of project.
16 17 18 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 16 def project_id @project_id end |
#retest_count ⇒ Integer
Returns Count of retest tests.
30 31 32 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 30 def retest_count @retest_count end |
#suite_id ⇒ Integer
Returns Id of test suite.
14 15 16 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 14 def suite_id @suite_id end |
#test_results ⇒ Array
Returns array of arrays of TestResults.
39 40 41 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 39 def test_results @test_results end |
#tests_names ⇒ Object
Returns the value of attribute tests_names.
37 38 39 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 37 def tests_names @tests_names end |
#untested_count ⇒ Integer
Returns Count of untested tests.
28 29 30 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 28 def untested_count @untested_count end |
#url ⇒ Array, String (readonly)
attr_accessor :case_ids
36 37 38 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 36 def url @url end |
Instance Method Details
#add_result_by_case_id(result, case_id, comment = '', version = '') ⇒ Object
108 109 110 111 112 113 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 108 def add_result_by_case_id(result, case_id, comment = '', version = '') TestrailResult.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_result_for_case/#{@id}/#{case_id}", status_id: TestrailResult[result], comment: comment, version: version)) end |
#close ⇒ Object
73 74 75 76 77 78 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 73 def close OnlyofficeLoggerHelper.log("Starting to send command to close run: #{@name}") test_run = TestrailRun.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/close_run/#{@id}", {})) OnlyofficeLoggerHelper.log("Run is closed: #{@name}") test_run end |
#delete ⇒ Object
129 130 131 132 133 134 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 129 def delete @project.runs_names.delete name Testrail2.http_post "index.php?/api/v2/delete_run/#{@id}", {} OnlyofficeLoggerHelper.log "Deleted run: #{@name}" nil end |
#duration ⇒ Float
Calculate duration of all tests in current spec in hours
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 148 def duration pull_tests_results test_results_date_array = [] @test_results.each_value do |test_result_sets| test_result_sets.each do |test_result| test_results_date_array << test_result.created_on end end ((test_results_date_array.max - test_results_date_array.min).to_f / (60 * 60)).round(2) end |
#get_incomplete_tests ⇒ Array, TestCaseTestrail
Get all incomplete test (With status ‘Untested’ or ‘Rerun’)
64 65 66 67 68 69 70 71 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 64 def get_incomplete_tests incomplete_tests = [] get_tests.each do |test| incomplete_tests << test if test.status_id == TestrailResult::RESULT_STATUSES[:retest] || test.status_id == TestrailResult::RESULT_STATUSES[:untested] end incomplete_tests end |
#get_test_by_id(id) ⇒ Object
91 92 93 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 91 def get_test_by_id(id) TestrailTest.new.init_from_hash(Testrail2.http_get("index.php?/api/v2/get_test/#{id}")) end |
#get_test_by_name(name) ⇒ Object
103 104 105 106 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 103 def get_test_by_name(name) get_tests if @tests_names.empty? @tests_names[StringHelper.warnstrip!(name.to_s.dup)].nil? ? nil : get_test_by_id(@tests_names[name]) end |
#get_tests ⇒ Array, TestCaseTestrail
Get all tests
97 98 99 100 101 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 97 def get_tests tests = Testrail2.http_get "index.php?/api/v2/get_tests/#{@id}" @tests_names = name_id_pairs(tests, 'title') if @tests_names.empty? tests end |
#parent_suite ⇒ Object
115 116 117 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 115 def parent_suite @suite = TestrailTest.http_get "index.php?/api/v2/get_suite/#{@suite_id}" end |
#pull_tests_results ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 136 def pull_tests_results @test_results = {} all_tests = get_tests all_tests.each do |current_test| test_data = test(current_test['id']) @test_results.merge!(test_data.title => test_data.get_results) end OnlyofficeLoggerHelper.log "Get test results for run: #{@name}" end |
#test(name_or_id) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 80 def test(name_or_id) case name_or_id.class.to_s when 'Fixnum', 'Integer' get_test_by_id name_or_id when 'String' get_test_by_name name_or_id else raise 'Wrong argument. Must be name [String] or id [Integer]' end end |
#update(name = @name, description = @description) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 119 def update(name = @name, description = @description) @project.runs_names.delete @name @project.runs_names[StringHelper.warnstrip!(name.to_s)] = @id updated_plan = TestrailRun.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/update_run/#{@id}", name: name, description: description)) OnlyofficeLoggerHelper.log "Updated run: #{updated_plan.name}" updated_plan end |