Link: http://hi.baidu.com/widebright/blog/item/8b08ca95230a0247d1135ef5.html
The reporter public method provided by qtp by default is obviously unable to meet our common needs, so some people have discovered undisclosed methods. One of the mining methods is to use the debug function of qtp to locate the reporter object and view its property value and method name. Similarly, for other qtp objects we want to know, if the public method is not enough, we can also try to see if there are undisclosed methods available.
For more information about how to enhance the qtp debugging function, see:
Http://www.advancedqtp.com/2008/03/vs2008-pdm-dll-dramatically-improves-qtp%E2%80%99s-debug-engine/comment-page-1/
The main steps are as follows:
1. Install vs2008 [not necessary]
2. Register a DLL first when IE8 is installed. regsvr32 "c: \ Program Files \ Internet Explorer \ PDM. dll"
3. Download a PDM. dll and register it.
4. Restart the machine
Keywords: qtp, reporter, report, parent node, root node, structured
========================================================== = ====================================
During qtp debugging, you can add monitoring on qtp reporter objects in the watch window and find the following functions:
Certificate -----------------------------------------------------------------------------------------------------------------------------------
Getcontext () 'returns the ID of the current node.
Getparentid (ID) 'is used to get the ID of the parent node.
Logevent (ET, pdescription, parentid) 'is the main function. The first parameter is fixed with "user "? The second parameter is a dictionary object describing the node, and the third parameter is the ID to be added to the parent node. This function is used to create a new node. The function returns the new node number.
Reportevent (eventstatus, reportstepname, details, [imagefilepath]), which is published in qtp documentation.
Restorecontext () 'restores the current node status from the stack.
Setcontext (eventid) 'sets the current node as the node specified by the eventid parameter. Later reports will all exist as subnodes of this node.
Setregistryroot (Root) '.
Setstatus (ID, status) 'sets the status of the node specified by ID, and whether or not the micfail/micpass and other surface nodes are successfully run.
Storecontext () 'keeps the current node status on the stack.
Unsetcontext () 'unsets the current node.
Certificate -----------------------------------------------------------------------------------------------------------------------------------
Usage: Some people say that sometimes unsetcontext is not easy to use and do not know which node is restored after unsetcontext. Therefore, it is best to use getcontext to keep the previous node number, and then switch setcontext to the child node. When you need to return the parent node, use the saved node number and then setcontext. You can also use storecontext and restorecontext to save and switch data.
The dictionary that describes the object. The DLL attributes specify the resource icon in the directory and serve as the second icon in the browser tree. You can specify the dll path and ICO resource number for other icons. If nothing is specified, there is also an icon, but it is not very nice. Based on the execution result of the node, qtp also puts the incorrect check box and the Red Cross icon in front.
Qtp custom report entry
Dim curnodeid, childnodeid
Curnodeid = Reporter. getcontext ()
Set objdict = Createobject ("scripting. Dictionary ")
Objdict ("status") = micpass
Objdict ("plaintextnodename") = "Custom node"
Objdict ("Stephen tmlinfo") = "<Div align = left>
Testing Objdict ("dlliconindex") = 206
Objdict ("dlliconselindex") = 206
Objdict ("dllpath") = "C: \ HP \ quicktestprofessional \ bin \ contextmanager. dll"
'Report the m entry
Childnodeid = Reporter. logevent ("user", objdict, reporter. getcontext)
Reporter. setstatus childnodeid, micfail
Reporter. storecontext
Reporter. setcontext (childnodeid)
Reporter. reportevent micfail, "Step1", "Step1, failed"
'Add otherCodeAnd so on.
Childnodeid = Reporter. logevent ("user", objdict, childnodeid)
Reporter. setstatus childnodeid, micdone
Reporter. setcontext (childnodeid)
Reporter. reportevent micfail, "step2", "step2, failed"
'Add other code that calls the action here.
Childnodeid = Reporter. logevent ("user", objdict, childnodeid)
Reporter. setstatus childnodeid, micpass
Reporter. setcontext (childnodeid)
Reporter. reportevent micpass, "Step3", "Step3, failed"
Reporter. restorecontext
Reporter. reportevent micpass, "step4", "step4, failed"
======================================
Report generated by the code above
A problem found during the test is that when logevent is called to add nodes, the node can only be added in this execution order. That is to say, after creating a node 1, we quit to the parent node and then did something about other parallel relationships, such as adding a parallel level node 2, in this case, you cannot add a subnode to node 1. You can only add or add a parallel level to node 2. I don't know if I have made it clear, but I will understand it when you come across it. But this is not a problem.
Two common functions:
---------------------------------------------------
Function enterchildnode (nodename, decription)
Dim curnodeid, childnodeid, objdict
Set objdict = Createobject ("scripting. Dictionary ")
Objdict ("status") = micpass
Objdict ("plaintextnodename") = nodename
Objdict ("maid") = decription
Objdict ("dlliconindex") = 206
Objdict ("dlliconselindex") = 206
Objdict ("dllpath") = environment ("productdir") & "\ bin \ contextmanager. dll"
Curnodeid = Reporter. getcontext ()
Childnodeid = Reporter. logevent ("user", objdict, curnodeid)
Set objdict = nothing
Reporter. setcontext (childnodeid)
Enterchildnode = curnodeid
End Function
Function leavechildnode (parentid)
Reporter. setcontext parentid
End Function
Usage
Dim currentid
Currentid = enterchildnode ("node name", "description using HTML Syntax ")
'The code of the subnode is called here.
'The code of the subnode is called here.
Leavechildnode (currentid)
---------------------------------------------------
It is best to save the current ID and set the restoration method of setcontext. storecontext and restorecontext seem to be sometimes inaccurate. Maybe other internal applications also call these two functions.