3

Quality Center OTA API provides interfaces like ISupportCopyPaste (copy/paste data using clipboard). The documented way to get a reference to an implemented interface is:

'Declare a variable to hold the reference for the interface 
Dim bf As IBaseFactory2 
' By assigning the implementing object reference to the 
' IBaseFactory2 type variable, the type is cast to that of the 
' implemented interface. The new variable is a reference to the 
' IBaseFactory2 interface within the parent object. 
' tdc is the global TDConnection object. 
Set bf = tdc.BugFactory

The above code is in VB (which I don't want to use).
However, QTP does not allow 'As' in Dim statement.
Can anyone tell how to get a reference using QTP ?
Any other solution to this problem ? eg: using Python Win32

Manas
  • 113
  • 1
  • 7

2 Answers2

2

The reason QTP "doesn't allow As in Dim statement" is that QTP scripts are based on VBScript not VB, and As is VB only (VBScript is dynamically typed).

If you want to use OTA in QTP you can try using the QCUtil object that QTP exposes (see QTP's help for more information).

If QCUtil doesn't give you the objects you need you can use any language that knows how to interact with COM in order to create the OTA object (these languages include but are not limited to, VB, VBScript, C++ and .NET languages, I'm not sure about Python).

If you do choose to use VBScript you can create the OTA object using VBScript's CreateObject function (search for CreateObject OTA for more information).

Motti
  • 110,860
  • 49
  • 189
  • 262
  • 1
    Thanks for a much better explanation. I am already able to do all of the things you mentioned using in VBScript and Python. But I want to "copy" TestSets from one folder to another in QC. I couldn't find any method to Copy (though there is a Move method) in the OTA reference. One way is to implement ISupportCopyPaste interface. So, my question is how to do that ? – Manas Jan 24 '11 at 04:55
  • 1
    @manas, if you have MS Excel installed, you can use VBA, which does support casting via As in the Dim statement. In fact, I have used Excel's VBA to automate both the QC and QTP APIs with great success. – Tom E Jan 25 '11 at 16:10
0

In theory most of OTA exposed objects and the interfaces they expose are IDispatch.

In other words; when working with these objects from vbscript, you don't really have to cast the object at hand to ISupportCopyPaste. You can just invoke the methods on the object at hand as if it was ISupportCopyPaste, you just need to get the method signature right.

Alex Shnayder
  • 1,362
  • 1
  • 13
  • 24
  • I tried the documented method signatures without success. Could you give/point me to any examples implementing Interfaces ? – Manas Feb 03 '11 at 12:18
  • To any rule there is an exception, and ISupportCopyPaste is that exception. ISupportCopyPaste is IUnknown and not IDispatch. – Alex Shnayder Feb 05 '11 at 20:43
  • The only option I see is either checking if QCUtils provides the functionality you need. Or you can write your own COM helper class (lets say in .net) which does allow IUnknown and QueryInterface calls. And ivoke that class from your script. – Alex Shnayder Feb 05 '11 at 20:53