'***************************************************
'***************************************************
'Author - QtpSudhakar.com
'Purpose - To Run a Test Batch for all tests in side of a folder
' - This will create a CSV file which will have all the status of execution
'How to Use - Specify the Folder Path of where tests are stored
' - Make sure you don't have any other empty folders without QTP test
' - Give TestPath, Save the code into VBS file and Double click on vbs file
'***************************************************
'For any doubts contact https://www.facebook.com/Qtpsudhakarblog
'***************************************************
'***************************************************
'Declare Variables
Dim TestsFolderPath 'To specify Tests folder path
Dim QtApp 'To store Qtp Automation Object
Dim fso 'To access file system
Dim fld 'To store the test folder object
Dim tFlName 'Unique File name to store Test Results
Dim fl 'To store Result File Object
Dim fldLst 'To store Child Folders(tests) of base folder
Dim f 'To store each QTP Test Folder
Dim tPath 'To store QTP Test Path
Dim tName 'To Store QTP Test Name
Dim WSH 'To open the created CSV result file
'Specify Base Tests Folder Path
TestsFolderPath="C:\Users\sudhakar\Desktop\tests"
'Create QTP Automation Object
Set QtApp = CreateObject("QuickTest.Application")
QtApp.launch 'open QTP
QtApp.visible=True 'Make it visible
'Create File system object
Set fso = CreateObject("scripting.filesystemobject")
'Get the base Tests folder
Set fld=fso.GetFolder(TestsFolderPath)
'Generate a unique file name with date and time
tFlName="TestExecution_"&Replace(replace(replace(now,"/","_"),":","_")," ","_")&".csv"
'Create the CSV file with the created name
Set fl=fld.CreateTextFile(tFlName)
'Get Subfolders from main folder
Set fldLst=fld.SubFolders
'Write first row as columns in CSV file
fl.WriteLine "TestName,TestPath,Status"
'Get each folder path and name to execute the test
For Each f In fldLst
tPath=f.Path 'Get Test Path
tName=f.Name 'Get Test Name
QtApp.open tPath 'Open Test in QTP
QtApp.test.run 'Execute Test
'Write Test result status into CSV file
fl.WriteLine tName&","&tPath&","&QtApp.test.LastRunResults.status
Next
'Close CSV file
fl.Close
'Get CSV File Path
tStatusFilePath=TestsFolderPath&"\"&tFlName
'Create WSH object to open the CSV file
set wsh=CreateObject("wscript.shell")
wsh.Run tStatusFilePath 'Open CSV file
'Release Variables
Set WSH=Nothing
Set f=Nothing
Set fldLst=Nothing
Set fl=Nothing
Set fld=Nothing
Set fso=Nothing
Set QtApp=Nothing
No comments :
Post a Comment