Skip to content

Commit

Permalink
feat(template): add template
Browse files Browse the repository at this point in the history
Signed-off-by: Naylin Medina <[email protected]>
  • Loading branch information
Naylin15 committed Oct 4, 2018
1 parent fa0d50f commit 5e9ceae
Showing 1 changed file with 59 additions and 33 deletions.
92 changes: 59 additions & 33 deletions lib/fastlane/plugin/test_report/actions/test_report_action.rb
Original file line number Diff line number Diff line change
@@ -1,53 +1,79 @@
require 'fastlane/action'
require_relative '../helper/test_report_helper'
require "erb"
require "nokogiri"
require "rexml/document"

module Fastlane
module Actions
class TestReportAction < Action
def self.run(params)
UI.message("The test_report plugin is working!")

report = File.read(File.expand_path(params[:path]))
doc = Nokogiri::XML(File.open(report))
test_suite_name = @doc.xpath('//test_suite').attr("name")
include REXML

File.rename("fastlane/test_output/report.junit", "fastlane/test_output/report.xml")

file = File.new(File.expand_path(params[:report_path]))
doc = Document.new(file)

template = '---
layout: testReport
---
<div class="total row">
<div class="col-sm-12">
<h2>Test Results</h2>
</div>
<div class="col-sm-12">
<h2> 8 tests</h2>
</div>
</div>
<% test_suite_name.each do |name| %>
<div>
<div class="test-suite row failing" onclick="changeDisplay('test-1')">
<h4 class="col-sm-12"><%= name %></h4>
<h4 class="col-sm-12">1 tests</h4>
</div>
<% end %>
<div id="test-1">
<div class="failing row">
<div class="title col-sm-12 dropdown-item">
<p>testTakeScreenshots</p>
</div>
<div class="time col-sm-12 dropdown-item">
<p>29.457s</p>
</div>
</div>
</div>
</div>'
<div class="total row">
<h2 class="col-sm-18">Test Results</h2>
<h2 class="col-sm-6 text-right"><%= doc.root.attributes["tests"] %> tests</h2>
</div>
<div>
<% i = 0 %>
<% doc.elements.each("testsuites/testsuite") do |name| %>
<% i = i + 1 %>
<% if name.attributes["failures"] == "0" %>
<div class="test-suite row test-suite--passing" onclick="changeDisplay(<%= "\'#test-#{i}\'"%>)">
<% else %>
<div class="test-suite row test-suite--failing" onclick="changeDisplay(<%= "\'#test-#{i}\'"%>)">
<% end %>
<h4 class="col-sm-20"><%= name.attributes["name"] %></h4>
<h4 class="col-sm-4 text-right"><%= name.attributes["tests"] %> tests</h4>
</div>
<!-- Failing or passing class -->
<div id="<%= "test-#{i}"%>">
<% doc.elements.each("testsuites/testsuite/testcase") do |test| %>
<% if test.attributes["classname"] == name.attributes["name"] %>
<% if test.attributes["time"] == nil %>
<div class="test-case--failing row">
<div class="col-sm-16">
<p><%= test.attributes["name"] %></p>
</div>
<div class="col-sm-4">
<p><%= test.elements["failure"].attributes["message"] %></p>
</div>
<div class="col-sm-4 text-right">
<p><%= test.elements["failure"].text %></p>
</div>
</div>
<% else %>
<div class="test-case--passing row">
<div class="col-sm-20">
<p><%= test.attributes["name"] %></p>
</div>
<div class="col-sm-4 text-right">
<p><%= test.attributes["time"] %></p>
</div>
</div>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
</div>'

result = ERB.new(template).result(binding())

open('test-report/index.html', 'w') do |f|
open('fastlane/test_output/index.html', 'w') do |f|
f.puts result
end

Expand Down

0 comments on commit 5e9ceae

Please sign in to comment.