module Testrail::Scenario
Public Class Methods
# File lib/cucumber_testrail/testrail_extensions.rb, line 3 def self.included(base) base.extend(ClassMethods) base.set_testrail_configuration(:status_map,{'passed'=>1,'failed'=>5,'undefined'=>7,'pending'=>6}) end
Public Instance Methods
returns true if the tag @ignore_testrail or environment variable IGNORE_TESTRAIL=true are found OR the suite and project id cannot be found
# File lib/cucumber_testrail/testrail_extensions.rb, line 60 def ignore_testrail? testrail_tag('ignore_testrail') || !suite || !project end
is this a manual scenario?
# File lib/cucumber_testrail/testrail_extensions.rb, line 65 def is_manual? testrail_tag('manual') end
return the jira ticket number if there is one
# File lib/cucumber_testrail/testrail_extensions.rb, line 112 def jira testrail_tag('jira') end
return the project id
# File lib/cucumber_testrail/testrail_extensions.rb, line 75 def project testrail_tag('project') end
skip sending the result - useful for simply loading the testcases into Testrail
# File lib/cucumber_testrail/testrail_extensions.rb, line 70 def skip_result? testrail_tag('skip_result') end
return the sub_section
id
# File lib/cucumber_testrail/testrail_extensions.rb, line 87 def sub_section testrail_tag('sub_section') end
return the suite id
# File lib/cucumber_testrail/testrail_extensions.rb, line 81 def suite testrail_tag('suite') end
return test results if it failed, ready to write into the testcase test result
# File lib/cucumber_testrail/testrail_extensions.rb, line 105 def test_result if status =~ /failed/ "#{status} #{exception} line #{backtrace_line}"[0..249] end end
return the testcase id
# File lib/cucumber_testrail/testrail_extensions.rb, line 93 def testcase testrail_tag('testcase') end
translate the scenario status into a testrail id using the configured status map. This can be changed in your set up env.rb but by default it maps
-
passed to 1
-
failed to 5
-
undefined to 2
-
pending to 2
# File lib/cucumber_testrail/testrail_extensions.rb, line 122 def testrail_status self.class.get_testrail_configuration(:status_map)[status.to_s] end
-
Looks for a tagname at scenario, feature file and environment levels in that order
-
Unless the tagname == ‘ignore_testrail’ it will return the id of the tag. e.g. input tagname ‘testcase’ output ‘5’
-
If the tagname == ‘ignore_testrail’ then it will return nil or true depeneding if it can find the tag or the environment variable
# File lib/cucumber_testrail/testrail_extensions.rb, line 29 def testrail_tag(tagname) #check scenario, feature, environment in that order result = nil unless tagname =~ /ignore_testrail|manual|skip_result/ [source_tag_names,feature_tags.tags.map{|t| t.name}].each do | tags | extracted_tag = tags.map{|tag| /^@#{tagname}_(\d+)$|^@#{tagname}_(.*)$/.match(tag)}.compact if extracted_tag if tagname=='jira' result = extracted_tag.map{|e| e.to_a.compact[1]}.join(', ') else result = extracted_tag.first.to_a.compact[1] # we compact it because there are two possible matches, if it hits the second then the first will be nil so after compacting # the result is always the first second element. Try it in irb to convince yourself end break end end else [source_tag_names,feature_tags.tags.map{|t| t.name}].each do | tags | extracted_tag = tags.map{|tag| /#{tagname}/.match(tag)}.compact.first if extracted_tag result = true break end end end result ||=ENV[tagname.upcase] end
returns a hash of status_id and comment to write into Testrail
test report
# File lib/cucumber_testrail/testrail_extensions.rb, line 128 def testrail_test_report {status_id:testrail_status,comment:test_result,defects:jira} end
returns a hash of :title, :type_id and :custom_steps to create or update a Testrail
testcase
- TODO
-
parameterize the mapping of type_id to manual, in other installations it might be different
# File lib/cucumber_testrail/testrail_extensions.rb, line 135 def testrail_testcase {'title'=>title,'type_id'=>(is_manual? ? 7 : 1 ),'custom_steps'=>steps_as_string} end
return the tesrun id
# File lib/cucumber_testrail/testrail_extensions.rb, line 99 def testrun testrail_tag('testrun') end