Class: TestCenter::Helper::HtmlTestReport::Report
- Inherits:
-
Object
- Object
- TestCenter::Helper::HtmlTestReport::Report
- Defined in:
- lib/fastlane/plugin/test_center/helper/html_test_report.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #add_test_center_footer ⇒ Object
- #add_testsuite(testsuite) ⇒ Object
- #collate_report(report) ⇒ Object
- #fail_count ⇒ Object
-
#initialize(html_file) ⇒ Report
constructor
A new instance of Report.
- #save_report(report_path) ⇒ Object
- #set_fail_count(fail_count) ⇒ Object
- #set_test_count(test_count) ⇒ Object
- #test_count ⇒ Object
- #testsuite_with_title(title) ⇒ Object
- #testsuites ⇒ Object
- #update_fail_count ⇒ Object
- #update_test_count ⇒ Object
Constructor Details
#initialize(html_file) ⇒ Report
Returns a new instance of Report.
8 9 10 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 8 def initialize(html_file) @root = html_file.root end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 7 def root @root end |
Instance Method Details
#add_test_center_footer ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 96 def = REXML::XPath.first(@root, ".//footer[@id = 'test-center-footer']") return if test_center_anchor = REXML::Element.new('a') test_center_anchor.text = 'collate_html_reports' test_center_anchor.add_attribute('href', 'https://github.com/lyndsey-ferguson/fastlane-plugin-test_center#collate_html_reports') = REXML::Element.new('footer') .add_attribute('id', 'test-center-footer') .text = 'Collated by the ' .add_element(test_center_anchor) .add_text(' action from the test_center fastlane plugin') body_element = REXML::XPath.first(@root, "//body") body_element.elements.add() end |
#add_testsuite(testsuite) ⇒ Object
19 20 21 22 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 19 def add_testsuite(testsuite) testsuites_element = REXML::XPath.first(@root, ".//*[@id='test-suites']") testsuites_element.push(testsuite.root) end |
#collate_report(report) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 24 def collate_report(report) testsuites.each(&:remove_duplicate_testcases) report.testsuites.each(&:remove_duplicate_testcases) FastlaneCore::UI.verbose("TestCenter::Helper::HtmlTestReport::Report.collate_report to report:\n\t#{@root}") report.testsuites.each do |given_testsuite| existing_testsuite = testsuite_with_title(given_testsuite.title) if existing_testsuite.nil? FastlaneCore::UI.verbose("\tadding testsuite\n\t\t#{given_testsuite}") add_testsuite(given_testsuite) else FastlaneCore::UI.verbose("\tcollating testsuite\n\t\t#{given_testsuite.root}") existing_testsuite.collate_testsuite(given_testsuite) FastlaneCore::UI.verbose("\tafter collation exiting testsuite\n\t\t#{existing_testsuite.root}") end end update_test_count update_fail_count end |
#fail_count ⇒ Object
62 63 64 65 66 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 62 def fail_count fail_count_element = REXML::XPath.first(@root, ".//*[@id = 'counters']//*[@id='fail-count']/*[@class = 'number']/text()") return fail_count_element.to_s.to_i if fail_count_element return 0 end |
#save_report(report_path) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 114 def save_report(report_path) output = '' formatter = REXML::Formatters::Transitive.new formatter.write(@root, output) File.open(report_path, 'w') do |f| f.puts output end end |
#set_fail_count(fail_count) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 68 def set_fail_count(fail_count) counters_element = REXML::XPath.first(@root, ".//*[@id = 'counters']") fail_count_number_element = REXML::XPath.first(counters_element, ".//*[@id='fail-count']/*[@class = 'number']/text()") if fail_count_number_element fail_count_number_element.value = fail_count.to_s else test_count_element = REXML::XPath.first(counters_element, ".//*[@id='test-count']") fail_count_element = test_count_element.clone fail_count_element.add_attribute('id', 'fail-count') test_count_element.each_element do |element| fail_count_element.add_element(element.clone) end REXML::XPath.first(fail_count_element, ".//*[@class = 'number']").text = fail_count counters_element.add_element(fail_count_element) end end |
#set_test_count(test_count) ⇒ Object
52 53 54 55 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 52 def set_test_count(test_count) test_count_element = REXML::XPath.first(@root, ".//*[@id = 'counters']//*[@id='test-count']/*[@class = 'number']/text()") test_count_element.value = test_count.to_s end |
#test_count ⇒ Object
48 49 50 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 48 def test_count REXML::XPath.first(@root, ".//*[@id = 'counters']//*[@id='test-count']/*[@class = 'number']/text()").to_s.to_i end |
#testsuite_with_title(title) ⇒ Object
43 44 45 46 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 43 def testsuite_with_title(title) testsuite_element = REXML::XPath.first(@root, ".//*[contains(@id, 'test-suites')]//*[@id='#{title}' and contains(concat(' ', @class, ' '), ' test-suite ')]") TestSuite.new(testsuite_element) unless testsuite_element.nil? end |
#testsuites ⇒ Object
12 13 14 15 16 17 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 12 def testsuites testsuite_elements = REXML::XPath.match(@root, "//section[contains(@class, 'test-suite')]") testsuite_elements.map do |testsuite_element| TestSuite.new(testsuite_element) end end |
#update_fail_count ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 86 def update_fail_count xpath_class_attributes = [ "contains(concat(' ', @class, ' '), ' test ')", "contains(concat(' ', @class, ' '), ' failing ')" ].join(' and ') failing_testcase_elements = REXML::XPath.match(@root, ".//[#{xpath_class_attributes}]") set_fail_count(failing_testcase_elements.size) end |
#update_test_count ⇒ Object
57 58 59 60 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 57 def update_test_count testcase_elements = REXML::XPath.match(@root, ".//*[contains(@class, 'tests')]//*[contains(concat(' ', @class, ' '), ' test ')]") set_test_count(testcase_elements.size) end |