Friday, October 21, 2011

Retrieve values from Quality Center Test Lab and Defects tab using OTA

Getting the Number of Passed, Failed, No Run and Not Completed Test cases

We can make use of the Filter as given below to get the number of Test cases according to the status Passed, Failed, No Run, Not Completed,etc.

Dim tdc, qcServer
Dim qcUsername,qcPassword,qcDomain,qcProject

Set tdc = CreateObject("TDApiOle80.TDConnection")
qcServer = "QC URL"
tdc.InitConnectionEx qcServer

If tdc.Connected Then
Msgbox "Connected to QC"
Else
MsgBox "Not connected to QC"
End If

qcUsername = "Your QC Username" 'Username
qcPassword = "Your Password" 'Password
tdc.Login qcUsername, qcPassword

If tdc.LoggedIn Then
MsgBox "Logged in to QC"
Else
MsgBox "Logged out from QC"
End If

qcDomain = "Domain" 'QC Domain Name
qcProject = "Project" 'QC Project Name

tdc.Connect qcDomain, qcProject

Dim vPath: vPath="Root\Account1\Proj1" 'Path to the folder containing test set
Dim vPass,vFail,vNR,vNC

Dim oTestSet: Set oTestSet = tdc.TestSetTreeManager.NodeByPath(vpath).TestSetFactory.NewList("").Item(1).TsTestFactory 'Item(1) Refers to the 1st test set in the path
Dim testFilter1: Set testFilter1 = oTestSet.Filter

'To Filter by Passed status
testFilter1.Filter("TC_STATUS") = "Passed"
vPass = vPass + oTestSet.NewList(testFilter1.Text).Count

'To Filter by Failed Status
testFilter1.Filter("TC_STATUS") = "Failed"
vFail = vFail + oTestSet.NewList(testFilter1.Text).Count

'To Filter by No Run status
vNR = vNR + oTestSet.NewList("[Filter]{TableName:TESTCYCL,ColumnName:TC_STATUS,LogicalFilter:" & Chr(39) & "No" & Chr(32) & "Run" & Chr(39) & ",VisualFilter:" & Chr(39) & "No" & Chr(32) & "Run" &Chr(39) & ",NO_CASE:}").Count

'To Filter by Not Completed status
vNC = vNC + oTestSet.NewList("[Filter]{TableName:TESTCYCL,ColumnName:TC_STATUS,LogicalFilter:" & Chr(39) & "Not" & Chr(32) & "Completed" & Chr(39) & ",VisualFilter:" & Chr(39) & "Not" & Chr(32) &"Completed" & Chr(39) & ",NO_CASE:}").Count

Msgbox "Passed: "&vPass&" Failed: "&vFail&" No Run: "&vNR&" Not Completed: "&vNC

Set testFilter1=Nothing

Set oTestSet=Nothing

Set tdc=Nothing


Getting the Number of Test cases executed by a tester in a specific test set

We can use the below code to get the count of test cases executed by a tester in a particular test set.

Dim vPath: vPath="Root\Account1\Proj1" 'Path to the folder containing test set

Dim oTestSet: Set oTestSet = tdc.TestSetTreeManager.NodeByPath(vpath).TestSetFactory.NewList("").Item(1).TsTestFactory 'Item(1) Refers to the 1st test set in the path ; tdc refers to the test
connection object in the previous snippet

Dim testFilter1: Set testFilter1 = oTestSet.Filter
Dim vtestcount: vtestcount=0
Dim tester_name:tester_name="divya" 'QC username of the tester for whom the count has to be calculated
testFilter1.Filter("TC_ACTUAL_TESTER") =chr(34)&Cstr(tester_name)&chr(34)

vtestcount = vtestcount + oTestSet.NewList(testFilter1.Text).Count
Msgbox "Number of Test Cases executed by "&tester_name&" : "&vtestcount
Set testFilter1=Nothing
Set oTestSet=Nothing


Getting the number of defects raised by a tester in a specific release according to severity

We need to apply multiple filters as we are using Tester name, Release Name and Defect Severity as the criteria.


Dim Bug_Ct:Bug_Ct=0
Dim tester_name:tester_name="divya"
Dim test_severity:test_severity="2-High"

Dim oBugFactory: Set oBugFactory=tdc.BugFactory
Dim TotBugcnt: TotBugcnt=oBugFactory.NewList("").Count 'To get the total number of defects in Defects tab.
Dim oBugFilter1:Set oBugFilter1=oBugFactory.Filter

oBugFilter1.Filter("BG_DETECTED_BY")=tester_name 'QC username of the tester for whom the defect count has to be calculated
oBugFilter1.Filter("BG_DETECTED_IN_REL") = "^Releases\proj1\1.1.01.201^" 'Name of the Release
oBugFilter1.Filter("BG_SEVERITY")=test_severity 'Defect Severity. Eg.: Can be 2-High, 1-Critical, 4-Low. Possible Values can be obtained from QC defects tab

Bug_Ct = Bug_Ct + oBugFactory.NewList(oBugFilter1.Text).Count
Msgbox Bug_Ct

Set oBugFilter1=Nothing


Getting the number of defects in a specific release according to defect status

