class OnlyofficeTestrailWrapper::TestrailRun
@author Roman.Zagudaev Class for working with TestRun in TestRail
Attributes
@return [Integer] Id of user to thom test assigned
@return [Integer] time since epoch on which run created
@return [String] Description of test run
@return [Integer] Count of failed tests
@return [Integer] Id of test run
@return [Bool] parameter of including all test cases
@return [True, False] is current run completed
@return [Integer] Id of milestone
@return [String] Name
of test Run
@return [Integer] Count of passed tests
@return [Integer] Id of project
@return [Integer] Count of retest tests
@return [Integer] Id of test suite
@return [Array] array of arrays of TestResults
@return [Integer] Count of untested tests
@return [Array] case Id's to include to run attr_accessor :case_ids @return [String] url to current test run
Public Class Methods
Default constructor @param [Integer] id id of test, default = nil @param [String] name name of test run, default = nil @param [String] description description of test run @param [Hash] params all other params @return [TestRunTestRail] new Test run
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 51 def initialize(name = '', description = '', suite_id = nil, id = nil, params = {}) @id = id @name = name @description = description @suite_id = suite_id @tests_names = {} @test_results = [] @is_completed = params[:is_completed] end
Public Instance Methods
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 107 def add_result_by_case_id(result, case_id, comment = '', version = '') HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/add_result_for_case/#{@id}/#{case_id}", status_id: TestrailResult[result], comment: comment, version: version), TestrailResult) end
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 72 def close OnlyofficeLoggerHelper.log("Starting to send command to close run: #{@name}") test_run = HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/close_run/#{@id}", {}), TestrailRun) OnlyofficeLoggerHelper.log("Run is closed: #{@name}") test_run end
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 124 def delete @project.runs_names.delete name Testrail2.http_post "index.php?/api/v2/delete_run/#{@id}", {} OnlyofficeLoggerHelper.log "Deleted run: #{@name}" nil end
Calculate duration of all tests in current spec in hours @return [Float] duration of tests in hours
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 143 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 all incomplete test (With status 'Untested' or 'Rerun') @return [Array, TestCaseTestrail] array of test cases
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 63 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
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 90 def get_test_by_id(id) HashHelper.parse_to_class_variable(Testrail2.http_get("index.php?/api/v2/get_test/#{id}"), TestrailTest) end
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 102 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 all tests @return [Array, TestCaseTestrail] array of test cases
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 96 def get_tests tests = Testrail2.http_get "index.php?/api/v2/get_tests/#{@id}" @tests_names = HashHelper.get_hash_from_array_with_two_parameters(tests, 'title', 'id') if @tests_names.empty? tests end
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 112 def parent_suite @suite = TestrailTest.http_get "index.php?/api/v2/get_suite/#{@suite_id}" end
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 131 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
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 79 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
# File lib/onlyoffice_testrail_wrapper/testrail_run.rb, line 116 def update(name = @name, description = @description) @project.runs_names.delete @name @project.runs_names[StringHelper.warnstrip!(name.to_s)] = @id updated_plan = HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/update_run/#{@id}", name: name, description: description), TestrailRun) OnlyofficeLoggerHelper.log "Updated run: #{updated_plan.name}" updated_plan end