Generate HTML Report Through QTP/UFT

1
72
Spread the love
  • 23
  • 23
  • 12
  • 22
  •  
  •  
  •  
  •  
  •  
  •  
    80
    Shares

Generate HTML Report Through QTP
Generate HTML Report Through QTP

Generate HTML Report Through QTP/UFT:

Objective of the Post:

The objective of this post is to show the colorful report coming out from QTP/UFT. Normally QTP/UFT reports are not so clear about the details. With the raw report, we can hardly take any call. All the test cases failed during automation run needs to be analyzed to check the validity of having a bug. There could be n number of bugs or can be one bug causing n numbers of failures. This type of report would give a colorful representation about failures.

Why Reporting ?

Test reports are part of framework.Test report analysis is part an parcel of an automator. It is a painful and laborious job. We can use some kind of automation by making the test result visually good and utility friendly. The utility will determine the analysis and report.

Advantages of Reporting

The objective of this code to create an HTML test report through QTP/UFT. Reporting is considered a significant challenge in Testing process.

With such representation of defects/failures, we can easily identify the design/process and tool issues. These will help in the below way:

  1. Reduce manual labor cost
  2. Improve product quality
  3. Improves readability during analysis when provided comments.
  4. Increase testing flexibility while showing custom functions(like sendkeys etc)
  5. free up automation and manual testers for another testing.
  6. It will make the defects/failures/errors visible. It shows how defects can be prevented from propagating to production.
  7. The easily understandable format for all level of management.

For creating HTML report in VBScript or UFT or any other langugaes,we will be using FileSystemObject’s Input Output methods.

The objective of the below code is to embed HTML tags to create HTML pages. This post will show step by step guide how to setup a HTML report code.

A simple HTML document Creation


Option Explicit
Dim FSOObject,strResulFile
Set FSOObject=CreateObject("Scripting.FileSystemObject")
Set strResulFile=FSOObject.OpenTextFile("D:\Test\Report.HTML",2,True)
strResulFile.WriteLine("<HTML>")
strResulFile.WriteLine("<HEAD>")
strResulFile.WriteLine("<TITLE>Test Report</TITLE>")
strResulFile.WriteLine("</HEAD>")
strResulFile.WriteLine("<BODY>")
strResulFile.WriteLine("It is a sample report")
strResulFile.WriteLine("</BODY>")
strResulFile.WriteLine("</HTML">)
strResulFile.Close()

While further improving , we can include the constants like:

Const cForReading=1Const cForWritting=2
Const cForAppending=8
Const cTitle="Test Report"

These constants will help to manipulate the HTML output in different ways.

As the test result will be displayed in tabular manner. We can also break the page into several other segments.like-

  • Executive summary
  • Detailed Summary
  • Test execution report details etc

As there are two or more tables are involved,it is best to create several utility subroutine for re-usability purpose.

The subroutines can be on:

  • BeginTableDefinition()
  • EndTableDefinition()
  • WriteTableHeader()
  • WriteTableSubHeader()
  • WriteHeaderPage()
  • WriteFooterPage()
  • DetermineFileName() and so on.

Details of WriteHeaderPage()

The header code setup will be as follows:

Sub WriteHeaderPage()
strResulFile.WriteLine("<HTML>")
strResulFile.WriteLine("<HEAD>")
strResulFile.WriteLine("<TITLE>Test Report</TITLE>")
strResulFile.WriteLine("</HEAD>")
strResulFile.WriteLine("<BODY>")

We can include style sheet information as well

Sub WriteHeaderPage()
strResulFile.WriteLine("<HTML>")
strResulFile.WriteLine("<HEAD>")
strResulFile.WriteLine("<STYLE>")
strResulFile.WriteLine("TD{Font-family:arial;")
strResulFile.WriteLine("Font-size:11pt;")
strResulFile.WriteLine("border-top:thin ridge black")
strResulFile.WriteLine("border-botton:thin ridge black")
strResulFile.WriteLine("border-left:thin ridge black")
strResulFile.WriteLine("border-right:thin ridge black}")
strResulFile.WriteLine("</STYLE>")
strResulFile.WriteLine("<TITLE>Test Report</TITLE>")
strResulFile.WriteLine("</HEAD>")
strResulFile.WriteLine("<BODY>")

Details of BeginTableDefinition()

Sub BeginTableDefinition()
strResulFile.WriteLine("<TABLE width='100%' border='1' CellSpacing='1' CellPadding='1'>")
End Sub

Details of EndTableDefinition()

Sub EndTableDefinition()
strResulFile.WriteLine("</TABLE>")
End Sub

Details of WriteTableHeader()

