Showing posts with label QTP Tutorials. Show all posts
Showing posts with label QTP Tutorials. Show all posts

HP QTP Data Driven Framework

HP quick Test Professional Data Driven Framework will create using QTP Data Driven Methods

We can prepare HP QTP Data Driven Framework using below procedure or steps



Steps to Create Data Driven Framework:


Using Creating Search Flight Reservation Login

1.Create Framework folder structure Folders are

1.Object Repository
2.Test Scripts
3.Test Data
4.Test Log

2.Create Flight Reservation xls with Username,password and Reservation parameters and paste into Test Data folder.
3.Create Object Repository  of  Flight Reservation and save it in Object Repository folder.
4.Associate Object Repository to Test Scripts.

Test Script:

Option Explicit
Dim RowCounts ,k

'Add new sheet
DataTable.AddSheet "Test_Data"
'Import Test_Data sheet
DataTable.ImportSheet "E:\Automation\FlightReservation\FlightReservation.xls","Login","Test_Data"

'Count Number of row count in Input sheet
RowCounts = DaaTable.GetSheet("Test_Data").GetRowCount

'Use for loop to run multiple data
For k=1 to RowCounts Step 1
DataTable.SetCurrentRow(k)

'Open Flight Application
SystemUtil.Run "Flight reservation application path .exe"

Uname= DataTable.Value("AgentName","Test_Data")
Pwd = DataTable.Value("Password","Test_Data")

Dialog("Login").WinEdit("Agent Name").Set Uname
Dialog("Login").WinEdit("Password").Set Pwd
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").exist Then

Reporter.ReportEvent micPass "Verify Flight Reservation Login","Test Case is Pass"
DataTable.Value("Test_Results","Test_Data") = "Test Case is Pass"
Window("Flight Reservation").Close

else

Reporter.ReportEvent micFail "Verify Flight Reservation Login","Test Case is Fail"
DataTable.Value("Test_Result","Test_Data") = "Test Case is Fail"
Dialog("Login").Dialog("Flight Reservation").Winbutton("OK").Click
Dialog("Login").WinButton("Cancel").Click

End If

Next

DataTable.ExportSheet "E:\Automation\FlightReservation\TestLog\FlightReservation_Results.xls","Test_Data"

5.Save the Scripts in Test Script folder
6.Run the Test Script
7.Verify Results of Test Script in Test Log folder with excel data.


Helpful User Define Functions in QTP


User Define Functions


User define functions are used in QTP to create functions for web/desktop application functionalities to create Test scripts.In order to create User define functions Testers should follow the some steps and Syntax.Same as programming language VBScript will allow to create user define functions for repeatable Actions for Applications.

User Defined Function Creation in QTP

Procedure 1:

Public/Private Function Function Name(String 1,......etc)
Statements 1
Statements 2
Statements 3
Statements 4
End Function

Procedure 2:
  • Using Function definition Generator
  • Click on Function definition Generator
  • Enter Name,Parameters
  • Click on OK

Function Library

Function library is a collection of functions which contains Test scripts for Web/Desktop applications.
In order to delete the redundency ,duplication of Test Suite.In order to use function library first of all testers should associate function library to the Test Scripts.

How to Associate Function library file in QTP

Function library file will save in .vbs extesion.Testers can create function file in Notepad/qtp also.
Function library file can be associate using
File-->Settings-->Resources-->Add Associate library file-->Browse the file path.
We can assign library file using : Executablefile "path of the file"

How to count Number of sub folders and print Names

How to get sub folder count and print folder names using below VBScript,In order to count number of subfolders we need to use File System Object(FSO) .Please check the below code(VB Script) to print number of sub folders as well as Count number of Sub folders.



VB Script:

Dim Obj,Obj1,Obj2,Fold_names

Set Obj = CreateObject("Scripting.FileSystemObject")

'Creating a file system object

    Set Obj1 = Obj.GetFolder("D:\Manual_Testing\Manual_Projects")

    Set Obj2 = Obj1.SubFolders

    msgbox Obj2.Count 'displaying count of sub-folders

    For Each Fold_Iteam in Obj2

        Fold_names = Fold_names& Fold_Iteam.name &vbnewline

