Class: TestCenter::Helper::HtmlTestReport::TestSuite

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/helper/html_test_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(testsuite_element) ⇒ TestSuite

Returns a new instance of TestSuite.



143
144
145
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 143

def initialize(testsuite_element)
  @root = testsuite_element
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



141
142
143
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 141

def root
  @root
end

Instance Method Details

#add_testcase(testcase) ⇒ Object



179
180
181
182
183
184
185
186
187
188
# 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) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# 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?Boolean

Returns:

  • (Boolean)


190
191
192
193
194
# 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?Boolean

Returns:

  • (Boolean)


166
167
168
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 166

def passing?
  @root.attribute('class').value.include?('passing')
end

#remove_duplicate_testcasesObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# 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) ⇒ Object



170
171
172
173
174
175
176
177
# 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) ⇒ Object



158
159
160
161
162
163
164
# 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

#testcasesObject



151
152
153
154
155
156
# 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

#titleObject



147
148
149
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 147

def title
  @root.attribute('id').value
end