Class: OnlyofficeTestrailWrapper::TestrailHelper
- Inherits:
-
Object
- Object
- OnlyofficeTestrailWrapper::TestrailHelper
- Includes:
- RubyHelper, TestrailHelperRspecMetadata
- Defined in:
- lib/onlyoffice_testrail_wrapper/testrail_helper.rb
Overview
Class with help methods with testrail
Instance Attribute Summary collapse
-
#add_all_suites ⇒ Object
Returns the value of attribute add_all_suites.
-
#in_debug ⇒ Object
Returns the value of attribute in_debug.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#run ⇒ Object
readonly
Returns the value of attribute run.
-
#suite ⇒ Object
readonly
Returns the value of attribute suite.
-
#suites_to_add ⇒ Object
Returns the value of attribute suites_to_add.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #add_cases_to_suite(cases, section_name = 'All Test Cases') ⇒ Object
- #add_result_to_test_case(example, comment = '', section_name = 'All Test Cases') ⇒ Object
- #get_incomplete_tests ⇒ Object
-
#initialize(project_name, suite_name = nil, plan_name = nil, run_name = nil) {|_self| ... } ⇒ TestrailHelper
constructor
A new instance of TestrailHelper.
Methods included from TestrailHelperRspecMetadata
#example_time_in_seconds, #init_custom_fields, #parse_pending_comment, #screenshot_link
Methods included from RubyHelper
Constructor Details
#initialize(project_name, suite_name = nil, plan_name = nil, run_name = nil) {|_self| ... } ⇒ TestrailHelper
Returns a new instance of TestrailHelper.
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 20 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 skip_testrail_connection? 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 yield(self) if block_given? @project = Testrail2.new.project project_name.to_s.dup if plan_name @plan = @project.get_plan_by_name(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_suites ⇒ Object
Returns the value of attribute add_all_suites.
18 19 20 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 18 def add_all_suites @add_all_suites end |
#in_debug ⇒ Object
Returns the value of attribute in_debug.
18 19 20 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 18 def in_debug @in_debug end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
17 18 19 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17 def plan @plan end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
17 18 19 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17 def project @project end |
#run ⇒ Object (readonly)
Returns the value of attribute run.
17 18 19 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17 def run @run end |
#suite ⇒ Object (readonly)
Returns the value of attribute suite.
17 18 19 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 17 def suite @suite end |
#suites_to_add ⇒ Object
Returns the value of attribute suites_to_add.
18 19 20 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 18 def suites_to_add @suites_to_add end |
#version ⇒ Object
Returns the value of attribute version.
18 19 20 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 18 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_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 |
# 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 example.pending result, comment, bug_id = parse_pending_comment(example.execution_result.) 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:') testrail_exception = ExampleFailedGotExpectedException.new(example) result = testrail_exception.result comment += testrail_exception.comment 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') testrail_exception = ExampleServiceUnavailableException.new(example) result = testrail_exception.result comment += testrail_exception.comment elsif exception.to_s.include?('Limited program version') testrail_exception = ExampleLPVException.new(exception) result = testrail_exception.result comment += testrail_exception.comment 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 |
#get_incomplete_tests ⇒ Object
116 117 118 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_helper.rb', line 116 def get_incomplete_tests @run.get_tests.filter_map { |test| test['title'] if test['status_id'] == 3 || test['status_id'] == 4 } end |