Next

msgbox Fold_names


HP QTP Data Table Methods

HP Quick Test Professional Data Table Methods


They are number of QTP Data Table methods to create Data Driven Framework ,below are the details.

1. Add Sheet
2. Delete Sheet
3. GetSheetCount
4. GetRowCount
5. GetSheet
6. Value
7. SetCurretRow
8. SetNextRow
9. SetPrevRow
10.Import /Import Sheet
11.Export /Export Sheet



Please find the details below

Add Sheet:

This method is used add new sheet to the run time data table
Syntax: DataTable.AddSheet("Sheet Name")

Delete:

This method is used to Delete one sheet using this method
Syntax: DataTable.DeleteSheet("Sheet Name")
Example : DataTable.DeleteSheet("Test_Cases")

GetSheetCount:

This method is used to Count number of sheets in Run time Data Table.
Syntax: DataTable.GetSheetCount

GetRowCount:

This method is used to count number of rows in the first excel sheet of the run time data table.
Syntax: DataTable.GetRowCount

GetSheet:

This method is used to get specified excel sheet from run time data table.
Syntax: DataTable.GetSheet("Sheet Name") or DataTable.GetSheet("SheetID")

Example : 
Sheet 1- 1
Sheet 2 - 2

DataTable.GetSheet(1)

Value:

This method is used to set or get value of cell data in specified the current row of the run time data table.
To Get Data
Syntax:

Variable Name = DataTable.Value(Parameter_Name,Sheet Name) or

Variable Name = DataTable(Parameter_Name,Sheet Name)

To Set Data
Syntax: DataTable.Value(Parameter Name,SheetName) = Value/Variable

DataTable(ParameterName,SheetName) = Value/Variable

Ex:
Uname = DataTable.Value("Username","rajeshk")
Pwd = DataTable.Value("Password","xxxxxxxxxx")

Browser("Gmail Login").Page("Gmail Login").WebEdit("Username").Set Uname
Browser("Gmail Login").Page("Gmail Login").WebEdit("Password").Set Pwd

SetCurrentRow:

This method is used to set specified row as current row in the run time data table.
Syntax: DataTable.SetCurrentRow(RowNumber)
Ex: Username = "Rajesh"
DataTable.SetCurrentRow(3)
DataTable.Value(3) = Username

SetNextRow:

This method is used to set the row after the current row as New Row in the Run time DataTable.
Syntax: DataTable.SetNextRow

SetPrevRow:

This method is used to set specified row as before the current row as new current row in Run time data table.
Syntax: DataTable.SetPrevRow

Import:

This method is used to import Excel file -Number of sheets to the run time Data table.
Syntax: DataTable.Import "Path of the Excel file"
DataTable.Import "E:\Automation\HP QTP\Testing.xls"

ImportSheet

This method is used to import specified excel sheet into Run time data table.
Syntax: DataTable.ImportSheet "Path of Excel file","Source Sheet","Destination Sheet"

Example:
DataTable.AddSheet "Test_Cases_App"

DataTable.ImportSheet "E:\Automation\HP QTP\Testing.xls","Test_Cases","Test_Cases_App"

Export:

This method is used Export Excel file in to specified location from another location
Syntax: DataTable.Export "Path of Excel file"

Export Sheet:

This method is used to export specified sheet into specified location
Syntax: DataTable.ExportSheet "Path of File","Sheet Name/Source Sheet"

DataTable.ExportSheet "E:\Automation\HP QTP","AutomationTesting.xls"

HP QTP Data Driven Testing

DATA DRIVEN TESTING



  1. Data Driven testing is used to test the application with multiple data.
  2. We will use Excel for data driven testing,
  1. Data Table enables you to run the tests with multiple set of data using Excel ..etc sources
  2. Data Table is used to store number of data and we can parameterize the data to the test script.
  3. In QTP there are two types of sheets by default
    1. Global Sheet
    2. Action1 Sheet
  4. One Data table have 256 sheets and in that one one sheet is Global ,Remaining 255 sheets are Action Sheets.

