Tuesday, December 20, 2011

Python with HP Quality center

As promised, check the code below will let you connect to QC
the below walks you through the test tree and updates the status of test cases.
you can use this as a function can call it in python script to update.
this was pretty useful to me , hops is the same case with you.

import win32com
from win32com.client import Dispatch

qcServer = "http://xxxxxxxxx/qcbin/"
qcUser = "xxxxx"
qcPassword = "xxxxx"
qcDomain = "xxxx"
qcProject = "xxxx"

t = win32com.client.Dispatch("TDApiOle80.TDConnection.1")
t.InitConnectionEx(qcServer)
t.Login(qcUser,qcPassword)
t.Connect(qcDomain,qcProject)

print "Logged in"

mg=t.TreeManager
npath="Root\xxxxxx"
tsFolder = t.TestSetTreeManager.NodeByPath(npath)
print tsFolder
tfactory=tsFolder.TestSetFactory
td_tsff=tfactory.Filter
td_testset=td_tsff.NewList()

for otest in td_testset:
print otest.Name
td_TSTestSetFactory = otest.TSTestFactory
td_tstsff = td_TSTestSetFactory.NewList("")


for otestitem in td_tstsff:
print otestitem.Name
td_RunFactory = otestitem.RunFactory
obj_theRun = td_RunFactory.AddItem("testrun")
obj_theRun.Status = "Passed"
otestitem.Status= "Passed"
obj_theRun.Post()
print otestitem.Status
next
next

tsFolder = None
tfactory = None
td_testset = None
td_TSTestSetFactory = None
td_RunFactory = None
obj_theRun = None
t.logout
t = None

print "done"

12 comments:

  1. If you have doubts about this , leave me a comment , I can get back to you with details.

    ReplyDelete
  2. Hi I am getting error while executing this step
    obj_theRun = td_RunFactory.AddItem("testrun")

    File ">", line 2, in AddItem

    Please help

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi thanks for your script it solved my requirement. but I have one more requirement, how can I read only one testcase with given nodepath for the same.

    ReplyDelete
  5. Hi. Thank you for posting this code. It has been very helpful. However could you please explain what was your reference for QC side functions? For example how can I access bugs list rather than tests? Thanks again.

    ReplyDelete
  6. Hi I have a problem. following your code. my qcServer = "https://10.135.55.24/qcbin/", I can login it manually by IE explorer, but I cannot login by python script. One ERROR always happens as below. can you help me trace this issue? thank you so much

    t.Login(qcUser,qcPassword)
    File "", line 3, in Login
    com_error: (-2147352567, 'Exception occurred.', (0, None, u'Failed to Login', None, 53312984, -2147220502), None)

    ReplyDelete
    Replies
    1. Did you get the solution for this.
      I am facing the same problem.

      Delete
  7. Hi,

    When i execute the above script, i am gettign error in line

    "t.InitConnectionEx(qcServer)"

    Error i am getting is,

    HTTP Status 404 - /qcbin/start_a.jsp/servlet/tdservlet/TDAPI_GeneralWebTreatment

    Thank you.

    ReplyDelete
  8. I am getting error at tfactory=tsFolder.TestSetFactory
    Can U pls help me out. I m new to HPQC and Python

    ReplyDelete
  9. I am getting error at tfactory=tsFolder.TestSetFactory
    Can U pls help me out. I m new to HPQC and Python

    ReplyDelete
  10. Great work, this helps lot for me. Thanks

    ReplyDelete
  11. Hai,

    Am getting a error:


    Traceback (most recent call last):
    File "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
    pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\work\Workspace\Test\src\ALM.py", line 11, in
    t = Dispatch("TDApiOle80.TDConnection.1")
    File "C:\Python34\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
    File "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
    File "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
    pywintypes.com_error: (-2147221164, 'Class not registered', None, None)

    Can you please help me how to figure it out.

    ReplyDelete