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.
21 22 23 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 21 def initialize(html_file) @root = html_file.root end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
20 21 22 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 20 def root @root end |
Instance Method Details
#add_test_center_footer ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 109 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
32 33 34 35 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 32 def add_testsuite(testsuite) testsuites_element = REXML::XPath.first(@root, ".//*[@id='test-suites']") testsuites_element.push(testsuite.root) end |
#collate_report(report) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 37 def collate_report(report) testsuites.each(&:remove_duplicate_testcases) report.testsuites.each(&:remove_duplicate_testcases) HtmlTestReport.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? HtmlTestReport.verbose("\tadding testsuite\n\t\t#{given_testsuite}") add_testsuite(given_testsuite) else HtmlTestReport.verbose("\tcollating testsuite\n\t\t#{given_testsuite.root}") existing_testsuite.collate_testsuite(given_testsuite) HtmlTestReport.verbose("\tafter collation exiting testsuite\n\t\t#{existing_testsuite.root}") end end update_test_count update_fail_count end |
#fail_count ⇒ Object
75 76 77 78 79 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 75 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
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 127 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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 81 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
65 66 67 68 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 65 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
61 62 63 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 61 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
56 57 58 59 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 56 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
25 26 27 28 29 30 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 25 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
99 100 101 102 103 104 105 106 107 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 99 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
70 71 72 73 |
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 70 def update_test_count testcase_elements = REXML::XPath.match(@root, "//*[contains(@class, 'tests')]//*[contains(concat(' ', @class, ' '), ' test ')]").uniq set_test_count(testcase_elements.size) end |