Login   /   Register

Report Hierarchical Events in QTP Log

Rate this article
     4 votes, average: 4.25 out of 54 votes, average: 4.25 out of 54 votes, average: 4.25 out of 54 votes, average: 4.25 out of 54 votes, average: 4.25 out of 5
Loading ... Loading ...
April 11th, 2008 by Yaron Assa

Motivation

The QTP native log has many drawbacks, especially if your scripts relay heavily on Functions. While Actions are reported in an hierarchical structure (i.e. nested according to their call chain), events reported by function are reported in a flat, unsorted manner. This can be illustrated by the following example:

image image

The following QTip will allow you to report custom events in an hierarchical manner. This will allow you to achieve reports like this one:

image

Notice that the report is structured as an hierarchical tree, even though all the events are executed within the same action. You can decide when to open a new node, and when to report in a flat manner.

How it’s done

The technique relays on three steps:

  1. Creating a new node in the results tree.
  2. Reporting events / Creating additional sub-nodes (they will be children / grandchildren of the node we’ve created)
  3. Climbing back "up" the hierarchy and reporting more events (they will be siblings of the node we’ve created)

 

Creating a new node in the results tree:

'dicMetaDescription will hold our new node’s details
Set dicMetaDescription = CreateObject("Scripting.Dictionary")
 
'Set node status
dicMetaDescription("Status") = MicDone
 
'Set node’s header
dicMetaDescription("PlainTextNodeName") = "A node with children"
 
'Set the node’s details. HTML is allowed
dicMetaDescription("StepHtmlInfo") = "<DIV align=left><H1>HTML layout testing</H1><b>This</b> can be handy to have.</DIV>"
 
'Some backdoor settings:
dicMetaDescription("DllIconIndex") = 206
dicMetaDescription("DllIconSelIndex") = 206
dicMetaDescription("DllPAth") = "C:\Program Files\Mercury Interactive\QuickTest Professional\bin\ContextManager.dll"
'If you’re using QTP 9.5, replace the previous line into:
'dicMetaDescription("DllPAth") = "C:\Program Files\HP\QuickTest Professional\bin\ContextManager.dll"
 
'Actually do the report, and get the new report node ID
intContext = Reporter.LogEvent("User", dicMetaDescription, Reporter.GetContext)
 
'Set the new report node as a parent
'From now on, all reports will be added under this node
Reporter.SetContext intContext

Reporting Events:

This is done the old fashion way:

Reporter.ReportEvent MicPass, "Some Header", "Some Details"

If we’d like, we could open new nodes under our current node by repeating step 1.

Climbing up the hierarchy:

After reporting a few events under the current node, we’d like to "climb up", and report the following events in a higher level (i.e., no longer under the node). You may need to do this several times in order to return to the report’s "top" level, depending on the number of sub-nodes you’ve created in your report.

'Now return to the parent level:
Reporter.UnSetContext

*This article is based on stalis’s post in SQAForums

Posted in Reports

5 Responses to “Report Hierarchical Events in QTP Log”

  1. Santhan Says:

    [-]

    Can we read content we set the same way?

  2. Yaron Assa Says:

    [-]

    Excellent question.

    As far as I know - no…

  3. Stefan Thelenius Says:

    [+]

    Thanks for the info (thanks to Stalis as well). When using functions instead of actions this method is very useful in order to ... ...

  4. Stefan Thelenius Says:

    [+]

    Reposting due to problems with quotation marks (hope it works better this time): dicMetaDescription("StepHtmlInfo") = _ "" &am... ...

  5. Stefan Thelenius Says:

    [+]

    Last try (sorry for spaming, forgot about escaping HTML elements): dicMetaDescription("StepHtmlInfo") = "<DIV align=left>... ...

Leave a Reply

You must be logged in to post a comment.

This article was viewed 1922 times