0

I want to try to add all the step details - Expected, Actual, Status, etc. to a QC Run for a testcase of a TestSet from a Python Script living outside the Quality Center. I have come till here (code given below) and I don't know how to add Step Expected and Step Actual Result. If anyone knows how do it, please help me out!! Please, I don't want any QTP solutions. Thanks, Code-

# Script name - add_tsrun.py 
# C:\Python27\python.exe 
# This script lives locally on a Windows machine that has - Python 2.7, Win32 installed, IE8 
# Dependencies on Windows Machine - Python 2.7, PythonWin32 installed, IE8, a QC Account, connectivity to QCServer 
import win32com.client, os 
tdc = win32com.client.Dispatch("TDApiOle80.TDConnection") 
tdc.InitConnection('http://QCSERVER:8080/qcbin') 
tdc.Login('USERNAME', 'PASSWORD') 
tdc.Connect('DOMAIN_NAME', 'PROJECT') 
tsFolder = tdc.TestSetTreeManager.NodeByPath('Root\\test_me\\sub_folder') 
tsList = tsFolder.FindTestSets('testset1') 
ts_object = tsList.Item(1) 
ts_dir = os.path.dirname('testset1') 
ts_name = os.path.basename('testset1') 
tsFolder = tdc.TestSetTreeManager.NodeByPath(ts_dir) 
tsList = tsFolder.FindTestSets(ts_name) 
ts_object = tsList.Item(1) 
TSTestFact = ts_object.TSTestFactory 
TestSetTestsList = TSTestFact.NewList("") 
ts_instance = TestSetTestsList.Item(1) 
newItem = ts_instance.RunFactory.AddItem(None)   # newItem == Run Object 
newItem.Status = 'No Run' 
newItem.Name = 'Run 03' 
newItem.Post() 
newItem.CopyDesignSteps()   # Copy Design Steps 
newItem.Post() 
steps = newItem.StepFactory.NewList("") 
step1 = steps[0] 
step1.Status = "Not Completed" 
step1.post() 
## How do I change the Actual Result?? 
## I can access the Actual, Expected Result by doing this, but not change it
step1.Field('ST_ACTUAL') = 'My actual result'           # This works in VB, not python as its a Syntax error!! 
Traceback (  File "<interactive input>", line 1 
SyntaxError: can't assign to function call

Hope this helps you guys out there. If you know the answer to set the Actual Result, please help me out and let me know. Thanks, Amit

amulllb
  • 3,036
  • 7
  • 50
  • 87

2 Answers2

2

As Ethan Furman answered in your previous question:

In Python () represent calls to functions, while [] represent indexing and mapping.

So in other words, you probably want to do step1.Field['ST_ACTUAL'] = 'My actual result'

Community
  • 1
  • 1
matt b
  • 138,234
  • 66
  • 282
  • 345
  • Hey Matt, Yup!! I exactly want to do that - step1.Field['ST_ACTUAL'] = 'My actual result' But, in VB, 'Field' is a property whereas in Python 'Field' is a method. Since in Python, we cannot assign value to a function call, I don't see any answer to this. That is the problem and I really don't know how to go around it? Thanks, Amit – amulllb Oct 18 '11 at 15:50
  • it sounds like `Field` should not be a method in the python class. What does this data structure hold - a mapping between keys and values? In this case you could use a [dict](http://docs.python.org/tutorial/datastructures.html#dictionaries). Or if you need to use something else, instead of writing `step.Field[key] = value`, just add a function like `step.add_field(key, value)` – matt b Oct 18 '11 at 16:01
  • I am really sorry if I wasn't clear. The method 'Field' is from a COM Object that come from "tdc = win32com.client.Dispatch("TDApiOle80.TDConnection")" The Field method cannot be overriden, cannot be modified since it belongs to QC API. Just so you know, Field takes a parameter called key (e.g ST_ACTUAL) and returns the value (a string). There are no dictionaries here!! – amulllb Oct 19 '11 at 17:06
2

Found the answer after a lot of Google Search :)

Simple -> Just do this:

step1.SetField("ST_ACTUAL", "my actual result") # Wohhooooo!!!!

If the above code fails to work, try to do the following:-

(OPTIONAL) Set your win32 com as follows- (Making ''Late Binding'')
# http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
    a. Start PythonWin, and from the Tools menu, select the item COM Makepy utility.
    b. Using Windows Explorer, locate the client subdirectory (OTA COM Type Library)
       under the main win32com directory and double-click the file makepy.py.

Thank you all...

amulllb
  • 3,036
  • 7
  • 50
  • 87