Class: OnlyofficeTestrailWrapper::TestrailRun

Inherits:
TestrailApiObject show all
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_run.rb

Overview

Class for working with TestRun in TestRail

Author:

  • Roman.Zagudaev

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TestrailApiObject

#init_from_hash, #name_id_pairs

Constructor Details

#initialize(name = '', description = '', suite_id = nil, id = nil, params = {}) ⇒ TestRunTestRail

Default constructor

Parameters:

  • id (Integer) (defaults to: nil)

    id of test, default = nil

  • name (String) (defaults to: '')

    name of test run, default = nil

  • description (String) (defaults to: '')

    description of test run

  • params (Hash) (defaults to: {})

    all other params



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_idInteger

Returns Id of user to thom test assigned.

Returns:

  • (Integer)

    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_onInteger (readonly)

Returns time since epoch on which run created.

Returns:

  • (Integer)

    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

#descriptionString

Returns Description of test run.

Returns:

  • (String)

    Description of test run



18
19
20
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 18

def description
  @description
end

#failed_countInteger

Returns Count of failed tests.

Returns:

  • (Integer)

    Count of failed tests



26
27
28
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 26

def failed_count
  @failed_count
end

#idInteger

Returns Id of test run.

Returns:

  • (Integer)

    Id of test run



12
13
14
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 12

def id
  @id
end

#include_all_casesBool

Returns parameter of including all test cases.

Returns:

  • (Bool)

    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_completedTrue, False (readonly)

Returns is current run completed.

Returns:

  • (True, False)

    is current run completed



43
44
45
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 43

def is_completed
  @is_completed
end

#milestone_idInteger

Returns Id of milestone.

Returns:

  • (Integer)

    Id of milestone



20
21
22
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 20

def milestone_id
  @milestone_id
end

#nameString

Returns Name of test Run.

Returns:

  • (String)

    Name of test Run



10
11
12
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 10

def name
  @name
end

#passed_countInteger

Returns Count of passed tests.

Returns:

  • (Integer)

    Count of passed tests



32
33
34
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 32

def passed_count
  @passed_count
end

#project_idInteger

Returns Id of project.

Returns:

  • (Integer)

    Id of project



16
17
18
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 16

def project_id
  @project_id
end

#retest_countInteger

Returns Count of retest tests.

Returns:

  • (Integer)

    Count of retest tests



30
31
32
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 30

def retest_count
  @retest_count
end

#suite_idInteger

Returns Id of test suite.

Returns:

  • (Integer)

    Id of test suite



14
15
16
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 14

def suite_id
  @suite_id
end

#test_resultsArray

Returns array of arrays of TestResults.

Returns:

  • (Array)

    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_namesObject

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_countInteger

Returns Count of untested tests.

Returns:

  • (Integer)

    Count of untested tests



28
29
30
# File 'lib/onlyoffice_testrail_wrapper/testrail_run.rb', line 28

def untested_count
  @untested_count
end

#urlArray, String (readonly)

attr_accessor :case_ids

Returns:

  • (Array)

    case Id’s to include to run

  • (String)

    url to current test run



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

#closeObject



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

#deleteObject



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

#durationFloat

Calculate duration of all tests in current spec in hours

Returns:

  • (Float)

    duration of tests 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_testsArray, TestCaseTestrail

Get all incomplete test (With status ‘Untested’ or ‘Rerun’)

Returns:

  • (Array, TestCaseTestrail)

    array of test cases



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_testsArray, TestCaseTestrail

Get all tests

Returns:

  • (Array, TestCaseTestrail)

    array of test cases



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_suiteObject



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_resultsObject



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