class TestCenter::Helper::HtmlTestReport::TestSuite

Attributes

root[R]

Public Class Methods

new(testsuite_element) click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 143
def initialize(testsuite_element)
  @root = testsuite_element
end

Public Instance Methods

add_testcase(testcase) click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 179
def add_testcase(testcase)
  tests_table = REXML::XPath.first(@root, ".//*[contains(@class, 'tests')]/table")
  details = testcase.failure_details
  if details
    tests_table.push(details)
    tests_table.insert_before(details, testcase.root)
  else
    tests_table.push(testcase.root)
  end
end
collate_testsuite(testsuite) click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 221
def collate_testsuite(testsuite)
  given_testcases = testsuite.testcases
  given_testcases.each do |given_testcase|
    existing_testcase = testcase_with_title(given_testcase.title)
    if existing_testcase.nil?
      HtmlTestReport.verbose("\t\tadding testcase\n\t\t\t#{given_testcase.root}")
      unless given_testcase.passing?
        HtmlTestReport.verbose("\t\t\twith failure:\n\t\t\t\t#{given_testcase.failure_details}")
      end
      add_testcase(given_testcase)
    else
      HtmlTestReport.verbose("\t\tupdating testcase\n\t\t\t#{existing_testcase.root}")
      unless given_testcase.passing?
        HtmlTestReport.verbose("\t\t\twith failure:\n\t\t\t\t#{given_testcase.failure_details}")
      end
      existing_testcase.update_testcase(given_testcase)
    end
  end
  set_passing(testcases.all?(&:passing?))
end
duplicate_testcases?() click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 190
def duplicate_testcases?
  nonuniq_testcases = testcases
  uniq_testcases = nonuniq_testcases.uniq { |tc| tc.title }
  nonuniq_testcases != uniq_testcases
end
passing?() click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 166
def passing?
  @root.attribute('class').value.include?('passing')
end
remove_duplicate_testcases() click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 196
def remove_duplicate_testcases
  # Get a list of all the testcases in the report's testsuite
  # and reverse the order so that we'll get the tests that
  # passed _after_ they failed first. That way, when
  # uniq is called, it will grab the first non-repeated test
  # it finds; for duplicated tests (tests that were re-run), it will
  # actually grab the last test that was run of that set.
  #
  # For example, if `testcases` is
  # `['a(passing)', 'b(passing)', 'c(passing)', 'dup1(failing)', 'dup2(failing)', 'dup1(passing)', 'dup2(passing)' ]`
  # then, testcases.reverse will be
  # `['dup2(passing)', 'dup1(passing)', 'dup2(failing)', 'dup1(failing)', 'c(passing)', 'b(passing)', 'a(passing)']`
  # then `uniq_testcases` will be
  # `['dup2(passing)', 'dup1(passing)', 'c(passing)', 'b(passing)', 'a(passing)']`
  nonuniq_testcases = testcases.reverse
  uniq_testcases = nonuniq_testcases.uniq { |tc| tc.title }
  (nonuniq_testcases - uniq_testcases).each do |tc|
    # here, we would be deleting ['dup2(failing)', 'dup1(failing)']
    failure_details = tc.failure_details
    # failure_details can be nil if this is a passing testcase
    tc.root.parent.delete_element(failure_details) unless failure_details.nil?
    tc.root.parent.delete_element(tc.root)
  end
end
set_passing(status) click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 170
def set_passing(status)
  desired_status = status ? ' passing ' : ' failing '
  to_replace = status ? /\bfailing\b/ : /\bpassing\b/
  
  attribute = @root.attribute('class').value.sub(to_replace, desired_status)
  attribute.gsub!(/\s{2,}/, ' ')
  @root.add_attribute('class', attribute)  
end
testcase_with_title(title) click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 158
def testcase_with_title(title)
  found_title_element = REXML::XPath.match(@root, ".//*[contains(@class, 'tests')]//*[contains(concat(' ', @class, ' '), ' test ')]//*[@class='title']").find { |n| n.text.to_s.strip == title  }
  if found_title_element
    testcase_element = found_title_element.parent.parent
    TestCase.new(testcase_element) unless testcase_element.nil?
  end
end
testcases() click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 151
def testcases
  testcase_elements = REXML::XPath.match(@root, ".//*[contains(@class, 'tests')]//*[contains(concat(' ', @class, ' '), ' test ')]")
  testcase_elements.map do |testcase_element|
    TestCase.new(testcase_element)
  end
end
title() click to toggle source
# File lib/fastlane/plugin/test_center/helper/html_test_report.rb, line 147
def title
  @root.attribute('id').value
end