From 5e9ceae883d1e745f7edb60959017c958da7fc68 Mon Sep 17 00:00:00 2001 From: Naylin Medina Date: Mon, 1 Oct 2018 13:02:28 -0400 Subject: [PATCH] feat(template): add template Signed-off-by: Naylin Medina --- .../test_report/actions/test_report_action.rb | 92 ++++++++++++------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/lib/fastlane/plugin/test_report/actions/test_report_action.rb b/lib/fastlane/plugin/test_report/actions/test_report_action.rb index 2bc5eb8..a81a189 100644 --- a/lib/fastlane/plugin/test_report/actions/test_report_action.rb +++ b/lib/fastlane/plugin/test_report/actions/test_report_action.rb @@ -1,7 +1,7 @@ require 'fastlane/action' require_relative '../helper/test_report_helper' require "erb" -require "nokogiri" +require "rexml/document" module Fastlane module Actions @@ -9,45 +9,71 @@ 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 --- - -
-
-

Test Results

-
-
-

8 tests

-
-
-<% test_suite_name.each do |name| %> -
-
-

<%= name %>

-

1 tests

-
-<% end %> -
- -
- - -
-
-
' + +
+

Test Results

+

<%= doc.root.attributes["tests"] %> tests

+
+
+ <% i = 0 %> + <% doc.elements.each("testsuites/testsuite") do |name| %> + <% i = i + 1 %> + <% if name.attributes["failures"] == "0" %> +
)"> + <% else %> +
)"> + <% end %> +

<%= name.attributes["name"] %>

+

<%= name.attributes["tests"] %> tests

+
+ +
"> + + <% doc.elements.each("testsuites/testsuite/testcase") do |test| %> + <% if test.attributes["classname"] == name.attributes["name"] %> + + <% if test.attributes["time"] == nil %> +
+
+

<%= test.attributes["name"] %>

+
+
+

<%= test.elements["failure"].attributes["message"] %>

+
+
+

<%= test.elements["failure"].text %>

+
+
+ <% else %> +
+
+

<%= test.attributes["name"] %>

+
+
+

<%= test.attributes["time"] %>

+
+
+ <% end %> + <% end %> + <% end %> +
+ <% end %> + +
' 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