QTP Database Testing : Connecting to an Access database and executing a query
One of the most intriguing and challenging tasks for a tester is to conduct a Database test and verify the query and the related outcome. It surely needs extensive knowledge on executing the underlying queries and verifying its correctness based on a host of parameters. The most important aspect is the correctness of the query and the optimized nature. This requires good knowledge in query writing, understanding the intricacies of the Database.
Given below is an instance of QTP usage by connecting to an Access Database and verifying the output.
The script goes like this.
objCon.open”d:\Copy of FoodPlanner.mdb”
Do While Not objRs.EOF
Set objRS = Nothing
Set objCon = Nothing
# Notice the objects objCON and objRS. These are defined to accomodate the ADODB Connection and RecordSet. objCON for the Connection and objRS for the RecordSet.
# CreateObject : It is a latebinding method used for creating a connection and recordset object.
# objCON.Provider : Provides the details related to the connecting DB. Here in this case, it is clearly visible and stated as “Microsoft.Jet.OLEDB.4.0” for the MS-Access DB.
# objCON.Open : Once the provider details are given, the user will need to open the relevant Access Database table.
# objRS.Open : This is used to open and execute the appropriate query
# Datatable.GetSheet(1).AddParameter : Used to create column parameters for the datatable output (is evident in the snapshot given later).
# Do while loop : In this loop, the individual rows from the Access database table are accessed and then passed to the Datatable.value(Column, Row).
# SetCurrentRow(row) : This statement will set the current row within the Datatable.
# Datatable.export : The runtime results within the Datatable are not visible and may be accomplished by exporting these values to an external excel file.
# set object = Nothing : Every object created using the CreateObject will need to be closed for efficient and effective release of objects.