How to update test step status in QC using QTP script? (9156 Views)
Reply
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 1 of 24 (9,156 Views)

How to update test step status in QC using QTP script?

My Requirement:
I want to update test execution status of each step in Test set.
Step Name, Description and Expected Result should be displayed in Test Instance Properties like they are displayed when we manually execute the test execution.

In simple words, I just need to update the Status as Pass/Fail for each step. Rest everything should be displayed as in manual.

Thanx,
Guri
Please use plain text.
Honored Contributor
Rhonda Robinson
Posts: 3,159
Registered: ‎11-13-2007
Message 2 of 24 (9,156 Views)

Re: How to update test step status in QC using QTP script?

Guri,

Try using this:

Reporter.ReportEvent EventStatus, ReportStepName, Details [, Reporter]

Status of the report step:
0 or micPass: Causes the status of this step to be passed and sends the specified message to the report.
1 or micFail: Causes the status of this step to be failed and sends the specified message to the report. When this step runs, the test fails.
2 or micDone: Sends a message to the report without affecting the pass/fail status of the test.
3 or micWarning: Sends a warning message to the report, but does not cause the test to stop running, and does not affect the pass/fail status of the test.


Example:
The following examples use the ReportEvent method to report a failed step.

Reporter.ReportEvent 1, "Custom Step", "The user-defined step failed."

or

Reporter.ReportEvent micFail, "Custom Step", "The user-defined step failed."

Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 3 of 24 (9,156 Views)

Re: How to update test step status in QC using QTP script?

Hi Rohanda,
Thanx for your reply.
Somehow after reading my query again, I felt that I was not very specific with my requirement. Sorry for that.

Let me re-phrase my requirement:

1. In QC we have Test Plan, Test Lab tabs. In Test plan we have design steps which contains Step name, Description, Expected result.

2. When we pull that particular test case from Test Plan to Test Lab, we get Test Set for execution.

3.When we manually run the execution in QC, it opens a window where we mark the status of step as pass/fail. Each steps show Description, Expected Result. We manually enter the Actual result.

Now when we save the execution, it displays status as pass/fail in Test lab.

Now from here my requirement starts:
I need all the above things to be done by QTP script like updating Test step actual result, status as Pass/Fail.

So, when we look at Test Instance properties it will show execution history and when I check particular run execution it will display results similar as Manual execution.

I hope this clears my requirement. If you need any more clarification just let me know.

I appreciate your time and effort.

Thanks,
Guri
Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 4 of 24 (9,154 Views)

Re: How to update test step status in QC using QTP script?

In my previous comment, I misspelled your name. Typo error :)

Hi Rhonda Robinson,
Adding more to what I mention in my last comments, I think I should go step by step approach to achieve my requirement.

So if you can send me code just to update test step status in QC, that will be great. I will implement that and then if everything works fine, will proceed ahead.

Another thing, It might seem silly to you but I have never worked on OTA api and I am not even sure where to write the script code. Does script needed to be written in QTP or in QC workflow script editor?

So if you can send me little detailed steps for implementing it, would be a great help.

Thanx,
Guri
Please use plain text.
Honored Contributor
Rhonda Robinson
Posts: 3,159
Registered: ‎11-13-2007
Message 5 of 24 (9,154 Views)

Re: How to update test step status in QC using QTP script?

Guri,

The code example I gave goes within your QTP script.

Place this line before and after each "step" within your QTP script.
(example line):
Reporter.ReportEvent EventStatus, ReportStepName, Details [, Reporter]

Example as used within one of my scripts:

Reporter.ReportEvent 2, "Step 2", "Logoff customer6_a."
Browser("name:=M&I DepositEdge").Close
Reporter.ReportEvent 2, "Step 2" ,"End"

Notice that the first parameter (the 2 in my example) sets the status for the step (pass, fail, done), the second parameter is the Step Name (we just leave ours with the numbers), and the third parameter is any text string you want displayed. This will actually be displayed in the Description portion of the Step Details. Perhaps using the optional fourth parameter will place the text in the Actual Results section.

Another example from my script (this one gives conditions for passing or failing the step):

Reporter.ReportEvent 2, "Step 3", "Login to the UI with customer2_a."
subLoginUser("customer2_a")
If Browser("name:=Deposit Director").Exist(5) Then
Reporter.ReportEvent micPass, "Branding", "Branding passed for 'Deposit Director'"
Else
Reporter.ReportEvent micFail, "Branding", "Branding DID NOT pass for 'Deposit Director'"
End If
Reporter.ReportEvent 2, "Step 3" ,"End"



Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 6 of 24 (9,154 Views)

Re: How to update test step status in QC using QTP script?

Hi Rhonda Robinson,
Thanx for quick response.

Just need to know what will be the fourth parameter to write result in Actual Result field.

