Reading:  

Quick Test Professional - The starters Guide


Working with databases

QTP doesn't provide built-in support for the database connection, But by using VBScript testers can be able to connect easily and also by using ADODB objects can interact with databases.

 

QTP Database operations are:

  • External Files are Database, Text files, Excel files and Word documents
  • By using database operations we can easily access the data from any database.
  • VB Script is object Based Language, It does not support external files

ADODB has four methods to work with the databases.

  • Connection: This class is used to establish a connection to the particular database during execution time.
  • Command: This class is used to execute specified DML Statements such as Insert, Update and Delete on connected database.
  • Fields: This is used to fetch a specific column from a record group after executing a query.
  • Recordset: This class is used to execute specified select statement on connected database and get the results.

To connect to Database:

To establish a connection to the database, need to specify the required database connection parameters.

Now, how to connect to the database with parameters:

  • Database Type: MSSQL SERVER
  • Server Name: SQLEXPRESS
  • Database Name: The unique full name of database.
  • User Id: The name, we select must be a valid user on the target database with db_owner
  • Password: The need to enter the password for the user name.

Example:

Dim objConnect
 Set objConnect = CreateObject("ADODB.Connection")     
 Dim objRecordSet 
 
 'To create RecordSet Object
 Set objRecordSet = CreateObject("ADODB.Recordset")     
 
 Dim DBQuery 'Query to be Executed
 DBQuery = "Select * from Orders where Order_Number = 1&quot"
 
 'Connecting using SQL OLEDB Driver
 objConnect.Open "Provider=sqloledb.1;Server=.\SQLEXPRESS;User Id=sa;Password=Password123;Database=Trial"
 
 'To execute the Query
 objRecordSet.Open DBQuery,objConnect
 
 'To get the Result Set
 Value = objRecordSet.fields.item(0)				
 msgbox Value
 
 ' To release the Resources
 objRecordSet.Close        
 objConnection.Close		
  Set objConnect = Nothing
 Set objRecordSet = Nothing
 

Result:

After executing the script the output as shown below

Working with databases - QTP

Description

In this tutorial, we will get to know Quick test professional. At the time of writting QTP is at version 12.2. This tutorial is subdivided into multiple parts as shown below

  • What is QTP
  • Automating tests
  • Environment
  • Recording and Playback
  • Object Repository
  • Actions
  • Data Table
  • Checkpoints in QTP
  • Synchronization
  • Smart Identification
  • Debugging and Error handling
  • Recovery Scenarios
  • Environment Variables
  • Library Files
  • Test Results
  • GUI Objects
  • Virtual Objects
  • Accessing Databases
  • Working with XML
  • Descriptive Programming
  • Automation Object Model
  • A work on Frameworks

Leave your feedback for us, Feedback help us improve our tutorials.

 



Prerequisites

Some knowledge on Windows OS and VB Script is recommended

Audience

Students who wish to learn QTP

Learning Objectives

Learn QTP

Author: Subject Coach
Added on: 16th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!