Sunday, February 27, 2011

How to Connect to Quality Centre using OTA API

Connect to Quality Center using OTA API

Private Function makeConnection(ByVal qcHostName$, qcDomain$, qcProject$, _
qcUser$, qcPassword$, Optional qcPort) As Boolean
'------------------------------------------------------------------------
' This routine makes the connection to the gobal TDConnection object,
' declared at the project level as Global tdc as TDConnection,
' and connects the user to the specified project.
'-----------------------------------------------------------------------
Dim qcServer As String
Const fName = "makeConnection" 'For error message

On Error GoTo makeConnectionErr
errmsg = ""

'Construct server argument of format "http://server:port/qcbin"
qcServer = "http://" & qcHostName

If Not (IsMissing(qcPort)) Then
If Len(qcPort) > 0 Then qcServer = qcServer & ":" & qcPort
End If

qcServer = qcServer & "/qcbin"

errmsg = "Failed to create TDConnection"
If (tdc Is Nothing) Then Set tdc = New TDConnection
If (tdc Is Nothing) Then GoTo makeConnectionErr
errmsg = ""
tdc.InitConnectionEx qcServer

'Log on to server
tdc.Login qcUser, qcPassword

' Connect to the project and user
tdc.Connect qcDomain, qcProject
makeConnection = SUCCESS
Exit Function

makeConnectionErr:
ErrHandler err, fName, err.Description & vbCrLf & errmsg
makeConnection = FAILURE
End Function

Here you can customise this to be a public function and create an object as in QcObject to connect to Quality Centre and set it to Nothing once the job is done. Some issues I have encountered while working with OTA API is if you keep connected to the object and working away for long time, you may get Automation Error: suggesting Quality Centre connections is no more available or something similar to this. Its always suggested to connect to it before performing an operation and close the connection once the job done and so on.

1 comment:

  1. How to create test set folder and test set name inside test lab using quality center OTA api?

    ReplyDelete