Tuesday 22 October 2013

How to import data from database into DataTable

We are not follow any formalities if we using text or Excel file as resorces. But we follow some formalities if we use database as resources

a) Create a database
b) Create Tables
c) Enter test data

d) Create DSN (Data Source Name) 

ConnectionString - if we want to connect QTP to database, connection string is required for connecting QTP and database

Defualt location for store DSN

C:\Program Files\Common Files\ODBC\Data Sources

e) Read data using SQL statements


we no need to close the database if we are using in QTP. becuase its internally close that application.QTP is ready made environment


Vb Script Automation objects. For VB scripting , we can test the same as which we test in QTP script. But user need to define everything for Excel,datatabel in VB Scripting. But the QTP is provide ready made environment like Datatable. so no need to close that application.



Example :

1) Create a datable for login with below fields in MS Office Access

UserName     Password

Arun        12345
Raj        45454
Ajay         45457





See Screenshot of the Table from MsAccess in below





 

2) Import from datatable

a) Right click on datatable -> Sheet-> import-> From database





b) From Database Query Wizard-> select option Specify SQL Statement Manually -> click next





c)Below steps for create Connection String

First we create the new DSN and then its create the Connection String






Select the appropriate  Driver for our database. Here we are using the MsAccess for our database. so we choosing tje corresponding driver as Microsoft Access Driver(.*mdb)



Give the any value while create new data source



 So from above step we are create the new DSN.
DSN is different and our database is different. Now we are going to connect both DSN and our Database using below method.



 Select the database from our local machine





Now we are connected the DSN and Database. So its generated the Connection String automatically. We are retrieve the data manually by writing the SQL Query in below






After execute the above query, the data are imported into the below datatable



The above data are imported from database into the datatable. So now we can follow the normal way and syntax for using those data. the syntax are,

Steps for Data Driven Testing using Data table

1) Genrate Basic Test and run it once
2) Launch Data Table and enter / Imprt test data
3) Connect test Data to the test
4) Run the test

Syntext for connecting test data to test using datatable

DataTable(Column id/"Column name", Sheet id/ Sheet name)



No comments:

Post a Comment