Here we need to apply the following criteria: Release Name, Defect status. If we want to be more specific , say, we need to find the same for a particular tester, then we can include tester name as a filter criteria.

The following code will give the output for number of defects raised in a specific release having the status "Closed" which were raised by tester1 and tester2.


Dim Bug_Ct:Bug_Ct=0
Set oBugFactory=tdc.BugFactory
Set oBugFilter1=oBugFactory.Filter
oBugFilter1.Filter("BG_DETECTED_IN_REL") = "^Releases\proj1\1.1.01.201^" 'Name of the Release
oBugFilter1.Filter("BG_STATUS")="Closed" 'Defect status for which count is calculated
oBugFilter1.Filter("BG_DETECTED_BY")="tester1 or tester2" 'QC Username of the testers for whom the count is calculated
Bug_Ct = Bug_Ct + oBugFactory.NewList(oBugFilter1.Text).Count
Msgbox Bug_Ct
Set oBugFilter1=Nothing

24 comments:

  1. thank you for sharing this. it helps

    just to add something on :- Getting the Number of Passed, Failed, No Run and Not Completed Test cases.

    your example showing only 1st test set in the path

    this can be for/next loop, you just need to get total count of test set in that path ==>
    tdc.TestSetTreeManager.NodeByPath(vPath).TestSetFactory.NewList("").Count

    ReplyDelete
  2. This is more helpful for me. Thank you so much for publishing this kind of code.
    I have one request, is it possible to get the test name like statuswise? if yes can you please provide same in your blog.
    thanks in advance

    ReplyDelete
  3. Hi I just tried it with "Getting the Number of Passed, Failed, No Run and Not Completed Test cases" but it errors out with "our Quality Center session has been disconnected. Contact your system administrator for more information" in the following line : "Dim oTestSet: Set oTestSet = tdc.TestSetTreeManager.NodeByPath(vPath).TestSetFactory.NewList("").Item(1).TSTestFactory 'Item(1) Refers to the 1st test set in the path"

    ReplyDelete
  4. how to fetch the comment on a perticular defect?

    ReplyDelete
  5. Thank you very much for this post . it is straight forward and very helpful

    ReplyDelete
  6. I would like to have the OTA code for downloading the test cases(test name , test case status, execution date etc) from test lab to excel. Does anyone has the code for it?

    ReplyDelete
  7. Is there a way to check for mandatory fields while updating a defect such that there is no blank values updated. I tried checking the "IsRequired" Field value on BugFactory object. But it gets only three fields which has "True" value which i think suggest as a mandatory field.The fields i get are "Summary", "Description" and "Activity Type". There are many more fields which i see are mandatory when we manually update a defect but those have a "False" value for "IsRequired" property".

    Would be glad if any one could share the code ?

    ReplyDelete
  8. Hi All,
    Is there any way to export the test set name, status, linked defect and status of the defect from the QC to Excel.
    Please provide the code if any one has.

    Regards,
    vara

    ReplyDelete
  9. Yes Vara, you can export it.

    Thanks,

    ReplyDelete
  10. how to filter through detection date and detection_in_RCYC?

    ReplyDelete
  11. How to filter defects in QC that are raised by a particular user and that doesnt have QC access now(he cannot login to qc because his credentials were not working) and has to be filtered by another user of the same project.

    ReplyDelete
  12. Is there a way to get the failure step description from test lab using OTA. Please post it here I wanted to get the common failure test cases. Any help is appreciated.

    ReplyDelete
  13. Hi, is there a way to apply more filter values to one field, so I can get all defects for instance which are assigned to person X or to person y. I tried to do it like this
    [...]
    testInstanceFilter.Filter(AssignedTo) = personX
    testInstanceFilter.Filter(AssignedTo) = personY
    [...]

    But is is not working, it delivers an empty list. In case I just take one person as a filter it works perfectly. I assume it makes an and-search and I do not know how to achieve it treates both as an or-search. Is there a way to do so?

    ReplyDelete
  14. How do i find the test cases executed for a particular date by a tester?

    ReplyDelete
  15. Can we get the count of defect failures of any defect?

    ReplyDelete
  16. This blog contain excellent stuff. We are providing Best QTP & QC Online Training.for more Visit QTP&QC Online Training

    ReplyDelete
  17. Thanks for your information. QTP provide most precise and independent review about a software application. This automation testing tool is ideal to determine the performance and validity of a software application. QTP training

    ReplyDelete
  18. Is there any way to filter the testset by using execution date and actual tester name both at a time?

    ReplyDelete
  19. Can we add Test Iteration to the test which we need to execute in Test Lab using OTA. I am able to get hold of the TSTest only.

    ReplyDelete
  20. How can i get a list of defects linked to a failed test? Please help!!

    ReplyDelete
  21. Thanks for sharing such informative article on Loadrunner Automation testing tool. This load testing tool will provide most precise information about the quality of software. Loadrunner Course in Chennai | Loadrunner training institute in Chennai

    ReplyDelete
  22. Thanks for Sharing the valuable information and thanks for sharing the wonderful article..We are glad to see such a wonderful article..
    QTP Training in Chennai | QTP Training Institute in Chennai | QTP Training

    ReplyDelete
  23. How can i get test instance name from test lab in qc

    ReplyDelete
  24. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete