Last week, I provided consultancy regarding QuickTest Professional and the WebServices add-in (more about this add-in next week!). At some point, the customer came to me and asked for advice regarding access to the Quality Center (QC) database. What was interesting about this query is that I discovered that the customer was not aware about the Open Test Architecture (OTA).
So, today, I want to give you insight about what is the OTA and give you a short example showing what you can achieve with it.
First of all, the OTA is:
- An integration API that allows the integration of any third-party tool within Quality Center;
- A manipulation API that permits the interaction with the Quality Center application without having to use the GUI frontend.
We will not talk about the integration API so if you are interested in learning more, log on your QC server then select Help > Documentation and read the OTA Guide.
The QC Client/Server architecture is a 3-tier architecture (web server, application server and database server). The figure below shows the interaction between the components. They consist of:
- Client application: the QC GUI front-end that you use when accessing Quality Center through your browser. Or any other application that communicates with QC using the API;
- Web server: the QC communication between the client and the server are performed using the HTTP protocol;
- Application server: by default, the JBOSS application server is installed with Quality Center. the QC application is built using Java and requires a J2EE application server. The J2EE platform is particularly well designed for client/server applications over the Internet
- Quality Center application: developed to be executed on a J2EE application server;
- Database Server: the database that holds the Quality Center information.
Quality Center API
The manipulation API is called Quality Center API and allows the interaction with Quality Center. It also allows you to interact with the database through the API making the interactions more secure. Also, it avoids your DBA (DataBase Administrator) having to provide an access to the database server(s) hosting the Quality Center database(s).
The API has only 1 entry point which is the TDConnection object. From this object, you can access a lot of Quality Center functionalities. The API functions are accessible through VBScript and any COM aware programming languages. It means that you can use this API as a standalone .VBS application, a macro in an Excel file, a script in QuickTest Professional or any other application where you would like to integrate such functionalities.
As an example, we are going to download all the defects that are stored on a Quality Center project using the Excel application.
The steps involve:
- Connect to the project
- Run a query to retrieve a list of defects
- Store the result in an Excel worksheet
1. Connect to the project
Each project stored in a Quality Center server is identified by its pair Domain/Project and a project is accessible only if the user belongs to this project. The connection to a server can be done by using only 4 lines of code:
‘ Return the TDConnection object.
Set QCConnection = CreateObject(“TDApiOle80.TDConnection”)
QCConnection.login “<username>”, “<password>”
‘ DEFAULT = Domain, QualityCenter_Demo = Project
QCConnection.Connect “DEFAULT”, “QualityCenter_Demo”
2. Execute a query
To execute a query in Quality Center, you have several options available.
The first one is to use the Command object. This object can run SQL queries for any Quality Center table. However, you need to be aware of what table to query and make sure you know what you do because you can mess up Quality Center. Also, this Command object can be used only if you are part of the TDAdmin group in this project.
The second one is to use a Factory object. The factory object returns objects that are part of the API, restricting the user from making mistakes. This is the method we’ll be using in this article. To access the defects, we are using the BugFactory:
Dim BugFactory, BugList
Set BugFactory = QCConnection.BugFactory
Set BugList = BugFactory.NewList(“”) ‘ Get a list of all the defects.
3. Store the result in an Excel worksheet.
We assume that you are running this script from a VBS file. Consequently, we have to open Excel first, then store the data in an Excel worksheet:
Dim Bug, Excel, Sheet
Set Excel = CreateObject(“Excel.Application”) ‘ Open Excel
Excel.WorkBooks.Add() ‘ Add a new workbook
‘ Get the first worksheet.
Set Sheet = Excel.ActiveSheet
Dim Bug, Row
Row = 1
‘ Iterate through all the defects.
For Each Bug In BugList
‘ Save a specified set of fields.
Sheet.Cells(Row, 1).Value = Bug.Field(“BG_BUG_ID”)
Sheet.Cells(Row, 2).Value = Bug.Summary
Sheet.Cells(Row, 3).Value = Bug.DetectedBy
Sheet.Cells(Row, 4).Value = Bug.Priority
Sheet.Cells(Row, 5).Value = Bug.Status
Sheet.Cells(Row, 6).Value = Bug.AssignedTo
Row = Row + 1
‘ Save the newly created workbook and close Excel.
Today, you have seen how to use the QC API to perform a simple task such as retrieving a list of defects. Bear in mind that you can do much more than that.
Find here a more complete example of the script described in this article.