Working with Database in UFT/QTP? – User friendly Tech help
Scenario:– How we can Fetch data from Database using UFT/QTP Automation Framework?
n
nSolution:– 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.
n
n 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
nwas given full rights for the database thus they can change/modify/update the database
n(thus selective in approach of testing, functionality/component/input data) with
ncomfort and without knowing any technical details of UFT.
n
nDatabase used in “Microsoft Access”, we can change the connection string parameters in
ncase we want to work with other databases like SQL Server, Oracle, Excel.
n
nPseudo-Code:–
n
nStep-1:- Manually creating Microsoft Access file and adding values into it
n
nStep-2:-Creating ADO objects for working with any kind of database
n
nStep-3:- Opening the database connection
n
nStep-4:-Sending the SQL command like select /delete/update
n
nStep-5:- Using Recordset object receiving the values from database until End of file(EOF)
n
nStep-6:- Closing the connection opened before and destroying the ADO objects to free the memory occupied by these objects.
n
nDatabase View:-n
![]() |
Access-Database with Tables(Test) |
n
Code Part-1:-
n
Below code is the calling script, which calls the DB functions placed separately
nin Function library.
n
'#################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#########################
n
nCode Part-2:-
nThis contains called Functions by above Driver Scriptn
![]() |
Opening Database Connection |
n
![]() |
Fetch and Update database |
n
![]() |
Closing the Database Connection |
n
Working with Outlook API in UFT