Generate HTML Report Through QTP/UFT

Test Automation As a Service
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.

Ads code goes here

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.
READ  Learn File System Object(FSO) in UFT or QTP or VBScript Free

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.

READ  How to Get List Name of a SharePoint link in UFT ?

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.
READ  Best Error Handling in VBScript or in UFT

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.

Share and Enjoy !

14 thoughts on “Generate HTML Report Through QTP/UFT”

  1. hello!,I really like your writing so so much! proportion we keep up a correspondence more about your article on AOL? I require an expert on this area to unravel my problem. May be that is you! Looking forward to look you.

  2. Hey I know this is off topic but I was wondering if you knew
    of any widgets I could add to my blog that automatically tweet my
    newest twitter updates. I’ve been looking
    for a plug-in like this for quite some time and was hoping maybe you would have some experience with something
    like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to your new updates.

  3. Hello to all, the contents present at this web page are truly awesome for people experience, well, keep up the nice work fellows.

  4. Hi, this weekend is pleasant in favor of me, because this moment i am
    reading this fantastic educational piece of writing here at my
    house.

  5. Hey I know this is off topic but I was wondering if you
    knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.

    I’ve been looking for a plug-in like this for quite some
    time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and
    I look forward to your new updates. adreamoftrains web
    hosting companies

  6. I believe this is one of the such a lot important info for me.
    And i am satisfied studying your article. However want to statement on some
    basic issues, The web site style is wonderful, the articles is actually
    nice : D. Good job, cheers

  7. Pingback: Learn File System Object(FSO) In UFT Or QTP Or VBScript Free - Tech Travel Hub

  8. I wanted to thank you for this great read!! I certainly enjoyed
    every little bit of it. I’ve got you book marked to check out
    new things you post…

  9. Pingback: Google

  10. Pingback: Google

  11. Pingback: Google

  12. Pingback: Google

  13. Pingback: Google

Leave a Comment

Your email address will not be published. Required fields are marked *