Problem – How do I populate the QC Steps Details?
I'll be honest: for a while, I had no idea how to populate the QC Step Details for the test results of a QTP test script.

I was stumped. I thought maybe there was a secret parameter for the QuickTest Pro reporter function that I was missing. I knew there must be a way to do it using QC/ALM's OTA API, but I never got around to figuring out -- until now.
FDA Reporting and QC Back story
While working on a project for a medical device, one of the requirements was that test result be formatted in a way that would satisfy an FDA audit. Luckily, this was accomplished using OTA.
This is what I found out:
Quality Center's OTA StepFactory to the Rescue
Turns out it's pretty easy to add this info to a test run's results history for the step details. All you need to do is tap into the OTA's CurrentRun and StepFactory objects.
Once you have an instance of the StepFactory object, it's then just a matter of adding your values to the ST_EXPECTED and ST_ACTUAL fields.
For example -- the following code will populate all the fields in the QC/ALM test lab test run step details:
Set myCurentRun = QCUtil.CurrentRun
Set myStepFactory = myCurentRun.StepFactory
myStepFactory.AddItem("Joe Debug Test Step")
Set myStepList = myStepFactory.NewList("")
stepID = myStepList.Count
myStepList.Item(stepID).Field("ST_STATUS") = "PASSED"
myStepList.Item(stepID ).Field("ST_DESCRIPTION") = "This is a debug test step"
myStepList.Item(stepID).Field("ST_EXPECTED") = "Joe"
myStepList.Item(stepID ).Field("ST_ACTUAL") = "Joe"
myStepList.Post

Next, roll it up and make a reusable QTP function that can be used by all your scripts. Since I need to use this pretty often, I create a function that I could reuse. The function's code is:
'-------------------------------------------------------------------------------
' @Function Name:reportFDA stepName,status,desc,expectedResult,actualResult
' @Documentation:Values to enter for possible FDA audit
'-------------------------------------------------------------------------------
Function reportFDA(stepName,status,desc,expectedResult,actualResult)
Set myCurentRun = QCUtil.CurrentRun
Set myStepFactory = myCurentRun.StepFactory
myStepFactory.AddItem(stepName)
Set myStepList = myStepFactory.NewList("")
nStepKey = myStepList.Count ' This sets step count
myStepList.Item(nStepKey).Field("ST_STATUS") = status
myStepList.Item(nStepKey).Field("ST_DESCRIPTION") = desc
myStepList.Item(nStepKey).Field("ST_EXPECTED") = expectedResult
myStepList.Item(nStepKey).Field("ST_ACTUAL") = actualResult
myStepList.Post
' Clean up.
Set myStepList = Nothing
Set myStepFactory = Nothing
Set myCurentRun = Nothing
End Function
'----------------------------------------------------------------
HEY, HEY, HEY! IT'S OTA!
That's it! With some simple OTA I was able to get the results format I was looking for.

{ 5 comments… read them below or add one }
Hi Joe,
Good post. I’ve always been amazed that after so many years, QTP and QC still don’t fully integrate. It would be so much better to have ‘Reporter.ReportEvent’ handle Expected & Actual results, but that’s what we’re stuck with.
I’ve messed with using this technique before to add attachments during a run, and one problem I ran into was that since the results of the current run weren’t fully posted back to QC/ALM until the test run finished, many of the steps appeared out-of-order. Anything you add with StepFactory appears first, and then the “typical” steps are added later. Looking at your screen shot, it appears that is still a problem. I see your custom step appears at the very top before we even see entries about “StartTest”.
The best way to implement this (i.e. add actual result as well as all test results to QC) is to keep both processes (QC and Test Run) separate and update QC only after a test run.
What this means is that you:
1. Run your test suite (this can be Selenium tests, Watir, whatever)
2. Save your test results (pass, fail, actual) to a db or flat file
3. Run your QC integration script / program to get the data from the test results db and then update QC via OTA.
Via this integration you can then accomplish the correct step order as you update the test results sequentially.
I want to Set build version of test case in execution grid. Can you please help me out?
Thanks in advance
GAnesh » Hi Ganesh – you should be able to modify the code in my post ALM/QC – How to Update a Test Set using OTA to change your test set field
Hi Joe,
First of all, you are doing a wonderfull job by sharing your knowledge and tips to all (I strongly belive, Knowledge is devine and you are sharing to all) Great Job!
I have implemented the above OTA solution for populating the actual and expected results. But, when i view the results in QC these steps are displayed first as we are adding at runtime and QTP is updating after the test execution is complete.
As an alternate solution, I am exporting the steps and then sorting by execution time works
Questions: 1) Is there a way we can achieve this with out the alternate solution…?
2) can we add the actual and exoected results to QTP steps i.e reporter.report event….?
Regards
Hari