How to use Quality Center Open Test Architecture API

Recently I’ve encountered a task: to create a script that would connect to QC and run a test set. It was expected that the execution of this script will be initiated by Outlook. The main idea was – a notification comes to my inbox and Outlook runs the script that runs a test set.

I knew that QC (and QTP also) has its Open Test Architecture API. I’ve downloaded a manual from the QC and explored a connection method, took a peace of code that runs a test set and modified it.

Here is what I got:

‘===================================== ‘
‘ VBScript Source File — Created with SAPIEN Technologies PrimalScript 4.1

‘ NAME:

‘ AUTHOR: Vadim Nekhai
‘ DATE : 17.12.2007

‘ COMMENT:

‘====================================

‘Option Explicit

Public Sub RunTestSet(otdc, tsFolderName, tSetName, _
HostName, runWhere)

Dim TSetFact, tsList
Dim theTestSet
Dim tsTreeMgr
Dim tsFolder
Dim Scheduler
Dim nPath
Dim execStatus

‘ Get the test set tree manager from the test set factory
‘tdc is the global TDConnection object.
Set TSetFact = otdc.TestSetFactory
Set tsTreeMgr = otdc.TestSetTreeManager
‘ Get the test set folder passed as an argument to the example code
nPath = “Root\” & Trim(tsFolderName)
Set tsFolder = tsTreeMgr.NodeByPath(nPath)
If tsFolder Is Nothing Then
err.Raise vbObjectError + 1, “RunTestSet”, “Could not find folder ” & nPath
End If

‘ Search for the test set passed as an argument to the example code

Set tsList = tsFolder.FindTestSets(tSetName)

If tsList Is Nothing Then
err.Raise vbObjectError + 1, “RunTestSet”, “Could not find test set in the ” & nPath
End If

If tsList.Count > 1 Then
MsgBox “FindTestSets found more than one test set: refine search”
Exit Sub
ElseIf tsList.Count < 1 Then
MsgBox “FindTestSets: test set not found”
Exit Sub
End If
Set theTestSet = tsList.Item(1)
‘Debug.Print theTestSet.ID

‘Start the scheduler on the local machine
Set Scheduler = theTestSet.StartExecution(HostName)

‘Set up for the run depending on where the test instances
‘ are to execute.

Select Case runWhere
Case “RUN_LOCAL”
‘Run all tests on the local machine
Scheduler.RunAllLocally = True
Case “RUN_REMOTE”
‘Run tests on a specified remote machine
Scheduler.TdHostName = HostName
‘ RunAllLocally must not be set for
‘ remote invocation of tests.
‘ Do not do this:
‘ Scheduler.RunAllLocally = False
Case “RUN_PLANNED_HOST”
‘Run on the hosts as planned in the test set
Dim TSTestFact, TestList
Dim tsFilter
Dim TSTst
‘Get the test instances from the test set
Set TSTestFact = theTestSet.TSTestFactory
Set tsFilter = TSTestFact.Filter
tsFilter.Filter(“TC_CYCLE_ID”) = theTestSet.ID
Set TestList = TSTestFact.NewList(tsFilter.Text)
Scheduler.RunAllLocally = False
End Select

‘Run the tests
Scheduler.run

Set execStatus = Scheduler.ExecutionStatus

While (RunFinished = False)
execStatus.RefreshExecStatusInfo “all”, True
RunFinished = execStatus.Finished
Wend
End Sub

‘================================

Const qcHostName = “”
Const qcDomain = “”
Const qcProject = “” ‘Please define here the name of the project
Const qcUser = “” ‘Please define here the username
Const qcPassword = “” ‘Please define here the password
Dim tdc
Dim qcServer
Dim objArgs
Dim strArg
Dim strTestSet
Dim bRunCode

‘======GETTING ARGUMENTS==============
set objArgs = WScript.Arguments
If WScript.Arguments.Count<1 Or WScript.Arguments.Count>2 Then
WScript.Echo “Please enter the name of the test set”
bRunCode = False
Else
For Each strArg in objArgs
WScript.Echo strArg&” is starting…”
strTestSet = strArg
bRunCode = True
Next
End If
‘===========================================================

If bRunCode Then
qcServer = “http://&#8221; & qcHostName
qcServer = qcServer & “/qcbin”
Set tdc = CreateObject(“tdapiole80.tdconnection”)

If (tdc Is Nothing) Then
MsgBox “tdc object is empty”
End If

tdc.InitConnectionEx qcServer
tdc.Login qcUser, qcPassword
tdc.Connect qcDomain, qcProject

RunTestSet tdc, “Insert here path to the test set”, strTestSet , “Insert here the name of the machine”, “RUN_LOCAL”

‘Disconnect from the project
If tdc.Connected Then
tdc.Disconnect
End If
‘Log off the server
If tdc.LoggedIn Then
tdc.Logout
End If
‘Release the TDConnection object.
tdc.ReleaseConnection
”Check status (For illustrative purposes.)
Set tdc = Nothing
End IF

P.S. Please define in this script the path to the test set and the name of the machine where the test set is supposed to run. The script needs an argument – the name of the test set.

About these ads
Explore posts in the same categories: Automated testing, Testing

Tags: , , , ,

You can comment below, or link to this permanent URL from your own site.

