Techno Logica


Wednesday, January 2, 2008

Connect to Quality Center using Scripting

To Connect QC from QTP using VB Script

Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
qtApp.TDConnection. Connect "URL", "DOMAIN", "PROJECT", "USERNAME", "PASSWORD", False

To get test name from quality center:

Set td=createobject("TDApiOle80.TDConnection.1")
td.InitConnectionEx "http://qc/qcbin"
td.ConnectProjectEx "DOMAIN", "PROJECT","USERNAME", "PASSWORD"
Set tstMgr = td.TreeManager
Set tsttr = tstMgr.NodeByPath("subject\functionality\SUB FOLDER NAME")
Set tsetFact = tsttr.TestFactory
Set tsetList = tsetFact.NewList("")
For Each tset in tsetList
Msgbox ("Test Name = " & tset.Name)
Next


To Find a particular the TestSet from QC :

Dim txtTestSet as String
txtTestSet = "TestSet_01"
Dim tset
tdc = New TDAPIOLELib.TDConnection
tdc.InitConnectionEx("http://server/qcbin")
tdc.Login("usrid", "pwd")
tdc.Connect("DOMAIN", "Project")
Dim tstMgr = tdc.TestSetTreeManager
Dim tsttr = tstMgr.NodeByPath("Root\SubFolder")
Dim tsetFact = tsttr.TestSetFactory
Dim tsetList = tsetFact.NewList("")
For Each tset In tsetList
If LCase(Trim(tset.Name)) = LCase(Trim(txtTestSet)) Then
MsgBox("Test Set Found")
End If
Next

NOTE : TDApiOle80 is for QC 8.0
TDAPIOLELib is for QC 9.0

7 comments:

gopikrishna.chowdhury@gmail.com said...

how do we access each step in a test and run each step individually for setting the result as pass or fail or no run using vb scripting.

Unknown said...

Use Reporter.reportevent micpass/micfail/micdone/micwarning
If browser(x).exists(20) then
Reporter.reportevent micpass,"browser exists","Browser found"

Else

Reporter.reportevent micFail,"browser exists","Browser not found"

Swapnadeep (Sunny) said...

Hi Gopi,
You need to go to
TDConnection->RunFactory->Run->StepFactory->Step

Once you have reached the Step Object, you can set the status as Pass or Fail.

Let me know if you want the code.

blogswamp said...

Hi Swapnadeep,All,
Is there a way where we can just update the status of the tests in QC by accessing the DB. What i am doing here is, i am running a series of tests on our test infrastructure, but i have similar test names in QC too which needs to be updated simultaneously. So i want to update the tests in QC with the results i get from my test infrastructure i.e Just pass or fail. In that case i don't want to run tests on QC just update the tests. Can anyone please help me out ...

Unknown said...
This comment has been removed by the author.
Unknown said...

How can I access each step in test steps individually for changing the status to Pass or Fail by running VB scripting.

Swapnadeep (Sunny) said...

Hi blogswamp,
u can try using,

TDConnection.Command
---------------------

The Command object represents a database command. You can use a Command object to query the database and return records in a Recordset Object, to execute a bulk operation, and to manipulate the structure of the database.

The Command object is intrinsically unsafe because it bypasses all the business logic of Quality Center and acts directly on the database. It is included in the API to enable the user to solve unforeseen problems. Before determining that there is no other solution to your application problem, consult your Mercury service representative to investigate other options.

The use of the Command object for a simple Select statement that does not change the database is safe.

Because of the risk, use of the Command object is restricted. For information about security and rights to use the Command object, refer to the Mercury Quality Center Administrator's Guide.


Example:

Dim com As TDAPIOLELib.Command
Dim RecSet As TDAPIOLELib.Recordset

' Setting and executing the SQL
Set com = tdc.Command
com.CommandText = "select * from bug"
Set RecSet = com.Execute


' Displaying the 2nd column data
For i = 1 To RecSet.RecordCount
List1.AddItem (RecSet.FieldValue(2))
RecSet.Next
Next