Test batch runner by using ADO

Excel files can also be accessed by using ADO objects. Similarly Test Batch runner can be created by using the ADO & AOM objects. Following is the code for the test batch runner by using ADO:


'********************* Launch QTP ****************************
Dim qtp
Set qtp=CreateObject("QuickTest.Application")
qtp.Launch
qtp.Visible=True

'*************** Open Excel file by using ADO objects **************
Dim ADO
Set ADO=CreateObject("ADODB.Connection")
ADO.Open "DSN=Excel Files;DBQ=C:\Users\sandeep\Desktop\Training\TestBatchRunner\TBR.xlsx;DefaultDir=C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\FILES;DriverId=790;MaxBufferSize=2048;PageTimeout=5;"

'**************Fetch data from excel file by using ADO***************
Set rs=createobject("ADODB.recordset")
rs.Open "Select * from [Sheet1$]",ADO
Dim counter:counter=0
Dim colCounter
Dim varScriptRunStatus
Dim scriptName
Do                      
counter=counter+1
colCounter=0
For each field in rs.Fields
colCounter=colCounter+1
If counter=1 Then                                                                                                                                        
If colCounter=2 Then
varScriptRunStatus=field.name
End If
else
If isnull(field.value)=False Then
If colCounter=2 Then
scriptName=field.value
End If
'*****************Open and execute scripts ****************************
If colCounter=3 and (lcase(varScriptRunStatus)=lcase(field.value) or lcase( varScriptRunStatus)="all")Then                                                                                                                                                                                                                
qtp.Open scriptName,True
qtp.Test.Run
End If                                                                                                                                                
End If
end If                                                
Next
rs.MoveNext
Loop until rs.EOF

'Release objects
Set rs=Nothing
Set ADO=Nothing
Set qtp=Nothing

Snapshot of the Data File:


Comments

  1. This is awesome! I have implemented it in our framework. Ashish your posts are really detailed and informative.

    This code works for me Perfectly. I rate it 5/5.

    Regards
    Sunil Jangir

    ReplyDelete
  2. This is awesome! I have implemented it in our framework. Ashish your posts are really detailed and informative.

    This code works for me Perfectly. I rate it 5/5.

    Regards
    Sunil Jangir

    ReplyDelete

Post a Comment

Popular posts from this blog

Test Batch Runner - Run QTP Scripts from xls file

Selenium: db and excel data into maps

Python: get entire workbook data cell by cell