21 Comments on “How to use Quality Center Open Test Architecture API”

  1. Damien Lyles Says:

    Thanks for posting this code. I’m trying to create a utility that will update the status of test instances within a test set. However, all of the examples that I see reference QCUtil. Can you point me to an example that uses otdc?

    Thanks.

    – Damien

  2. Ashok Says:

    hi,

    am ashok, am a test Eng.. do u have the QC open arcitecture API ..
    i mean do u have the QC automation reference model or COM Model of QC.

  3. feelsgood11 Says:

    Hi,
    You can get QC OTA from the download page.

  4. Eli Says:

    Thank you fore the post.
    The only problem I am having is the testset notification mail (Test results) is not working while using the VB file the execute the testset.
    Any idea why and how to make it work?

  5. feelsgood11 Says:

    Hello Eli,

    You are welcome.
    Probably you have to turn on an email notification in the properties of the test run.
    Unfortunately I cannot give more info.
    Hope you make it working.

    BR,
    Vadim

  6. Chris1234 Says:

    Feelsgood11 you said that you can get the QC OTA from the download page. Did you mean the add-in download page or is there another page that you are referring to?

    I checked that page but couldn’t find it. If you could give the exact location of this reference manual it would be greatly appreciated

  7. Yugandhar Says:

    Hi Frnd,
    i find this a very useful site.thanks for all ur efforts.I need some script help.let me explain u the scenario.

    I have a HTML Interface where i need to select what i need(data/input) which will generate an excel sheet for me with input data needed to be passed to QTP in a particular location on my machine.Now my problem is like i need script to to have a button on HTML interface ,when i click on that button it has to launch QC ,enter user name and password automatically and go to the test lab and select the test actions that i need to execute.i also need to specify at what time i need to execute the code.can you help me code this

  8. feelsgood11 Says:

    Hi Chris1234,

    I cannot point location out exactly since I don’t work with QC at the moment.
    I can send you QTA docs via email.
    They are 5MB in RAR.

  9. feelsgood11 Says:

    Hi Yugandhar,

    I guess everything is possible ;)
    You just have to play around with it.
    Unfortunately I cannot do it right now since I don’t use QC at the moment.
    Hope you find a way out ;)

  10. Panos Says:

    Hi,

    Thanks for the post. i have a similar requirement. please help me.
    In our scenario, we have to select a Test from TestLab(eg: Root\Folder1\Test1) and while clicking the ‘Run’ button, we have written code(inside Run Test( ) method in script editor of workflow) to run an external testing application.we are calling a .bat file to achieve this. our issue is we are not able to pass the test name which is selected to run.

    In your example we are passing the exact Test folder and Name of test to identify the test and then running it. In our case we have to identify the test name which is selected by user in order to run.

    Please reply

  11. udi Says:

    Hi,
    can you please send me the QTA docs via email as well.
    Thanks in advance.

    Udi

  12. feelsgood11 Says:

    Hello Udi,

    Please check you email.

    BR,
    Vadim

  13. Kumar Says:

    Hi,

    Would you please clarify my doubt in QC. My use case is as folows.

    I Have a self developed Bug tracking application. My client also holds Quality Central.

    The required task is

    “When I create a bug/Testcase or any thing in the QC that should be reflected in my bug tracking application and the reverse should also work”

    The approach i tried to follow has some hurdles as follows

    When QC creates a bug, will there be any event raised in OTA (Open Test Architecture) API so that there i can acess my application DB and insert the records there.

    Question is : Is there be any event in the OTA API in which i can call an external exe or dll to achive my functionality.

    And I am sure i can achive reverse of this by invoking OTA API in my code.

    And if there is any other alternative approach to do this please sugesst them.

    Regards,
    Kumar Ch.

  14. Liliana Says:

    Hi Im trying to create projects and domains through OTA, but I can’t find the OTA objects for that, any idea?

    Thankyou!

  15. Lonnie Allen Says:

    • How did you get this code to work? Many variables are not declared which causes problems setting up.
    • Do you have variable declarations turned off?
    • The use of variants which take more resources than explicitly defining them as String or Integer.

  16. nims Says:

    Hi,

    I like your post.
    Currently, I am working on automation project that needs testsets status to upload in QC.

    I would appreciate if you can send me OTA API doc to my email.

    With Regards,
    Nims

  17. Harsh Says:

    Hi,

    The above script is for running automated test.

    Is it possible to run a manual test set (i.e. test case with no script) using OTA?

  18. RM Says:

    Hi,
    I was trying to execute a test step from Excel VBA using OTA API. I was able to create a test set, a run. But when it came to executing a step and changing status to ‘Passed’, I got an error message saying I do not have permission for it. Would you know if such a restriction can be placed by the QC admins? If so, would you know what setting it is?

    Thanks in advance.

  19. Ace Says:

    Nice post. Can you tell me how to get a filtered list of all testinstances in a testset folder. ex. i would only like to get the testinstances with a status of “failed”. thanks in advance

  20. Senthil_mca80 Says:

    Hi,

    I have a question on workflow scripting. I want to update the result set of the script after the status changed in test lab. for example,

    Script “LoginVerify” Failed on Cycle1 and the same script reassigned to Cycle2.I want to update the result for “LoginVerify” at cycle2. Is there any way to do this?

    Thanks,
    Senthil

  21. deshnilesh Says:

    Hi,

    I am also looking for the OTA API, unfortunately my copy got corrupted. Would it be possible for you to place it at some common location so that its accessible to all.

    Regards,
    Nilesh


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: