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 ALM 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.
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
Thank you, but this code does not work with BPT (QTP11/ALM11)
If you add a step to the run, the run_report in ALM is empty. Although that the STEP table is populated correctly. (bug?)
Do you know of any workaround to do the same thing with BPT?
Hi, i’m using below code execute test cases in a QC. In a below approach, i’m fetching my test case name one by one from external excel file. The problem is that each test case name has ‘spaces’ in it and this code throws error if i have space in my test case.
So to overcome this problem, i’m splitting my test case and storing one unique string in a vriable and trying to search that test cases using wildcard in QC. But its not working..
Have look at the code below:-
Sub LatestDesign()
Set QCConnection = CreateObject(“TDApiOle80.TDConnection”)
QCConnection.InitConnectionEx “*************************************”
QCConnection.Login “*******”, “******”
QCConnection.Connect “**********”, “********”
Set TS_SetFactory = QCConnection.TestSetFactory
Set TS_TreeMgr = QCConnection.TestSetTreeManager
TS_TestFolderPath = “*************”
Set TS_TestFolder = TS_TreeMgr.NodeByPath(TS_TestFolderPath)
Set TS_TestSetList = TS_TestFolder.Findtestsets(“***********t”)
Set objExcel = CreateObject(“Excel.Application”)
Set objWorkbook = objExcel.Workbooks.Open(“C:\Documents and Settings\*****\********\***_Export.XLXS”)
Set objDriverSheet = objWorkbook.Worksheets(“Tests”)
Dim i
Dim kstr As String
Dim pstrArray() As String
i = 2
Do While objDriverSheet.Cells(i, 2).Value “”
kstr = objDriverSheet.Cells(i, 2).Value
pstrArray() = Split(kstr)
TC_Value = pstrArray(1)
Set TestSet = TS_TestSetList.Item(1)
Set Test_Case_Filter = TestSet.TSTestFactory.Filter
Test_Case_Filter.Filter(“TS_NAME”) = *TC_Value* ‘{This line throws the error message, Index not found, means QC could not able to search test case name}
Set TS_TestCaseList = Test_Case_Filter.NewList()
Set TS_TestCase = TS_TestCaseList.Item(1)
Set tcStepID = TS_TestCase.RunFactory
Set theRun = tcStepID.AddItem(” “)
Dim j
theRun.Status = “Passed”
theRun.CopyDesignSteps
theRun.Post
Set runStepName = theRun.StepFactory
Set tsStepName = runStepName.NewList(” “)
For j = 1 To 2
Set runStep = tsStepName.Item(j)
runStep.Status = “Passed”
runStep.Field(“ST_ACTUAL”) = “Passed”
runStep.Post
j = 1 + 1
Next
i = i + 1
Loop
MsgBox “Done”
‘objExcel.application.quite
objExcel.quite
Set objExcel = Nothing
QCConnection.Disconnect
QCConnection.Logout
QCConnection.ReleaseConnection
End Sub
From above code:-
TC_Value holds the part of my test case name. Suppose test case name is TC01 New Test Case. Then TC_Value=TC01. Now using *TC01* as a wildcard, i’m looking to search this test case in QC.
Anybody knows that how this would work?
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
Where did you learn OTA? It is so dificult, there is no good reference to study and learn that.
It is confusing – the best place is the OTA_API_Reference that comes with QC/ALM. If you have a newer version of ALM 11.5 it look like they are moving towards an easier to use REST api to get this type of info.
In ALM test lab for a test case in a test set I want to Enter values in “Signatures” field through code. Can you please provide me the code to enter values to it. Or else can any body tell about the data base field name for “Signatures”.
This code work fine only if I run the script from QC. If i run the code from QTP, it runs the script but does not write the results. Can you help why?
When you run from QTP do you run and select the QC results option?
My qtp test has following code and 3 iterations in datatable.
when it is executed, ‘stepID’ returns 0 every time. May I know why.
It should have returned number of steps from LastRun report.
Set myCurentRun = QCUtil.CurrentRun
Set myStepFactory = myCurentRun.StepFactory
Set myStepList = myStepFactory.NewList(“”)
stepID = myStepList.Count
Print stepID
Hi All,
I am new to testing and this is my first job, I am looking for a tool that can update the test status from spread sheet into HP ALM. (I am new to testing and to HP ALM).
We do not have QTP in our work place.
Testing is done manually by testers and results are updated in a spreadsheet and then I need to workout how to get the results updated in HP ALM.
Can any one point me to a tool that can be used please.
Thanks
Pindu
Hi does anyone know how many words you can put in the ‘expected results’ field? Thanks.
HI JOE ,
THANKS A LOT FOR YOUR POST . CAN YOU PLEASE LET ME KNOW IF IT IS POSSIBLE TO GET THE FAILED SCRIPT REASON FROM THE LIST OF SCRIPT EXECUTED .
FOR EXAMPLE , IF WE RUN 500 SCRIPT AND 30 HAVE FAILED , NEEED TO EXPORT THE 30 TEST CASES NAME AND FAILED STEP DETAILS . WE HAVE USED REPORTER.REPORT EVENT IN OUR SCRIPTS .
Your code is very helpful in updating the test results. Thanks you for this.
I tried using code in QTP11 BPT test script. It actually updates the actual and expected results correctly. However order of test steps are changing. Meaning, “Start Business Component” and “End Business component” steps are displaying at the end for each component.
For e.g the order of the steps are displaying as:
Step 1
Step 2
Start Business Component
End Business Component
is there way we can remove these two steps or keep them in proper order? Any input/help is greatly appreciated.
Hi all,
That was the awesome code. I have a question now. If I am to write 500 test case, My script takes time while executing from QC , whereas it is very fast when executing from UFT.
Is that possible to write the all 500 test case in QC at final stage of run ??
Thanks for the article. One note on my UFT 14.03 system about case sensitivity.
myStepList.Item(stepID).Field(“ST_STATUS”) = “PASSED”
That needs to match what is configured in ALM 12.55 (“Passed” in my case) or you won’t get the nice little green icon with it in the Run Result for that step.