class OnlyofficeTestrailWrapper::TestrailRun

@author Roman.Zagudaev Class for working with TestRun in TestRail

Attributes

assignedto_id[RW]

@return [Integer] Id of user to thom test assigned

created_on[R]

@return [Integer] time since epoch on which run created

description[RW]

@return [String] Description of test run

failed_count[RW]

@return [Integer] Count of failed tests

id[RW]

@return [Integer] Id of test run

include_all_cases[RW]

@return [Bool] parameter of including all test cases

is_completed[R]

@return [True, False] is current run completed

milestone_id[RW]

@return [Integer] Id of milestone

name[RW]

@return [String] Name of test Run

passed_count[RW]

@return [Integer] Count of passed tests

project_id[RW]

@return [Integer] Id of project

retest_count[RW]

@return [Integer] Count of retest tests

suite_id[RW]

@return [Integer] Id of test suite

test_results[RW]

@return [Array] array of arrays of TestResults

tests_names[RW]
untested_count[RW]

@return [Integer] Count of untested tests

url[R]

@return [Array] case Id's to include to run attr_accessor :case_ids @return [String] url to current test run

Public Class Methods

new(name = '', description = '', suite_id = nil, id = nil, params = {}) click to toggle source

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

add_result_by_case_id(result, case_id, comment = '', version = '') click to toggle source
# 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
close() click to toggle source
# 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
delete() click to toggle source
# 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
duration() click to toggle source

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_incomplete_tests() click to toggle source

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
get_test_by_id(id) click to toggle source
# 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
get_test_by_name(name) click to toggle source
# 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_tests() click to toggle source

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
parent_suite() click to toggle source
# 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
pull_tests_results() click to toggle source
# 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
test(name_or_id) click to toggle source
# 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
update(name = @name, description = @description) click to toggle source
# 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