Class: XcodeResultBundleProcessor::TestSummaries::HTMLReport

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging
Defined in:
lib/xcoderesultbundleprocessor/test_summaries/html_report.rb

Instance Method Summary collapse

Constructor Details

#initialize(results_bundle) ⇒ HTMLReport

Returns a new instance of HTMLReport.



6
7
8
9
10
# File 'lib/xcoderesultbundleprocessor/test_summaries/html_report.rb', line 6

def initialize(results_bundle)
  @results_bundle  = results_bundle
  @stylesheet_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'static', 'report.css')
  @js_path         = File.join(File.dirname(__FILE__), '..', '..', '..', 'static', 'report.js')
end

Instance Method Details

#_format_element_summary(buffer, element_summary) ⇒ Object



145
146
147
148
149
150
151
152
153
# File 'lib/xcoderesultbundleprocessor/test_summaries/html_report.rb', line 145

def _format_element_summary(buffer, element_summary)
  buffer << element_summary.summary

  element_summary.children.each do |child|
    _format_element_summary(buffer.indent, child)
  end

  buffer
end

#_format_test(test, mab, destination_dir) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/xcoderesultbundleprocessor/test_summaries/html_report.rb', line 71

def _format_test(test, mab, destination_dir)
  mab.a name: test.identifier do
    if test.passed?
      mab.h2 test.summary
    else
      mab.h2.testFailed test.summary
    end
  end

  mab.ul do
    test.failure_summaries.each do |failure_summary|
      li do
        em "Failure at #{failure_summary.location}"
        pre failure_summary.message
      end
    end
    ''
  end

  mab.div.timelineContainer do
    table do
      tr do
        test.activities.each do |activity_summary|
          td do
            h4 activity_summary.title

            table do
              tr do
                activity_summary.subactivities.each do |subactivity|
                  td do
                    h5 subactivity.title

                    unless subactivity.screenshot_path.nil?
                      basename = File.basename(subactivity.screenshot_path)

                      output_image_path = File.join(destination_dir, 'screenshots', basename)
                      @results_bundle.copy_file(File.join('Attachments', subactivity.screenshot_path), output_image_path)

                      img src: File.join('screenshots', basename)
                    end

                    unless subactivity.snapshot_path.nil?
                      a.viewSnapshot href: '#' do
                        'View Snapshot'
                      end

                      pre.snapshot do
                        @results_bundle.open_file(File.join('Attachments', subactivity.snapshot_path)) do |file|
                          snapshot_plist   = CFPropertyList::List.new(data: file.read)
                          element_snapshot = ElementSnapshot.new(snapshot_plist)

                          snapshot_summary = SnapshotSummary.parse(element_snapshot.to_h)

                          buffer = IndentedStringBuffer.new
                          _format_element_summary(buffer, snapshot_summary)
                        end
                      end
                    end

                    ''
                  end
                end
                ''
              end
            end
          end
        end
        ''
      end
    end
  end
  ''
end

#save(destination_dir) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xcoderesultbundleprocessor/test_summaries/html_report.rb', line 12

def save(destination_dir)
  info "Saving HTML report to #{destination_dir}"

  raise "Destination directory #{destination_dir} already exists" if Dir.exist?(destination_dir)

  FileUtils.mkdir_p(File.join(destination_dir, 'screenshots'))

  info 'Deserializing logs'
  action_logs = LogDeserializer.deserialize_action_logs(@results_bundle)
  debug action_logs


  tests = TestSummaries.new(@results_bundle.read_plist('TestSummaries.plist'))

  debug "Formatting test summaries <#{tests.ai}>"

  Markaby::Builder.set_html5_options!
  Markaby::Builder.set(:indent, 2)
  mab    = Markaby::Builder.new({}, self)
  report = mab.html5 do
    head do
      link rel: 'stylesheet', href: 'report.css'
      script src: 'report.js' do
        ''
      end
    end

    body do
      unless tests.failed_tests.empty?
        h1 'Failed Tests :('
        ul do
          tests.failed_tests.each do |failed_test|
            li do
              a href: "##{failed_test.identifier}" do
                failed_test.identifier
              end
            end
          end
        end
      end

      h1 'Test Timelines'
      tests.tests.each do |test|
        _format_test(test, mab, destination_dir)
      end

      hr

      h1 'Action Logs'
      pre action_logs

    end
  end

  FileUtils.copy(@stylesheet_path, File.join(destination_dir, 'report.css'))
  FileUtils.copy(@js_path, File.join(destination_dir, 'report.js'))
  File.open(File.join(destination_dir, 'index.html'), 'w').write(report)
end