module Awetestlib
class HtmlReport
# Initialize the report class
def initialize(report_name)
@reportname = report_name
@reportContent1 = ''
@reportContent2 = ''
end
# Create a report
def create_report(reportName)
# Get current time
t = Time.now
# Format the day
if(t.day.to_s.length == 1)
strDay = '0' + t.day.to_s
else
strDay = t.day.to_s
end
# Format the month
if(t.month.to_s.length == 1)
strMonth = '0' + t.month.to_s
else
strMonth = t.month.to_s
end
# Format the year
strYear = t.year.to_s
# Format the hour
if(t.hour.to_s.length == 1)
strHour = '0' + t.hour.to_s
else
strHour = t.hour.to_s
end
# Format the minutes
if(t.min.to_s.length == 1)
strMinutes = '0' + t.min.to_s
else
strMinutes = t.min.to_s
end
# Format the seconds
if(t.sec.to_s.length == 1)
strSeconds = '0' + t.sec.to_s
elsif (t.sec.to_s.length == 0)
strSeconds = '00'
else
strSeconds = t.sec.to_s
end
# Create the report name
strTime = '_' + strMonth + strDay + strYear + '_' + strHour + strMinutes + strSeconds + '.html'
strNiceTime = strDay + '-' + strMonth + '-' + strYear + ' @ ' + strHour + ':' + strMinutes + ':' + strSeconds
strTotalReport = reportName + strTime
# Create the HTML report
strFile = File.open(strTotalReport, 'w')
# Format the header of the HTML report
@reportContent1 = '
Awetestlib Test Run
|
|
Test Report |
Script |
: |
' + @reportname.capitalize + ' |
Test Execution |
: |
' + strNiceTime + ' |
'
@reportContent2 = '
Test Step |
Result |
'
# Close the report
strFile.close
return strTotalReport
end
def add_to_report(step, result)
# Format the body of the HTML report
if (result == 'PASSED')
@reportContent2 = @reportContent2 + '' + step + ' | '
@reportContent2 = @reportContent2 + '' + result + ' | '
elsif (result == 'FAILED')
@reportContent2 = @reportContent2 + ' ' + step + ' | '
@reportContent2 = @reportContent2 + '' + result + ' | '
else
@reportContent2 = @reportContent2 + ' ' + step + ' | '
@reportContent2 = @reportContent2 + '' + result + ' | '
end
end
def finish_report(reportName)
# Open the HTML report
strFile = File.open(reportName, 'a')
@reportContent2 = @reportContent2 + '
|
|
'
strFile.puts(@reportContent1)
strFile.puts(@reportContent2)
# Close the report
strFile.close
end
end
end
|