Class: TestCenter::Helper::HtmlTestReport::TestCase

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(testcase_element) ⇒ TestCase

Returns a new instance of TestCase.



246
247
248
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 246

def initialize(testcase_element)
  @root = testcase_element
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



244
245
246
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 244

def root
  @root
end

Instance Method Details

#failure_detailsObject



269
270
271
272
273
274
275
276
277
278
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 269

def failure_details
  return nil if @root.attribute('class').value.include?('passing')

  xpath_class_attributes = [
    "contains(concat(' ', @class, ' '), ' details ')",
    "contains(concat(' ', @class, ' '), ' failing ')",
    "contains(concat(' ', @class, ' '), ' #{title} ')"
  ].join(' and ')
  REXML::XPath.first(@root.parent, ".//*[#{xpath_class_attributes}]")
end

#passing?Boolean

Returns:

  • (Boolean)


254
255
256
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 254

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

#remove_failure_detailsObject



280
281
282
283
284
285
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 280

def remove_failure_details
  details = failure_details
  return if details.nil?
  
  details.parent.delete_element(details)
end

#row_colorObject



258
259
260
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 258

def row_color
  @root.attribute('class').value.include?('odd') ? 'odd' : ''
end

#set_row_color(row_color) ⇒ Object



262
263
264
265
266
267
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 262

def set_row_color(row_color)
  raise 'row_color must either be "odd" or ""' unless ['odd', ''].include?(row_color)

  current_class_attribute = @root.attribute('class').value.sub(/\bodd\b/, '')
  @root.add_attribute('class', current_class_attribute << ' ' << row_color)
end

#titleObject



250
251
252
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 250

def title
  REXML::XPath.first(@root, ".//h3[contains(@class, 'title')]/text()").to_s.strip
end

#update_testcase(testcase) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 287

def update_testcase(testcase)
  color = row_color
  failure = failure_details
  if failure.nil? && !passing?
    HtmlTestReport.error("\t\t\t\tupdating failing test case that does not have failure_details")
  end
  parent = @root.parent

  failure.parent.delete(failure) unless failure.nil?

  new_failure = testcase.failure_details
  if new_failure && testcase.passing?
    HtmlTestReport.error("\t\t\t\tswapping passing failing test case that _does_have_ failure_details")
  end

  parent.replace_child(@root, testcase.root)
  @root = testcase.root
  unless new_failure.nil?
    parent.insert_after(@root, new_failure)
  end
  set_row_color(color)
end