Thursday, July 30, 2009

Copy all QC defects to an Excel Sheet

'***********************************************************************
'Purpose: This script copies all QC defects into an Excel file
'This example you can run from .vbs run-time or from QTP.
'Scripted by: Uday
'***********************************************************************

QCServerURL="Server Name"
QCUserLogInName="User Name"
QCUserPwd="User Password"
QCDomain="Domain Name"
QCProject="Project Name"

Set QCConnObj=createobject("TDApiole80.TDConnection")

'These are the functions for Connect to QC, Copy defects to Excel and Disconnect from QC.
ConnectToQCProj()
WriteDefectsIntoExcel()
DisConnectProj()

Public Function ConnectToQCProj
'User Login to QC
QCConnObj.InitConnectionEx QCServerURL
QCConnObj.Login QCUserLogInName,QCUserPwd

If QCConnObj.LoggedIn<>TRUE Then
msgbox "QC User Authentication has failed"
WScript.Quit
End If

'User connect to QC
QCConnObj.Connect QCDomain,QCProject
End function


Public function WriteDefectsIntoExcel()

Set BugFactoryObj=QCConnObj.BugFactory
Set BugList=BugFactoryObj.NewList("")

Set XLObj=createobject("Excel.application")
XLObj.Workbooks.Add()
Set XLSheet=XLObj.ActiveSheet


XLSheet.Cells(1, 1).Value = "Bug Id"
XLSheet.Cells(1, 2).Value = "Summary"
XLSheet.Cells(1, 3).Value = "Detected By"
XLSheet.Cells(1, 4).Value = "Priority"
XLSheet.Cells(1, 5).Value = "Status"
XLSheet.Cells(1, 6).Value = "Assigned To"

RowNo=2

For each bug in BugList
XLSheet.Cells(RowNo, 1).Value = Bug.Field("BG_BUG_ID")
XLSheet.Cells(RowNo, 2).Value = Bug.Summary
XLSheet.Cells(RowNo, 3).Value = Bug.DetectedBy
XLSheet.Cells(RowNo, 4).Value = Bug.Priority
XLSheet.Cells(RowNo, 5).Value = Bug.Status
XLSheet.Cells(RowNo, 6).Value = Bug.AssignedTo
RowNo=RowNo+1
Next

XLObj.ActiveWorkbook.SaveAs("C:\QC_Defects.xls")
XLObj.Quit

Set XLObj=nothing

End Function



Public Function DisConnectProj()
QCConnObj.Disconnect
QCConnObj.Logout
QCConnObj.ReleaseConnection
Set QCConnObj=Nothing
End function

Wednesday, July 29, 2009

Find all tests in a folder path

'***********************************************************************
'Purpose: This script displays all test names in a folder(path) in Test Plan module
'This example you can run from .vbs run-time or from QTP.
'Scripted by: Uday
'***********************************************************************


QCServerURL="QC server path
QCUserLogInName="user name"
QCUserPwd="password"
QCDomain="domain name"
QCProject="project name"

Set QCConnObj=createobject("TDApiole80.TDConnection")

TestsInPath="Folder Path"


ConnectToQCProj()
FindTestsInANode(TestsInPath)
DisConnectProj()



Public Function ConnectToQCProj
'User Login to QC
QCConnObj.InitConnectionEx QCServerURL
QCConnObj.Login QCUserLogInName,QCUserPwd

If QCConnObj.LoggedIn<>TRUE Then
msgbox "QC User Authentication has failed"
WScript.Quit
End If

'User connect to QC
QCConnObj.Connect QCDomain,QCProject
End function

Public Function DisConnectProj()
QCConnObj.Disconnect
QCConnObj.Logout
QCConnObj.ReleaseConnection
Set QCConnObj=Nothing
End function

Public function FindTestsInANode(TestsInPath)
'Here we need to goto the path
Set TreeManagerObj=QCConnObj.TreeManager
Set ParentFolderObj=TreeManagerObj.NodeByPath(TestsInPath)
'Here we are picking all the tests in that folder
Set TestFactObj=ParentFolderObj.TestFactory
Set TestListObj=TestFactObj.NewList("")
For each testObj in TestListObj
msgbox testObj.Name
Next
End Function