Created
June 18, 2014 11:17
-
-
Save hron84/6dd3e1faa282fec01bf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' unless defined?(Gem) | |
require 'nokogiri' | |
xml = ARGV.first | |
if xml.nil? or xml == '--help' then | |
puts "Usage: #{$0} TEST-junit.xml" | |
exit 1 | |
end | |
report = Nokogiri::XML(open(xml)) | |
total = report.root.attr('tests').to_s.to_i | |
fails = report.root.attr('failures').to_s.to_i | |
errors = report.root.attr('errors').to_s.to_i | |
success = total - fails - errors | |
tests = report.css('testsuite testcase') | |
testdetails = [] | |
tests.each do |t| | |
failed = t.children.map(&:name).include?('failure') | |
error = t.children.map(&:name).include?('error') | |
tag = error ? 'ERROR' : (failed ? 'FAIL' : 'OK') | |
classname = t.attr('classname').empty? ? nil : t.attr('classname') | |
name = [classname, t.attr('name')].compact.join('#') | |
result = error ? t.css('error').first.children.first.content : (failed ? t.css('failure').first.children.first.content : '') | |
time = t.attr('time') | |
testdetails << { name: name, tag: tag, result: result, time: time } | |
end | |
loop do | |
system('clear') | |
print "Testsuite: #{report.root.attr('name')}" | |
print " on #{report.root.attr('hostname')}" unless report.root.attr('hostname').empty? | |
print " at #{report.root.attr('timestamp')}" unless report.root.attr('timestamp').empty? | |
puts | |
puts | |
print "Total time: #{report.root.attr('time')}s" | |
puts " #{success} / #{total} succeeded, #{fails} failed, #{errors} error" | |
puts | |
puts '-' * 60 | |
testdetails.each_with_index do |test,i| | |
puts " [#{i + 1}] #{sprintf('%-40s', test[:name][0..40])} [#{sprintf('%-05s', test[:tag])}]" | |
end | |
puts | |
puts " [Q] Exit" | |
puts '-' * 60 | |
print " * Select testcase to see details (it's available only for unsuccessful testcases) : " | |
ans = STDIN.gets.strip | |
idx = ans.to_i | |
exit 1 if ans.downcase == 'q' | |
if idx < 1 or idx > testdetails.size then | |
puts " ! Invalid ID." | |
sleep 0.5 | |
next | |
end | |
puts '-' * 60 | |
puts "Testcase: #{testdetails[idx - 1][:name]}" | |
puts "Run time: #{testdetails[idx - 1][:time]}s" | |
puts "Result: #{testdetails[idx - 1][:tag]}" | |
puts | |
testdetails[idx - 1][:result].split(/[\n]/).each { |l| puts " #{l}" } | |
puts '-' * 60 | |
puts ' * Press ENTER to continue' | |
STDIN.gets | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment