In this post, we will learn about how to create a connection to ALM using OTA API.
Open Test Architecture is an API shipped with HP ALM/QC, for automating background tasks like modifying bulk field values or downloading all of the attachments from the defects module. We can also use this API for Generating bulk reports, custom graphs and have the functionality built which is not available otherwise using the ALM/QC front end application.
OTA API’s object will be downloaded and registered in the machine when we open ALM for the first time. Once the components are registered, you can use the OTA COM Type Library for connecting ALM using any programming language which supports COM objects.
we will use Excel 2010 for connecting and accessing ALM/QC using OTA API.
2. Connecting to ALM using OTA API
Below are the steps for using OTA API for ALM Connection
A) Open Excel and Click on Developer ribbon and Click Visual Basic.
B) Click on Tools-> References and Check “OTA COM Type Library”.
Once we have the reference for this library, we can use the following code for connecting to ALM/QC
Dim ErrorString As String 'Create Connection Object of OTA API Dim OQCConnection As New TDAPIOLELib.TDConnection Sub TestALMOTAConnection() If ConnectALM("http://yourQCServer/qcbin", "yourusername", "password", "yourdomainname", "yourprojectnane") = True Then MsgBox "Connected to ALM" If DisConnectALM = True Then MsgBox "Project Disconnected Successfuly" Else MsgBox ErrString End If Else MsgBox ErrorString End If End Sub Public Function ConnectALM(URL As String, UserName As String, Password As String, Domain As String, Project As String) On Error GoTo Err_Handler ErrorString = "" 'Initiate connection with ALM Server OQCConnection.InitConnectionEx URL 'Connect to User OQCConnection.Login UserName, Password 'Connect to Domain and Project OQCConnection.Connect Domain, Project '"Successfully Connected to the project, Enjoy!!!" ConnectALM = True Exit Function Err_Handler: 'Check if the connection is successfull If OQCConnection.Connected = False Then ErrorString = "QC Server URL Initialization failed!!!" ConnectALM = False Exit Function End If 'Check if Login is Successfull If OQCConnection.LoggedIn = False Then ErrorString = "Unable to Login to ALM using the provided Credentials" ConnectALM = False Exit Function End If 'Check if project is connected If OQCConnection.ProjectConnected = False Then ErrorString = "Unable to Connect to the Domain or Project" ConnectALM = False End If End Function Public Function DisConnectALM() On Error GoTo Err_Handler ErrString = "" If OQCConnection.ProjectConnected Then OQCConnection.Disconnect End If If OQCConnection.LoggedIn Then OQCConnection.Logout End If If OQCConnection.Connected Then OQCConnection.ReleaseConnection End If 'Logged Out of QC DisConnectQC = True Exit Function Err_Handler: If OQCConnection.Connected Then ErrString = "Error Occurred while Disconnecting the QC Connection Object" End If If OQCConnection.ProjectConnected Then ErrString = "Error Occurred while disconnecting project" End If If OQCConnection.LoggedIn Then ErrString = "Error Occurred while Loggin out the User" End If DisConnectQC = False End Function
Once, you copy the above code, update the variables for a call to the function ConnectALM and execute TestOTAALMConnection function. If everything works fine then you should see a message ‘Connected to ALM’.
Now, let’s understand how the code works here,
1) ALM URL: For connecting to ALM using OTA API, we must use the URL till qcbin instead of full ALM URL, e.g. http://YourServer/qcbin.
All other variables should be provided with the values, you are using for connecting to ALM/QC
1) InitConnectionEx: This function is used for initializing the connection between ALM and your code. If ALM server is accepting connections.
2) Connected: This property will be false if the connection initialization is not completed.
2) Login: Login functions accepts ALM Username and password and used for login to the ALM/QC Server.
3) LoggedIn: This property is used for identifying, if user login was successful or not in the previous step. Login function will through error and we will have to use
4) Connect: This function will accept domain name and project name and will connect to ALM Project.
5) ProjectConnected: This function will provide details about if the Connection to the project was successful.
Now let’s see how to disconnect ALM connection, which will be similar to Logout functionality using the ALM GUI.
For Logging out of ALM we have to call the corresponding logout functions to InitConnectionEx, Login and Connect. These functions are used in the DisConnectALM function. Below is the description of the function used for disconnecting ALM
1) Disconnect: This function will disconnect the ALM Project.
2) Logout: This function will log out the user connected.
3) ReleaseConnection: This function will release the ALM connection object, after calling this function we will loose all of the references with ALM server.
Below is the table for showing the method property relationship of the functions and properties used above
|ServerName||Empty String||Server Name||Server Name||Server Name||Server Name||Server Name||Empty String|
|ProjectName||Error||Empty String||Empty String||Project Name||Empty String||Empty String||Error|
We will discuss about accessing and changing specific ALM modules in the later posts.