Generate HTML Report Through QTP/UFT

1
382
Spread the love
  • 23
  • 23
  • 12
  • 23
  •  
  •  
  •  
  •  
  •  
  •  
    81
    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 the 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 levels of management.

For creating an HTML report in VBScript or UFT or any other languages, 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 set up an 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 a 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 subroutines 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 the 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.

Other components to generate various reporting

Initialization file(.INI)

Apart from creating an HTML file, you can also create an Initialization file(.INI). An INI file is used to store configuration to control the execution. The master driver script reads the.INI file and executes the script.

INI file is an ASCII text plain file having extension as .ini. INI files allow us to make necessary to an application, utility or scripts without changing the code. It prevents hard coding in the scripts.

Importance of INI file

  1. Configuration files will be outside of the script.
  2. Many settings possible without disturbing the actual script.
  3. Avoid accidental manual errors.

The disadvantages of .ini file

.INI files are stored in hard drive hence to read or update, we need to have a disk I/O code which may slow down the script execution.

Structure of .INI file

  • Each .INI file should have zero or more key-value pairs.
  • .INI file can contain comments. Comments generally start with a semicolon like
    ; sample INI file
  • We can have blank spaces in the .INI file. But it is used to have good orientation. When the .INI file is processed, the engine ignores the blank space.

Important functions if working with .INI file

  1. FileExists()-> Checks if the same .INI file already exists or not.
  2. OpenTextFile()->Opens the .INI file to get the contents.
  3. ReadLine()->Read one configuration at a time. The configurations are provided in the .ini file in a key-value manner. This will read line by line.
  4. Close()-> Once all required configuration are read, we need to close it.

Log generator

You can also take the help of a Log generator that generates logs during the execution of the script. This will log pass, fail, warning and other step information. It can be used to generate other logging as well.

Important functions for log reporting

  1. FileExists()-> Checks if the same log file already exists or not.
  2. OpenTextFile()->Opens the log file to get the contents.
  3. ReadLine()-> Reads the logs from logfile.
  4. SkipLine()->Skips the logger header info while reading the log.
  5. WriteLine()->Writes a line into log file.
  6. WriteBlankLines()-> Writes blank lines and formats the presentation.
  7. Close()->Closes a log file upon completion of the log reading or writing.

Log Analyzer

Log Analyzer is a separate VBScript to analyze the log Infos after reading various log files.

Prediction generator

A VBScript code to predict the errors and point out possible reasons and sources.

Script Scheduler

A scheduler program to execute the script at a regular interval and contribute to the log file.

Archive management

Ensure that the VBScript reports, logs and prediction files are achived for future reference.

Important functions for archiving

  1. FileExists()-> Checks if the same log file already exists or not.
  2. MoveFile()-> Move the required files to the archival folder.
  3. DeleteFile()->Delete a log file or report file when not required anymore.
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
  • 23
  •  
  •  
  •  
  •  
  •  
  •  
    81
    Shares

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here