cheat sheet · QA · Ruby · Ruby 1.9 · ruby excercise · selenium · selenium-webdriver · Selenium-webdriver · watir · watir-webdriver

Custom HTML report for Ruby(Watir/Selenium) Base Automation framework

Requirement:

Sample HTML report for any ruby based Automation Testing Framework

Installation/Changes :

1. Create code.rb file and paste the below code.

2. Create folder named as Results in the same location.

Code:

def get_time_name
$time=Time.now
$time_name="#{$time.hour.to_s}-#{$time.min.to_s}-#{$time.sec.to_s}-#{$time.day.to_s}-#{$time.mon.to_s}-#{$time.year.to_s}"
$result_date = "#{$time.day.to_s}-#{$time.month.to_s}-#{$time.year.to_s}"
end
def create_report
get_time_name
@result_file_name="Report"+"-"+$time_name
@full_file_name="Results/#{@result_file_name}.html"
$report=File.open(@full_file_name,'w')
end
def insert_head_title(title)
$report.puts "<html><head>
<title> #{title} </title>
</head>"
end
def start_table
$report=File.open(@full_file_name,'a')
$report.puts "<table border=1>
<tr>
<th>Test Case Name</th>
<th>Test Case Description</th>
<th>Browser Name</th>
<th>Result</th>
<th>Remarks</th>
</tr>"
$report.close
end
def insert_reportname_date(name,date)
$report.puts "<body bgcolor='#5CB3FF'>
<p align='left' size=2>
<b><img src='https://encrypted-tbn1.google.com/images?q=tbn:ANd9GcQB0l0xnGOHuRPFMMMi-OVg39nfAU1Ogvxr7Okk7DD8ZpqlMF9r'></img> </b>
</p>
<p size=12>
<center> <b><u>#{name} </u></b></center>
</p>
<p align='right' size=12>
<b>Date: #{date} </b>
</p>"
$report.close
end
def report_row(*details)
$report=File.open(@full_file_name,'a')
name=details[0]
desc=details[1]
browser=details[2]
result=details[3]
reason=details[4]
if result.downcase == "pass"
$report.puts "<tr>
<td>#{name}</td>
<td> #{desc}</td>
<td> #{browser} </td>
<td bgcolor='green'>#{result}</td>
<td>#{reason}</td>
</tr>"
else
$report.puts "<tr>
<td>#{name}</td>
<td> #{desc}</td>
<td> #{browser} </td>
<td bgcolor='red'>#{result}</td>
<td>#{reason}</td>
</tr>"
end
$report.close
end
def close_table
$report=File.open(@full_file_name,'a')
$report.puts "</table></br>"
$report.close
end
def summary_report(overall,passed,failed)
$report_overall=overall
$report_pass=passed
$report_fail=failed
$report=File.open(@full_file_name,'a')
$report.puts "<p> <b>Total Test cases : #{$report_overall} </b></p>
<p> <b>Passed : #{$report_pass} </b></p>
<p> <b>Failed : #{$report_fail} </b></p>
</body>
</html>"
$report.close
end

create_report
insert_head_title("Raveendran -- Sample HTML Report")
insert_reportname_date("My Test Report",$result_date )
start_table
report_row("Check Google Home Page","Check The Title in Google Home Page","IE","PASS","Title Present")
report_row("Check Google Home Page","Check The Title in Google Home Page","FF","FAIL","Title Not Present")
close_table
summary_report(2,1,1)

 

Output HTML File: