kv1481 Absent Member.
Absent Member.
2945 views

How to use GetObject method to get an existing instance of QTP

Hi All,

 

How can one use GetObject method to get an existing instance of QTP.

I would like to retrieve some information from QTP while script is executing through another vbs script which would be executed manually to retrieve some details of QTP.

And later would like to use the methods available in AOM.

 

Is this possible, if so how can i achieve this.

 

Your thoughts and ideas would be much appreciated.

 

Thanks in advance,

kv

0 Likes
3 Replies
kv1481 Absent Member.
Absent Member.

Re: How to use GetObject method to get an existing instance of QTP

Hi All,

 

Following is the piece of code throught which one can get an existing instance of QTP.

Now my question is .. .. is there a way to load functionlibraries during runtime. Using AOM from an external vbscript using the code similar to below.


Set objGetqtp = GetObject("","QuickTest.Application")
'MsgBox objGetqtp.test.Author
Set lst = objGetqtp.test.Actions
msgbox lst.count
For ctr = 1 to lst.count - 1
      MsgBox lst(ctr).Name 'To fetch the current action name getting executed
Next

 

Any thoughts??

 

Thanks in Advance,

kv

0 Likes
Ana_Noncheva Absent Member.
Absent Member.

Re: How to use GetObject method to get an existing instance of QTP

Hello,

 

Please check the QTP AOM reference for this, there are also code examples.

Following is for associating a lib file with a test:

 

'************************************************************************************************************************
'Description:
'
'This example opens a test, configures the test's libraries' collection
'and saves the test.
'
'Assumptions:
'There is no unsaved test currently open in QuickTest.
'For more information, see the example for the Test.SaveAs method.
'************************************************************************************************************************

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtLibraries 'As QuickTest.TestLibraries ' Declare a test's libraries collection variable
Dim lngPosition

' Open QuickTest
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Launch QuickTest
qtApp.Visible = True ' Set QuickTest to be visible

' Open a test and get its libraries collection
qtApp.Open "C:\Tests\Test1", False, False ' Open a test
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries collection object

' Add Utilities.vbs if it's not in the collection
If qtLibraries.Find("C:\Utilities.vbs") = -1 Then ' If the library cannot be found in the collection
    qtLibraries.Add "C:\Utilities.vbs", 1 ' Add the library to the collection
End If

' If we "pushed" Math.vbs - place it back at position 1
If qtLibraries.Count > 1 And qtLibraries.Item(2) = "C:\Math.vbs" Then ' If there is more than one library and Math.vbs is in position 2
    qtLibraries.MoveToPos 1, 2 ' Switch between two first libraries
End If

' If Debug.vbs is in the collection - remove it
lngPosition = qtLibraries.Find("C:\Debug.vbs") ' Try finding the Debug.vbs library
If lngPosition <> -1 Then ' If the library was found in the collection
    qtLibraries.Remove lngPosition ' Remove it
End If

' Set the new libraries configuration as a default
qtLibraries.SetAsDefault ' Set library files associated with the test as default for new ones

'Save the test and close QuickTest
qtApp.Test.Save ' Save the test
qtApp.Quit ' Quit QuickTest

Set qtLibraries = Nothing ' Release the test's libraries collection
Set qtApp = Nothing ' Release the Application object

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”
0 Likes
kv1481 Absent Member.
Absent Member.

Re: How to use GetObject method to get an existing instance of QTP

Hi Ana,

 

Thanks for the reply, yes i did try this but i get a message stating -

"Error: This operation cannot be performed during a run session."

 

Any other ways i can achieve, associating library during runtime after getting handle on existing instance?

 

Thanks in advance,

kv

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.