Class: OnlyofficeTestrailWrapper::TestrailHelper

Inherits:
Object
  • Object
show all
Includes:
RubyHelper, TestrailHelperRspecMetadata, TestrailStatusHelper
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_helper.rb

Overview

Class with help methods with testrail

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TestrailStatusHelper

#check_status_exist

Methods included from TestrailHelperRspecMetadata

#example_time_in_seconds, #init_custom_fields, #parse_pending_comment, #screenshot_link

Methods included from RubyHelper

#debug?

Constructor Details

#initialize(project_name, suite_name = nil, plan_name = nil, run_name = nil) {|_self| ... } ⇒ TestrailHelper

Returns a new instance of TestrailHelper.

Yields:

  • (_self)

Yield Parameters:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 19

def initialize(project_name, suite_name = nil, plan_name = nil, run_name = nil)
  @in_debug = debug?
  begin
    @bugzilla_helper = OnlyofficeBugzillaHelper::BugzillaHelper.new
  rescue Errno::ENOENT
    @bugzilla_helper = nil
  end
  if @in_debug
    OnlyofficeLoggerHelper.log 'Do not initialize Testrail, because spec run in debug'
    @run = TestrailRun.new
    return
  end
  OnlyofficeLoggerHelper.log 'Begin initializing Testrail...'
  @suites_to_add = []
  @add_all_suites = true
  @search_plan_by_substring = false
  yield(self) if block_given?
  @project = Testrail2.new.project project_name.to_s.dup
  if plan_name
    @plan = @project.get_plan_by_name(search_plan_by_substring ? get_plan_name_by_substring(plan_name.to_s) : plan_name.to_s)
    @plan ||= @project.create_new_plan(plan_name, suites_to_add_hash(@add_all_suites ? all_suites_names : @suites_to_add))
  end
  return if suite_name.nil?

  @suite = @project.suite suite_name.to_s
  if @plan
    init_run_in_plan(suite_name.to_s)
  else
    @run = @project.init_run_by_name(run_name ? run_name.to_s : suite_name.to_s, @suite.id)
  end
  raise "Plan '#{@plan.name}' is completed! Cannot add results. See #{@plan.url}" if !@plan.nil? && @plan.is_completed

  OnlyofficeLoggerHelper.log 'Initializing complete!'
end

Instance Attribute Details

#add_all_suitesObject

Returns the value of attribute add_all_suites.



17
18
19
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17

def add_all_suites
  @add_all_suites
end

#ignore_parametersObject

Returns the value of attribute ignore_parameters.



17
18
19
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17

def ignore_parameters
  @ignore_parameters
end

#in_debugObject

Returns the value of attribute in_debug.



17
18
19
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17

def in_debug
  @in_debug
end

#planObject (readonly)

Returns the value of attribute plan.



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

def plan
  @plan
end

#projectObject (readonly)

Returns the value of attribute project.



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

def project
  @project
end

#runObject (readonly)

Returns the value of attribute run.



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

def run
  @run
end

#search_plan_by_substringObject

Returns the value of attribute search_plan_by_substring.



17
18
19
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17

def search_plan_by_substring
  @search_plan_by_substring
end

#suiteObject (readonly)

Returns the value of attribute suite.



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

def suite
  @suite
end

#suites_to_addObject

Returns the value of attribute suites_to_add.



17
18
19
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17

def suites_to_add
  @suites_to_add
end

#versionObject

Returns the value of attribute version.



17
18
19
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17

def version
  @version
end

Instance Method Details

#add_cases_to_suite(cases, section_name = 'All Test Cases') ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 54

def add_cases_to_suite(cases, section_name = 'All Test Cases')
  if @in_debug
    OnlyofficeLoggerHelper.log 'Do not add test result, because spec run in debug '
    return
  end
  OnlyofficeLoggerHelper.log "Begin scanning #{@suite.name} suite for new cases" unless cases.is_a?(Array)
  section = @suite.section section_name.to_s
  existing_cases = section.get_cases.map { |test_case| test_case['title'] }
  cases.each { |case_name| section.create_new_case case_name.to_s unless existing_cases.include?(case_name) }
  OnlyofficeLoggerHelper.log 'Suite scanning complete!'
  @suite = @project.get_suite_by_id @suite.id
