Mar 16, 2010

Driver Script

 Driver Script
Generally in Keyword Driven Framework Driver Script is the only QTP Script, remaining all are Vb Script files (.vbs) 
Driver script organizes Tests execution and stores Test logs in the specified file/folder

Sample Driver Script
'adding sheets to runtime data table
datatable.AddSheet ("Module")
datatable.AddSheet ("Testcase")
datatable.AddSheet ("Teststep")

'Importing sheets from an external excel file
datatable.ImportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\test data\inputdata.xls",1,"Module"
datatable.ImportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\test data\inputdata.xls",2,"Testcase"
datatable.ImportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\test data\inputdata.xls",3,"Teststep"

Mrowcount=datatable.GetSheet("Module").getrowcount
For i=1 to Mrowcount step 1
    datatable.SetCurrentRow(i)
    Mexe=datatable.Value(3,"Module")
    If ucase(Mexe)="Y"  Then
        ModuleId= datatable.Value (1,"Module")

        Tcrowcount=datatable.GetSheet ("Testcase").getrowcount
        For j=1 to Tcrowcount step 1
            datatable.SetCurrentRow (j)
            ModuleId1=datatable.Value(4,"Testcase")
            Tcexe=datatable.Value(3,"Testcase")
            If ModuleId=ModuleId1 and Ucase(Tcexe)="Y" Then
                TcId=datatable.Value(1,"Testcase")

                Tsrowcount=datatable.GetSheet("Teststep").getrowcount
                For k= 1 to Tsrowcount step 1
                datatable.SetCurrentRow(k)
                Tcid1=Datatable.Value(5,"Teststep")

                    If TcId= TcId1 Then
                        keyword= datatable.Value(3,"Teststep")
                        Select Case keyword
                        Case "ln"
                        res=Login()
                        datatable.Value(6,"Teststep")=res
                        Case "ca"
                            close_app
                        Case "op"
                            res=Openord()
                            datatable.Value(6,"Teststep")=res
                           
                        End Select
                    End If

                Next
            End If

        Next
    End If
Next
datatable.ExportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\testlog\results.xls","Teststep"

Sample Initialization Script  
 Initialization Script Launches QTP Tool and Calls Driver Script, Driver Script execute Tests and Stores Results.
Finally   Initialization Script Closes QTP tool

Option Explicit
Dim qtApp
set qtApp=createobject("QuickTest.Application")
qtApp.Launch
qtApp.Visible=True
qtApp.Open "C:\Flight\Testscripts\Driver"
qtApp.Test.Run
qtApp.Quit

1 comments:

Thanks a lot. Your blog is helping me a lot to learn QTP

Post a Comment