Two Types of Data tables

  1. Design Time Data Table
  2. Run Time Data Table

Difference between Design Time Data Table and Run Time Data Table

Design Time Data Table Run Time Data Table
This data table is viewed in QTP main test i.e in Expert View below. This data table is viewed in QTP test Results page
This data table is created priot to the test scripts execution. This data table created after the test execution

Creation of Data Driven Testing using Data table

  1. Software Testers will check the application,how it will perform the same action with multiple set of data.
  2. We can create a data driven test with a loop that can run multiple times with the different set of data.

QTP File System Objects login using Text file


Create a Text file with Username,Password

Username,Password
xxxxxxx,xxxxxxx
xxxxxx,xxxxxxxx

Option Explicit
Dim ObjFSO,ObjRD,Name

Set ObjFSo = Createobject("Scripting.filesystemobject")
Set ObjRD = ObjFSo.Opentextfile("c:\root folder\testing.txt")

While ObjRD.atEndOfline = false

Name = ObjRD.readline

Systemutil.Run "flight.exe application path"

Dialog("login").WinEdit("Agent Name").Set name
Dialog("login").WinEdit("Password").Set name
Dialog("login").WinButton("OK").Close

Window("Flight Reservation").Close

wend

ObjRD.Close

Set ObjRD = nothing
Set ObjFSo = nothing

how to identify objects in qtp

QTP(Quick Test Professional) identified the Objects from the web application i.e Test Objects .

QTP has 4 types of Object Identifiers

1. Mandatory Properties
2. Assistive Properties
3. Ordinal Identifier
4. Smart Identification




QTP mainly identify the objects in Desktop,Web applications using mandatory objects Ex:name,Id.
Quick Test Professional uses identification properties to identify the Test Objects ,Run Time Objects in Web,Desktop application.

So in order to test a application may be it is Desktop or Web application you need to identify the Test Objects in Application ,in order to define the Framework for your application you need Test Objects to identify the application Elements.Today we are going to learn QTP object identification Types.


Mandatory Properties:


Mandatory properties are those properties where QTP identify the objects while recording the Test Script.

Ex:
Systemutil.Run "iexplore","http://qaqtptutorials.wordpress.com"
Browser("Software Testing Tutorials").page("Software Testing Tutorials").Sync
'To check the Text box
Browser("Software Testing Tutorials").page("Software Testing Tutorials").WebEdit("name:=Username").Sync

Here we used name as mandatory property for WebEdit Test Object Class.

Assistive Properties:


If QTP has not identifying the objects with Mandatory Properties then QTP will use additional property to identify the Test Objects in application.

If you are using descriptive programming  with out Object Repository then we can use more properties to identify the Test Objects in application like below

Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("name:=Username").Set "xxxxxxxx"
Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("id:=password").Set "xxxxxxxx"

Ordinal Identifier:


We can use Ordinal Identifier to identify the Test Objects in Application ,in this we have Creation Time,Index,Location features to identify the Objects in application.

We can use this ordinal identifier if application having no of text boxes which is having some same properties at that time we can use.

First Name:Text Box 1
Last Name:Text Box 2
Middle Name:Test Box 3

Here for each text box we can identify as index:=0 ,Index:=1 , index:=2
Now we can write the test script as


Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("name:=test","index:=0").Set "Rajesh f"
Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("name:=test","index:=1").Set "rajesh s"
Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("name:=test","index:=2").Set "Rajesh t"

Same Example for Location

Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("name:=test","location:=0").Set "Rajesh f"
Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("name:=test","location:=1").Set "rajesh s"
Browser("name:=Software Testing Tutorials").Page("title:=Software Testing Tutorials").WebEdit("name:=test","location:=2").Set "Rajesh t"

Same we can use it for Creation time also ,mostly we can use it for browsers close functionality.While opening the browser some creation time will create at that time we can use this technique.

Smart Identification

QTP is not able to find the test objects in application with above three properties at that time qtp automatically identify the test objects using Smart identification mechanism.