end

#add_result_by_case_name(name, result, comment = 'ok', section_name = 'All Test Cases') ⇒ Object



117
118
119
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 117

def add_result_by_case_name(name, result, comment = 'ok', section_name = 'All Test Cases')
  @suite.section(section_name).case(name.to_s).add_result(@run.id, result, comment)
end

#add_result_to_test_case(example, comment = '', section_name = 'All Test Cases') ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 67

def add_result_to_test_case(example, comment = '', section_name = 'All Test Cases')
  if @in_debug
    OnlyofficeLoggerHelper.log 'Do not add test result, because spec run in debug '
    return
  end
  exception = example.exception
  custom_fields = init_custom_fields(example)
  if @ignore_parameters && (ignored_hash = ignore_case?(example.))
    comment += "\nTest ignored by #{ignored_hash}"
    result = :blocked
  elsif example.pending
    result, comment, bug_id = parse_pending_comment(example.execution_result.pending_message)
    if example.exception.to_s == 'Expected example to fail since it is pending, but it passed.'
      result = :failed
      comment = "Test passed! #{comment}"
    end
    custom_fields[:defects] = bug_id.to_s
    example.add_custom_exception(comment) if result == :failed
    result = :lpv if comment.downcase.include?('limited program version')
  elsif exception.to_s.include?('got:') || exception.to_s.include?('expected:')
    result = :failed
    failed_line = RspecHelper.find_failed_line(example)
    comment += "\n#{exception.to_s.gsub('got:', "got:\n").gsub('expected:', "expected:\n")}\nIn line:\n#{failed_line}"
  elsif exception.to_s.include?('to return') || exception.to_s.include?('expected')
    result = :failed
    comment += "\n#{exception.to_s.gsub('to return ', "to return:\n").gsub(', got ', "\ngot:\n")}"
  elsif exception.to_s.include?('Service Unavailable')
    result = :service_unavailable
    comment += "\n#{exception}"
  elsif exception.to_s.include?('Limited program version')
    result = :lpv
    comment += "\n#{exception}"
  elsif exception.nil?
    result = if @last_case == example.description
               :passed_2
             elsif custom_fields.key?(:custom_js_error)
               :js_error
             else
               :passed
             end
    comment += "\nOk"
  else
    result = :aborted
    comment += "\n#{exception}"
    custom_fields[:custom_autotest_error_line] = exception.backtrace.join("\n") unless exception.backtrace.nil?
  end
  @last_case = example.description
  @suite.section(section_name).case(example.description).add_result @run.id, result, comment, custom_fields
end

#delete_plan(plan_name) ⇒ Object



132
133
134
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 132

def delete_plan(plan_name)
  @project.plan(get_plan_name_by_substring(plan_name.to_s)).delete
end

#get_incomplete_testsObject



121
122
123
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 121

def get_incomplete_tests
  @run.get_tests.map { |test| test['title'] if test['status_id'] == 3 || test['status_id'] == 4 }.compact
end

#get_tests_by_result(result) ⇒ Object

Parameters:

  • result. (Array)

    Example: [:retest, :passed]



126
127
128
129
130
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 126

def get_tests_by_result(result)
  check_status_exist(result)
  result = [result] unless result.is_a?(Array)
  @run.get_tests.map { |test| test['title'] if result.include?(TestrailResult::RESULT_STATUSES.key(test['status_id'])) }.compact
end

#mark_rest_environment_dependencies(supported_test_list, status_to_mark = :lpv) ⇒ Object



136
137
138
139
140
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 136

def mark_rest_environment_dependencies(supported_test_list, status_to_mark = :lpv)
  get_incomplete_tests.each do |current_test|
    add_result_by_case_name(current_test, status_to_mark, 'Not supported on this test environment') unless supported_test_list.include?(current_test)
  end
end