Sub WriteTableHeader(strTableHeader)
strResulFile.WriteLine("<tr>")
strResulFile.WriteLine("<td colspan='5' style='background:purple"&
color:red;>")
strResulFile.WriteLine("<center><b>"&strTableHeader &"</b></center></td>)
strResulFile.WriteLine("</tr>")
End Sub

Note : Here we have taken the strTableHeader as parameter, hence we can construct that outside of the code and push it to the HTML subroutine.

Details of WriteTableSubHeader()

Sub WriteTableSubHeader(strTableSubHeader)
strResulFile.WriteLine("<tr>")
strResulFile.WriteLine("<td colspan='3'>")
strResulFile.WriteLine("<b>"&strTableSubHeader&"</b></td>)
strResulFile.WriteLine("</tr>")
End Sub

Details of WriteFooterPage()

Sub WriteFooterPage()
strResulFile.WriteLine("</body>")
strResulFile.WriteLine("</HTML>")
End Sub

Change the file Name- DetermineFileName()

Sub DetermineFileName()
DetermineFileName=Replace(Date(),"/","-")
End Sub

HTML Report Out code


Function WriteResultsData()
Dim valisTestCaseID ="1" ,Environment.Value(”tion_no”),sProducts="class",Environment.Value(”Product_name”),
sTestcaseDesc="Animesh",Environment.Value("Customer_Name"),sPolicy_ID="Excell line"&(sTestCaseID+1)
‘// Change the below path
Screen_Shot_Path= “D:\AnimeshTempProblem_new_”
dim sTablePath1
mynow=now
mynow=replace( mynow,” “,”_”)
mynow=replace( mynow,”/”,”_”)
mynow=replace( mynow,”:”,”_”)
sScreenPath=Screen_Shot_Path + sname + mynowsScreenPath1=Screen_Shot_PathDesktop.CaptureBitmap sScreenPath & “.png”,true
sScreenPath1=sScreenPath1+”.html”color=”Green”
Dim fso, f, ts
Const ForReading = 1, ForWriting = 2,ForAppending = 8
sScreenPath= sScreenPath & “.png”
Set fso = CreateObject(”Scripting.FileSystemObject”)
filespec=sScreenPath1If (fso.FileExists(filespec)) Then
Set f = fso.OpenTextFile(sScreenPath1, ForReading)
ReadAllTextFile = f.ReadAll
ReadAllTextFile=replace(ReadAllTextFile,”
Company name Automation Testing Reports
“,”")
ReadAllTextFile=replace(ReadAllTextFile,”
TestCase ID
Client_Name
Products
Policy_ID
Date
ScreenShotPath
TestCase ID
Client_Name
Products
Policy_ID
Date
ScreenShotPath
“,”")
ReadAllTextFile=replace(ReadAllTextFile,”
TestCase ID
Client_Name
Products
Policy_ID
Date
ScreenShotPath
“,”")ReadAllTextFile= replace ( ReadAllTextFile,”
“,”")ReadAllTextFile= replace ( ReadAllTextFile,”
“,”")ReadAllTextFile= replace ( ReadAllTextFile,”“,”")
Set f = fso.OpenTextFile(sScreenPath1, ForWriting, True)
f.writeline”
Company name Automation Testing Reports
TestCase ID
Client_Name
Products
Policy_ID
Date
ScreenShotPath
“& ReadAllTextFile &”
“& sTestCaseID &”
“&sTestcaseDesc&”
“& sProducts &”
“& sPolicy_ID &”
“& Now &”
” & sScreenPath &”
”
f.close
Else
set myfile=fso.CreateTextFile (sScreenPath1 ,true) ‘ Create a file.
myfile.writeline”
Company name Automation Testing Reports
TestCase ID
Client_Name
Products
Policy_ID
Date
ScreenShotPath
“& sTestCaseID &”
“&sTestcaseDesc&”
“& sProducts &”
“& sPolicy_ID &”
“& Now &”
” & sScreenPath &”
”
myfile.close
End If
end function

another way  to display the error number and description


Public Function FunctionName(Object, Method, Arguments, retVal).
Proposed Function Body...
/* Code */
Set Props = Object.GetTOProperties
PropsCount = Props.Count
Desc = "Operation Failed." & vbCrLf & "Object Description: " & vbCrLf
For i = 0 To PropsCount - 1
PropName = Props(i).Name
PropValue = Props(i).Value
Desc = Desc & PropName & " = " & PropValue & vbCrLf
Next
reporter.ReportEvent micFail , "Error " , Desc & vbCrLf & "Failed On: " & Method

These concepts are useful during Interview in UFT or while preparation for certifications.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 23
  • 23
  • 12
  • 22
  •  
  •  
  •  
  •  
  •  
  •  
    80
    Shares

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here