If that happens, that will be great.
Please use plain text.
Honored Contributor
Rhonda Robinson
Posts: 3,159
Registered: ‎11-13-2007
Message 7 of 24 (9,154 Views)

Re: How to update test step status in QC using QTP script?

Actually, the help file states that the fourth parameter (reporter) is not in use.

When you execute the steps using an automated script, the information from the actual steps is not given in the Description or Expected Results area so having the outcome written to the Description would not satisfy your need?
Please use plain text.
Honored Contributor
Reju George
Posts: 380
Registered: ‎01-15-2009
Message 8 of 24 (9,154 Views)

Re: How to update test step status in QC using QTP script?

Hi Rhonda...doesnt Reporter.ReportEvent only update the result file in QTP ! From Guri's question, my understanding is you want to update the Status field in QC for each test under a testset and not the results file of QTP, am I right Guri ?
Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 9 of 24 (9,154 Views)

Re: How to update test step status in QC using QTP script?

Hi Reju,
You are correct. This is what I want.
I need to update QC steps in test set.

Is there any other code to do it?

Thanx,
Guri
Please use plain text.
Honored Contributor
Reju George
Posts: 380
Registered: ‎01-15-2009
Message 10 of 24 (9,154 Views)

Re: How to update test step status in QC using QTP script?

Yes its possible...need to to do it using OTA or Open Test Architecture where we need to write a vb script to do this. I have not done it but let me dig into it.
Please use plain text.
Honored Contributor
Rhonda Robinson
Posts: 3,159
Registered: ‎11-13-2007
Message 11 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

No you do not need to use the OTA. I have verified this by looking at past executions of an automated script which contains these Report.Reporter lines. The status and the text are written to each step on the execution dialog box.
Please use plain text.
Honored Contributor
Rhonda Robinson
Posts: 3,159
Registered: ‎11-13-2007
Message 12 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

See the attached screen shot. This shows the Test Instance Properties dialog box for the test where I took my examples from. Notice that Step 2 has a Status of Done (equates to the use of 2 in the reporter line) and the Description says "logoff customer 6_a" just as my example code line says to write.
Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 13 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

hey guys,
i am now trying ReportEvent and let you know what's happening in sometime.
Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 14 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

Hey Rhonda,
Can i have your number to call and discuss?
If possible..
Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 15 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

What about Description expected result field data.
How can we show same description as mentioned in Design Steps of that test script?
Please use plain text.
Advisor
Guri Singh
Posts: 26
Registered: ‎02-03-2009
Message 16 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

Hey Reju,
Did you find any solution to it.
Please use plain text.
Advisor
Monika Gopalakrishna
Posts: 23
Registered: ‎03-04-2008
Message 17 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

Hi Guri,

I am also looking for the same.
I have an automation suite whose results have to be updated to the appropriate Manual testcases, if not the steps at least the status of the testcase.
I have started understanding the QC API.
Let me know if u have found a solution, meanwhile i will work over it and keep u updated.

Thanks,
Monika.
Please use plain text.
Occasional Visitor
LamNguyen
Posts: 1
Registered: ‎09-11-2009
Message 18 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

Hi,

I use this code :

//test: the testcase that you want to run
function UpdateStep(test, stepName, runningResult) {
var stepF = test.DesignStepFactory;
var stepList = stepF.NewList("");

var desStep;
if(stepList.Count == 0)
desStep = StepF.AddItem("");
else
desStep = stepList.Item(1);

desStep.StepName = stepName;
desStep.StepDescription = runningResult;
desStep.StepExpectedResult = "....";
desStep.Post();
desStep.Refresh();
}

The design steps update so well after Testcase running.

But when run the testset, it just update the previous running result.
Who can improve it for me?

Thanks so much.
Please use plain text.
Occasional Visitor
Siddhant
Posts: 1
Registered: ‎12-04-2009
Message 19 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

This is the code my dear :

Updae the test step status and enter actual results


Set TestSetF = Qcutil.QCConnection.TestSetFactory

Set aFilter = TestSetF.Filter

aFilter.Filter("CY_CYCLE") = "New" ' New is the name of test

Set lst = TestSetF.NewList(aFilter.Text)

If lst.Count = 0 Then

Set TstSet = TestSetF.AddItem(Null)

TstSet.Field("CY_CYCLE") = "New"

TstSet.Post

Else

Set TstSet = lst.Item(1)

End If

Set testInstanceF = TstSet.TSTestFactory

Set aFilter = testInstanceF.Filter

aFilter.Filter("TC_TEST_ID") = "39"

Set lst = testInstanceF.NewList(aFilter.Text)

If lst.Count = 0 Then

Set tstInstance = testInstanceF.AddItem(Null)

tstInstance.Field("TC_TEST_ID") = "39"

Else

Set tstInstance = lst.Item(1)

End If

