Avoid Pure Virtual Function Call Error with Mercury.ObjectRepositoryUtil !!


We shall look into the ObjectRepositoryUtil object and an issue we will face if we do not properly release the object before exiting the program. An important note here is that we do not need to open QTP while developing code using the automation object model. We just need a .vbs (VB script) file to work with QTP's automation object model. I will not go into details of this but rather focus on the topic we are going to discuss.


When creating an object using Mercury.ObjectRepositoryUtil we must ensure that the objects are released after its use. Else we will get thrown with an exception, the "dreaded" R6025 - pure virtual function call error. This exception causes QTP to crash !!!



The exception would be thrown if you are not properly "releasing" the memory. Releasing memory attached to an object is achieved by "Set"ting your object to "Nothing".

For testing this lets first get prepared...
We first need a shared repository. For that, open a script you already have and go to Resources->Object Repository and then File -> Export Local Objects. Save your file as "C:\shared.tsr"
Now..lets open a new test and enter the following code

Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
RepositoryFrom.Load "C:\shared.tsr"
Set FromCollection = RepositoryFrom.GetChildren("Test Objects")
For itemno = 0 To FromCollection.Count - 1
Set TestObject = FromCollection.Item(itemno)
Msg = RepositoryFrom.GetLogicalName(TestObject)
MsgBox Msg
Set TestObject = Nothing 'Important to release memory <== Try commenting this line to see the error ;)
Next
Set FromCollection = Nothing 'Important to release memory
Set RepositoryFrom = Nothing 'Important to release memory


This is how your program should be. Always remember to release objects while playing with shared repositories to avoid getting the virtual function call error causing QTP to crash.
I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (9)

How to capture Checkpoint return value?

For those who are new to QTP, let me tell you a key functional testing feature provided by QTP - Checkpoint. The definition as per QTP Help is "A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property. This enables you to identify whether your application is functioning correctly. "



For eg: lets go to Google.




We see three links right of the search box. We will add a check to see if the text "Preferences" is present between the links "Advanced Search" and "Language Tools". QTP provides a feature called as Text checkpoint to accomplish this. So in QTP, we will click on Insert -> Checkpoint -> Text Checkpoint








Next we will click on the "Preferences" Link in Google. We would see that the checkpoint properties would be as shown below
Now you would see that your line of code in QTP would be

Browser("Google").Page("Google").Check CheckPoint("Google")
So far so good..... Your test result will show "Pass" if the checkpoint passed. QTP makes use of the "Check" method to work on a checkpoint. The return type for the Check method is a boolean value, meaning this would return a true or false. If it returns true, your results would show pass and if it returns false, your results would show a fail.
Ok...now to the topic related to the title of this post.... what if we want to capture this return value...!!!
Lets try the following...
retVal = Browser("Google").Page("Google").Check CheckPoint("Google")
Oops....what happened....




If you want to retrieve the return value of a checkpoint, you must add parentheses around the name of the checkpoint in the statement. When you call a function and expect a return value you must add parantheses. So your new statement would be
retVal = Browser("Google").Page("Google").Check(CheckPoint("Google"))
MsgBox retVal


This would give the message box with value True.
Hope this helped you all. Keep blogging. As always..

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (1)comments

Visitors

Website Counter