Working with Database in UFT/QTP?

Scenario:– How we can Fetch data from Database using UFT/QTP Automation Framework?

Solution:–  Database plays a crucial role in designing a robust framework in UFT.It provides flexibility to user to add or delete data irrespective to script of UFT.

We used this concept in creating Data/Keyword /Hybrid frameworks.  Basic aim was to allow non-expert users of UFT to run the scripts on selective data. Our manual team
was given full rights for the database thus they can change/modify/update the database
(thus selective in approach of testing, functionality/component/input data) with
comfort and without knowing any technical details of UFT.

Database used in “Microsoft Access”, we can change the connection string parameters in
case we want to work with other databases like SQL Server, Oracle, Excel.

Pseudo-Code:–

Step-1:- Manually creating Microsoft Access file and adding values into it

Step-2:-Creating ADO objects for working with any kind of database

Step-3:- Opening the database connection

Step-4:-Sending the SQL command like select /delete/update

Step-5:- Using Recordset object receiving the values from database until End of file(EOF)

Step-6:- Closing the connection opened before and destroying the ADO objects to free the memory occupied by these objects.

Database View:-

 

accessdatabase-8232440
Access-Database with Tables(Test)

 

Code Part-1:-

Below code is the calling script, which calls the DB functions placed separately
in Function library.

'#################Driver Script#########################
'Microsoft Access database path
sDBName ="C:UsersuftHelpDesktopData.mdb"
'Function call to connect to database,Incase Opening the connection fails then exit the test
if (not fnDatabaseConn(sDBName)) then
 Reporter.ReportEvent 1,"Connection to database cannot be establised","So exiting the test" ExitTest
End if
'Function call to fetch data from database and looping till the end of data is reached
Do
'Variable to take the data returned from the database 
 Dim sFileData
 'Function call to fetch data from database , Input parameters is the Table/Column Name of Database
 sFileData= fnDatabaseFetch ("Test","UserName")
 'IF data is returned from the database than do some operation on the returned data
 if( sFileData  "" ) then
 msgbox "Value of Data fetched from Database is " &sFileData
 'Function call for Updating the database reflecting that operation on current row is done
 fnUpdateDataBase "Test",Trim(sFileData)
 else
 Exit do
 End if
Loop
Msgbox "SuccessFully Completed Running of scripts on Data"
'Function call to close the opened connection fnCloseDatabase
'#################End of Driver Script#########################

Code Part-2:-
This contains called Functions by above Driver Script

 

creating2bdatabase2bconnection-9546399
Opening Database Connection

 

fetch2bdata2bfrom2bdatabase-3955788
Fetch and Update database

 

closeconnection-5972619
Closing the Database Connection

 

Working with Outlook API in UFT

Was this article helpful?
YesNo

Similar Posts