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.



215
216
217
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 215

def initialize(testcase_element)
  @root = testcase_element
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



213
214
215
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 213

def root
  @root
end

Instance Method Details

#failure_detailsObject



238
239
240
241
242
243
244
245
246
247
248
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 238

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)


223
224
225
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 223

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

#remove_failure_detailsObject



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

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

#row_colorObject



227
228
229
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 227

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

#set_row_color(row_color) ⇒ Object



231
232
233
234
235
236
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 231

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



219
220
221
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 219

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

#update_testcase(testcase) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/fastlane/plugin/test_center/helper/html_test_report.rb', line 257

def update_testcase(testcase)
  color = row_color
  failure = failure_details
  if failure.nil? && !passing?
    FastlaneCore::UI.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?
    FastlaneCore::UI.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