Module: Testrail::Scenario
- Defined in:
- lib/cucumber_testrail/testrail_extensions.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#ignore_testrail? ⇒ Boolean
returns true if the tag @ignore_testrail or environment variable IGNORE_TESTRAIL=true are found OR the suite and project id cannot be found.
-
#is_manual? ⇒ Boolean
is this a manual scenario?.
-
#jira ⇒ Object
return the jira ticket number if there is one.
-
#project ⇒ Object
return the project id.
-
#skip_result? ⇒ Boolean
skip sending the result - useful for simply loading the testcases into Testrail.
-
#sub_section ⇒ Object
return the sub_section id.
-
#suite ⇒ Object
return the suite id.
-
#test_result ⇒ Object
return test results if it failed, ready to write into the testcase test result.
-
#testcase ⇒ Object
return the testcase id.
-
#testrail_status ⇒ Object
translate the scenario status into a testrail id using the configured status map.
-
#testrail_tag(tagname) ⇒ Object
-
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.
-
-
#testrail_test_report ⇒ Object
returns a hash of status_id and comment to write into Testrail test report.
-
#testrail_testcase ⇒ Object
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.
-
#testrun ⇒ Object
return the tesrun id.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 |
# 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 |
Instance Method Details
#ignore_testrail? ⇒ Boolean
returns true if the tag @ignore_testrail or environment variable IGNORE_TESTRAIL=true are found OR the suite and project id cannot be found
60 61 62 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 60 def ignore_testrail? testrail_tag('ignore_testrail') || !suite || !project end |
#is_manual? ⇒ Boolean
is this a manual scenario?
65 66 67 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 65 def is_manual? testrail_tag('manual') end |
#jira ⇒ Object
return the jira ticket number if there is one
112 113 114 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 112 def jira testrail_tag('jira') end |
#project ⇒ Object
return the project id
75 76 77 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 75 def project testrail_tag('project') end |
#skip_result? ⇒ Boolean
skip sending the result - useful for simply loading the testcases into Testrail
70 71 72 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 70 def skip_result? testrail_tag('skip_result') end |
#sub_section ⇒ Object
return the sub_section id
87 88 89 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 87 def sub_section testrail_tag('sub_section') end |
#suite ⇒ Object
return the suite id
81 82 83 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 81 def suite testrail_tag('suite') end |
#test_result ⇒ Object
return test results if it failed, ready to write into the testcase test result
105 106 107 108 109 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 105 def test_result if status =~ /failed/ "#{status} #{exception} line #{backtrace_line}"[0..249] end end |
#testcase ⇒ Object
return the testcase id
93 94 95 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 93 def testcase testrail_tag('testcase') end |
#testrail_status ⇒ Object
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
122 123 124 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 122 def testrail_status self.class.get_testrail_configuration(:status_map)[status.to_s] end |
#testrail_tag(tagname) ⇒ Object
-
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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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,..map{|t| t.name}].each do | | extracted_tag = .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,..map{|t| t.name}].each do | | extracted_tag = .map{|tag| /#{tagname}/.match(tag)}.compact.first if extracted_tag result = true break end end end result ||=ENV[tagname.upcase] end |
#testrail_test_report ⇒ Object
returns a hash of status_id and comment to write into Testrail test report
128 129 130 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 128 def testrail_test_report {status_id:testrail_status,comment:test_result,defects:jira} end |
#testrail_testcase ⇒ Object
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
135 136 137 |
# 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 |
#testrun ⇒ Object
return the tesrun id
99 100 101 |
# File 'lib/cucumber_testrail/testrail_extensions.rb', line 99 def testrun testrail_tag('testrun') end |