tstInstance.Status = "Failed"

tstInstance.Post



Set testInstanceF = TstSet.TSTestFactory

Set RunF = tstInstance.RunFactory

Set theRun = RunF.AddItem("MyRun")


theRun.CopyDesignSteps

theRun.Post


Set runStepF = theRun.StepFactory

Set lst = runStepF.NewList("")

For Each Item In lst

Set runStep2 = Item

runStep2.Status = "Failed "

' runStep2.StepDetails ="Dude"

runStep2.Field("ST_ACTUAL") = "Test 123"

runStep2.Post

Next
Please use plain text.
Occasional Visitor
gaya3siv
Posts: 1
Registered: ‎03-14-2011
Message 20 of 24 (9,137 Views)

Re: How to update test step status in QC using QTP script?

@ Siddhant

Your code seem to pass the steps of the testcase, But the actual test case does not pass in QC. I tried executing your code and observed the same.

So we have to create a run for the test step and keep on passing it.

For example,
( Continuation to the above code)
Set runstep = Item.Run
Item.Status = "Passed"
Item.post

This additional code pass the testcase in QC too !

Happy learning !

Please use plain text.
Occasional Advisor
lithium999
Posts: 11
Registered: ‎08-19-2011
Message 21 of 24 (9,088 Views)

Re: How to update test step status in QC using QTP script?

Hi

Are there any links that we can learn this online? I have copy-pasted the script and it works, but any links that i can learn QC Updates from scratch

Thanks
Please use plain text.
Occasional Visitor
Ratheesha
Posts: 1
Registered: ‎09-19-2011
Message 22 of 24 (9,042 Views)

Re: How to update test step status in QC using QTP script?

[ Edited ]

Hi,

 

The above code is giving an error in below two lines... I am getting "Cannot create object lst for virtual TStestSet" error.

 


aFilter.Filter("TC_TEST_ID") = "39"

Set lst = testInstanceF.NewList(aFilter.Text)

 

Could you please any one explain me What is the value should be passed to TC_TEST_ID instead of 39 here..?

Please use plain text.
Occasional Visitor
hchulki
Posts: 2
Registered: ‎11-09-2011
Message 23 of 24 (8,198 Views)

Re: How to update test step status in QC using QTP script?

Try using other columns from the Test Instance table in QC.

Please use plain text.
Advisor
Pandharinathj
Posts: 7
Registered: ‎03-03-2014
Message 24 of 24 (1,934 Views)

Re: How to update test step status in QC using QTP script?

    Dim runStepList
    Dim CurrentRun ' object which holds the current run

'=============================================================================================
'@purpose- this function will copy design steps from 'design steps' tab to current run of test in QC
'make sure qtp and qc connection has been established before runnning the test
'=============================================================================================
Function CopyDesingSteps()
    Onerrorresumenext
    Dim otest
    if QCUtil.IsConnected =Falsethen
    msgbox"Please establish connection to ALM first."
        'ExitAction
        Exitfunction
    
    Endif
    set CurrentRun = QCUtil.CurrentRun
    
    ' copy design steps to current run

      CurrentRun.CopyDesignSteps

     GetDesignSteps  CurrentRun

    intTotalNumberOfUpdatedSteps=0
    
EndFunction



'=============================================================================================
'@ purpose- this function will retrive  the list of steps of current run in to runStepList
'=============================================================================================
Function GetDesignSteps(CurrentRun)
    'On error resume next
    Dim intStepcount
    Set runStepF = CurrentRun.StepFactory

    Set runStepList = runStepF.NewList("")
        intTotalNumberOfSteps=runStepList.Count
    For intStepcount = 1To runStepList.Count
        runStepList.Item(intStepcount).Field("ST_STATUS") ="Not Completed"
        runStepList.Item(intStepcount).Field("ST_ACTUAL") ="Not Completed"
        runStepList.Post
        
    Next
    
    Set runStepF = nothing               
EndFunction
'=============================================================================================
'@purpose- This function will update specified step with status and actual in test run result
'=============================================================================================
Function UpdateStep(byval stepID,byval strStatus,byval strData)
    'On error resume next

        If strStatus = TrueThen
            strStatus="Passed"
        '
        else
        strStatus="Failed"
        
        EndIf
        ' update step status and step actuals
        runStepList.Item(stepID).Field("ST_STATUS") =strStatus
        runStepList.Item(stepID).Field("ST_ACTUAL") =strData
        runStepList.Post
        
EndFunction

Sub EndTest()
    CurrentRun.Post
    Set runStepList= nothing
    Set Currentrun = nothing

endSub
Sub BeginTest()
     ' copy design steps to current run
 CopyDesingSteps 

EndSub

 

 

In qtp script at the start call BeginTest() function then use UpdateStep to update each step and at the end use EndTest to post result in qc

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation