Showing posts with label ALM / QC. Show all posts
Showing posts with label ALM / QC. Show all posts

Friday, September 14, 2012

QC OTA API Filter usage in Ruby

Creating filters can be one of the trickiest things in QC OTA API usage. The first thing you might run into when using Ruby is how you set a filter. In Visual Basic you set a filter like this:

testsetFilter.Filter("CY_CYCLE_ID") = "> 0"

However, in Ruby you have to use the setproperty method e.g.

testsetFilter.setproperty('Filter', 'CY_CYCLE_ID', '> 0')

There were a couple of filters that I was struggling with, but finally got them working. The first one was when I wanted to filter only test cases for some specific test sets in the Test Lab. The working Ruby code looks like this:

testsetf = qc.TestSetFactory
testsetFilter = testsetf.Filter
testsetFilter.setproperty('Filter', 'CY_CYCLE_ID', '> 0')
testsetl = testsetf.NewList(testsetFilter.Text)
 

testf = qc.TestFactory
testFilter = testf.Filter
testFilter.setproperty('XFilter','TEST-TESTSET',testsetFilter.Text)
testl = testFilter.NewList()

... and I have a list with the filtered tests.


The second problem was with filtering tests for only a specific folder path in Test Plan. The working Ruby code looks like this:

aFilter.setproperty('Filter', 'TS_SUBJECT', "^Subject\\release1^")

... using the TS_PATH property only returned empty value and the trick with TS_SUBJECT property was to use "^ and ^" before and after the value. To get the test path from a list of tests e.g.

thisTest.Field('TS_SUBJECT').Path

Tuesday, August 28, 2012

ALM / QC integration using OTA API

To integrate your test automation tools with HP Quality Center / Application Lifecycle Management, the easiest way is to use QC's Open Test Architecture (OTA) API.

OTA API is a COM library that enables you to integrate external applications with QC. Through this interface you can do most of the same tasks as you can do through the GUI.

To be able to access OTA API from your PC, you have to install the HP Quality Center Connectivity Add-in. To do so, go to Help -> Add-ins page and select HP Quality Center Connectivity. It will download the OTAClient.dll to your PC.

Here is an example script in Ruby, which counts the amount of open defects in QC:

require 'win32ole'

opendefects = 0

# Create the TDConnection object
qc = WIN32OLE.new('TDApiOle80.TDConnection')

qcserver = 'http://localhost:8080/qcbin/'

# Initiate connection to the QC server
qc.InitConnectionEx(qcserver)                     
puts "Connection status: #{qc.Connected}"                         

# Authenticates to QC
qc.Login("myuser", "mypassword")                      
puts "Logged in status: #{qc.LoggedIn}"

# Connect to the QC Domain and Project
qc.Connect("MYDOMAIN", "myproject")                 
puts "Project Name: #{qc.ProjectName}"

# Get defect list and count open defects
bugf = qc.BugFactory
bugl = bugf.NewList("")

for thisBug in bugl
    if thisBug.Status == "New" or thisBug.Status == "Open" or thisBug.Status == "Reopen"
        opendefects = opendefects+1
    end
end

# Disconnect and Logout from QC
qc.Disconnect
qc.Logout
puts "Logged in status: #{qc.LoggedIn}"

# Release connection from the QC server
qc.ReleaseConnection
puts "Connection status: #{qc.Connected}"

# Print results
puts "Total number of defects: " + bugl.count.to_s
puts "Total number of open defects: " + opendefects.to_s



... and the output should be something like:

Connection status: true
Logged in status: true
Project Name: myproject
Logged in status: false
Connection status: false
Total number of defects: 52
Total number of open defects: 5