[This below example is based on a post in advancedqtp.com]
In QTP while actions are shown in hierarchy, events reported by functions are reported in a flat, unsorted manner.
The following section will allow you to report results of even functions in a hierarchical way for example.
Let’s move straightway to an example and I will explain what is happening here after an example. Create a test called Test 1 and three function libraries F1, F2 and F3.
Just type the below code in Test and function libraries respectively. Associate the function libraries with the test and run the test. It will show the results as shown below in the screenshot with NO hierarchies at all.
Test 1
f1
F1
Function f1 ()
f2
End function
F2
Function f2 ()
f3
End function
F3
Function f3 ()
Msgbox "function f3 says hello"
End function
Now we will add some lines of code in all of these function libraries and a test, so now these look like as below: This extra added code is to add a New Node in the report hierarchy. This is a very simple example – Test 1 is calling F1, F1 is calling F2, and F2 is calling F3. Each function is returning a value of 1 to its calling function (e.g. F1 is returning a value of 1 to Test 1, F2 is returning a value of 1 to F1 and so on). I am checking that returned value in “if condition” and setting the pass and fail accordingly. You can see below screenshot that how different nodes are created.
[This is just a very simple example and can be done in many other different ways and this may not be the best of them. This is just to make you understand]
Test 1
F1
F2
F3