Navigation to Object Identification in QTP

Tools-->Object Identification.


How to use transactions in QTP


Transactions




Transactions are used to find the speed of test script execution between the start and end point  means how much time it is taken to execute particular block of script.

In QTP having two Transactions

1.Start Transaction
2.End Transaction

Ex: 

Service.start Transaction<"Click Link">
Browser("Software Testing Tutorials").page("Software Testing Tutorials").link("text:2015").Click
Service.End Transaction<"Load Page">

Steps:

1.Go to Insert-->Start Transaction
2.Enter Transaction Name

1.Go to Insert-->End Transaction
2.Enter END transaction name.

QTP Synchronization Topics


Synchronization:

When we run out application at that time out application may not respond with the expected speed.


For example: 

  1. Progress bar to reach 100%.
  2. Status message to appear.
  3. Button become enable.
  4. Pop up window message to appear.
We can handle these timings problems by synchronizing your test script to ensure that quick test professional waits until web application is ready before performing any step.

We are having three synchronizations:

  1. Synchronization point.
  2. Wait and Exist.
  3. Increase time out.
Synchronization Point

 It is instruct QTP to stop the test until object property achieves the value in particular application.
We can use this option to provide waiting time  to the QTP based on particular object property.

Syntax: 

Browser("Browser name").page("page name").waitproperty "text","successful message",time in millisecond.


Steps to generate Synchronize point:

1.Place the cursor in required place of script.
2.Click on Start Recording
3.Click Insert-->Synchronization
4.Show object with hand icon
5.Press OK
6.Select Property name[Enable]
7.Enter property value[true]
8.Timeout in milliseconds
9.Press OK
10.Stop recording

Wait:
Wait is used to wait qtp untill object found according to specified time

Example:

Browser("Browser name").page("page name").Sync
Wait(5) //5 in milli seconds
Browser("Browser name").page("page name").WebEdit("Password").GetROproperty("text")



QTP Recording Modes



There are three types of Recording modes in QTP
  • Standard Recording (Default)
  • Analog Recording
  • Low level Recording
Standard Recording:
  1. Records the test in terms of GUI objects in qtp.
  2. QTP records the objects in application and application performed steps.
  3. Standard mode is the default and takes advantage of quick test object finding.
Analog Recording:
  1. Analog recording records the exact mouse and keyboard operations in applications relation to screen or application window.
  2. Analog recording will display in single line with track file.Window("microsoft Internet").Runanalog"track"
Low Level Recording
  1. This low level recording is enables to record all run time objects as window
  2. Generally for Multimedia purposes.

Powerful Automation Testing process in HP QTP





Automation testing process steps
  1. Tools Evaluation
  2. Analyzing Test Cases
  3. Preparing Modules sheet
  4. Effort Estimation
  5. Preparing summary report using POC
  6. Automation folder structure
  7. Preparing Object Repository
  8. Creating Library functions
  9. Creating scripts
  10. Dry run
  11. All script Execution
  12. Preparing Results
  13. Delivery of scripts-Framework

Successful versions of QTP tool


QTP is known as Quick Test Professional (QTP),QTP is used to test Functional as well as Regression testing purpose.



Below are the QTP versions till now.

QTP VERSIONS
Name
Version
Released
Astra Quicktest First version May 1998
Astra Quicktest version 3.0 Feb 2000
Astra Quicktest version 5.0 Feb 2001
Quick Test Professional version 6.5 Sep 2003
Quick Test Professional version 8.0 2004
Quick Test Professional version 8.2 2005
Quick Test Professional version 9.0 April 2006
Quick Test Professional version 9.1/9.2 Feb 2007
Quick Test Professional version 9.5 Jan 2008
Quick Test Professional version 10.0 Jan 2009
Quick Test Professional version 11.0 Sep 2010
Unified Functional Testing version 11.5 Dec 2012

It supports popular environments including
  • Windows
  • Web
  • Dot Net
  • Java
  • SAP
  • Active x
  • Siebel
  • Oracle.... etc