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"

17 comments:

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

    ReplyDelete
    Replies
    1. How can I do this in Linux/Unix environment instead of windows?

      Delete
  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,

    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
  7. Did you get the solution for this.
    I am facing the same problem.

    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
  12. I am also faced the same , instead of storing https://10.135.55.24/qcbin/ in qcserver i have passed value straightaway like t.InitConnectionEx('https://10.135.55.24/qcbin/') its working fine. Hope it helps

    ReplyDelete
  13. Could you please let me know if there is a way to update the Step Name, Step Description, expected , actual and test status.

    ReplyDelete
  14. hi iam getting below error-

    Traceback (most recent call last):
    File "C:\Users\Ajit_Mallick\PycharmProjects\Test\venv\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:/Users/Ajit_Mallick/PycharmProjects/Test/alm.py", line 46, in
    d = number_of_steps("rd")
    File "C:/Users/Ajit_Mallick/PycharmProjects/Test/alm.py", line 11, in number_of_steps
    td = win32com.client.Dispatch("TDApiOle80.TDConnection")
    File "C:\Users\Ajit_Mallick\PycharmProjects\Test\venv\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
    File "C:\Users\Ajit_Mallick\PycharmProjects\Test\venv\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
    File "C:\Users\Ajit_Mallick\PycharmProjects\Test\venv\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)

    ReplyDelete
  15. Nice work, so if anyone want to convert one file into another then use this converter;

    Simple File Converter

    ReplyDelete
  16. That converter can easily convert one file into another like those;

    Ods to Pdf

    Vob to Mp4

    Mov to Flv

    Mpg to Avi

    Mxf to Mov

    ReplyDelete