Thursday, 27 December 2012

Descriptive Programming In QTP

This article provides the details about:
  • Introduction to Descriptive Programming 
  •  Advantages of Descriptive Programming
  • Writing Descriptive Programming
  • When and Where to use the Descriptive Programming
  • Points to note with Descriptive Programming

Introduction to Descriptive Programming:
Descriptive programming is mainly used to perform the actions on objects which are not present in the object repository or we can simply tell that the entering/providing the object information directly into the test script is called Descriptive Programming.

Advantages of Descriptive Programming:
01.Maintenance is easy as the resources are less.
02.Script are portable as we can run the scripts from any machine.
03.We can start the test execution process before the application is ready.

Wring Descriptive Programming:
We have 2 ways to write the Descriptive programs.

01.Static Programming / Giving the description in the form of string arguments.
02.Dynamic Programming / Creating properties collection object for the description.

01.Static Programming:
This is most commonly used method in which the object description is directly passed into the script by specifying the "property:=value" pairs.It directly describes the object instead of specifying an object's name.


InvokeApplication "c:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "STC"
Dialog("text:=Login").WinEdit("attached text:=Password:").SetSecure password

Dialog,WinEdit,WinButton  - Test objects
text, attached text - Property Names
Login,Agent Name:, Password:, - Property Values - Represents the logical names of the objects

If we feel that the property information is not sufficient to identify the object uniquely we can add more property information.If we want to get the object names we can use object spy feature which is present in the object repository manager.
If we want to maintain the objects information in a centralized location then we can use Constants.
Const Login="text:=Login",Agent ="attached text:=Agent Name:"
Const Pwd ="attached text:=Password:", WBut ="text:=OK"

Note:We can declare n-number of contants in a single line separated by comma(,). But we need to use the word Const if we are going for a new line.

Creating Library:
01.Copy the above declared constants to a notepad and save it as a .vbs file.
02.Associate the vbs file to File> Settings> Resource> Click (+) icon> Browse the path of the vbs file and select the vbs file and then click on Apply, OK buttons or the library file can be loaded dynamically.

Syntax: ExecuteFile "path of the vbs file"
Example Of Creating Script using constants:
InvokeApplication("c:\Program Files\HP\QuickTest Professional\
Dialog(Login).WebEdit(Agent).Set "STC"
Dialog(Login).WebEdit(Pwd).SetSecure password

Advantages of the static programming: The main advantage of using library in static programming is that the changes can be easily done as the variable are declared in a common location.

02.Dynamic Programming:
This is also similar to the static programming. But the only difference is that it collects all the properties of a particular object in an instance of that object.By using that the object can be referenced easily by using the instance instead of the string arguments.

01.Create the description of the object.
Syntax:Set Variable=Description.Creare
Ex: Set Login = Description.Create
02.Enter properties information into the description of the object.
Syntax: Variable("Property Name").value ="Property Value"
Ex:Login("text").value = "Login"
03.Generating statements using description objects
Syntax:TestObject(Description Object").Method

Creating propeties Collection Of Objects:
Set oLogin = Description.Create
Set oPassword = Description.Create
Set oUname = Description.Createc
Set oOK = Descrption.Creae

Enter the properties information into objetcs:
oUname("attached text").value="Agent Name:"
oPassword("attached text').value ="Password:"

Generating Tests using properties collection objects:
InvokeApplication "c:\Program Files\ HP\ QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog(oLogin).WinEdit(oUname).Set "STC"
Dialog(oLogin).WinEdit(oPassword).SetSecure password

We can create the library files like static programming by following the below mentioned steps.

01.Create description objects and put into one library, by associating that library file,we can generate tests.
02.Dynamic programming is little bit difficult in preparation that the static programming but maintenance is easy.

Wednesday, 26 December 2012

QTP Settings Global Configuration

This article explains the details about the object identification and configuration.

As we know that there are around 25-30 object properties are available for each object in QTP. But QTP recognizes them by using only 2 to 3 properties.

By default QTP has certain configuration for each environment. We can add more properties if we feel that the default properties are not enough to identify the object.

In this article am going to explain the various object identification configurations available in QTP.

01.Normal Identification:
In this type of configuration,QTP uses two types properties to identify the object uniquely.
   a. Mandatory Properties
   b. Assistive Properties
In this configuration,QTP learns all mandatory properties at a time and thinks whether these properties are sufficient to identify the object uniquely. If it feels the properties are sufficient to identify the object uniquely then it stops learning.Otherwise,it learns the first assistive property once and stops and thinks and keep on repeating the steps until the object is uniquely identified.At the end of the assistive properties if QTP feels that the properties are not sufficient it finally goes to Ordinal Identifier.

02.Smart Identification:
In this type of configuration, QTP uses two types of properties to identify the object uniquely.
  a.Base filter properties
  b.Optional properties
This is an optional configuration.If we feel that the normal configuration is not enough to identify the object we can go for Smart Identification configuration. In this QTP learns all base filter properties at a time and thinks whether the properties are sufficient to recognize the object uniquely.If QTP feels the properties are sufficient then it stop learning.Otherwise, it goes to the optional filter properties and learns one by one.Then QTP keep on repeating the same step if it feel the properties are not sufficient. At the end of the assistive properties if QTP feels that the properties are not sufficient it finally goes to ordinal identifier.

03.Ordinal Identifiers:

We have 3 types of Ordinal Identifiers in QTP.
   b.Creation Time

Index: This one is based on the sequence of the programs. It starts from Zero.
Creation Time:This one is based on the loading time of the web objects.It starts from Zero.
Location: This one is based on the object location on the AUT. It starts from Zero.

Since QTP is a stand alone application, it's is not possible to configure the settings as Global. But QTP is providing a feature called "Generate Script" to configure the settings as Global.

01.The settings are available in 3 areas.
    a.File> Settings
    b.Tools> Options
    c.Tools> Object Identification
02.Configure the required settings and generate scripts.
03.The script should be stored in VBS format and shared with the team members.
04.Launch the generated script across n-number of PCs to get the same settings.

Tuesday, 21 August 2012

How to record a script in QTP?

This article explains the steps to be followed to record a script in QTP. Recording script in QTP is very useful for the beginners. We have to follow a certain steps to record a script.

01.Launch the QTP tool.
02.Click on Record button or Press F3 on QTP tool and observe that a pop up window is opened. This window will be opened automatically whenever the "Record" button is pressed.
03.Observe that the pop up window is opened with "Record and Run Settings" tab for each environment based on the add in configured/selected.
  Assume that we have Oracle, SAP add ins are configured along with the default Windows and Web environments.So, the pop up will be opened with Record and Run Settings tabs for Web,Windows, Oracle and SAP environments provided that the add ins are loaded when QTP launched.
04.For any environment the record and run settings are classified into two generic groups.

  • Record and Run on ANY window belonging to the particular environment.
  • Record and Run on a SPECIFIC window belonging to the particular environment. This option is recommended.
05. QTP will remember the settings for the entire record session until the record settings are manually changed by the Automation Engineer.
06.Click on "OK" button and observe that the disclaimer is updated as "Recording" in right bottom of the QTP tool bar.
07. Then launch the application to which the script to be recorded.Perform some action on the application and observe that the script is recorded in the form of VBScript in Expert View and in the form of Object Tables in Keyword view.
08.Once the action is performed on the Application just press on "Stop" or "F4" button and observe that the script recording is stopped.
09.Then Save the script.
10.Playback and check the script to make sure that the script is rerunning without any issue.

Wednesday, 20 June 2012

Insert Call To Existing Action in QTP

This article explains the details about the call to existing action in QTP. We can insert call to the existing/ reusable action stored in the current test or stored in external test. The action will be copied to the current test in read only format. We can view the steps of the action in action view, but we can't modify them.

The called action's object repository is also read only.If the called action has data in the Data Table,we can select whether we want the data from the action's data sheet to be imported as local,editable or read only from the original action.But the columns and data from the called action's global date sheet is always imported into the calling test as a local, editable copy.

Assume that we need to modify the called external action. TO to this, we need to open the original action from the test in which it resides and make the necessary changes. This modifications will be reflected in all the tests which are call that action. If we use the original action's data when you call an external action,then the changes made to the original action's data are applied as well.

Note: We can view the location of the original action in the General tab of the action properties dialog box.

Steps to be followed to insert a call to an existing action:

01.Navigate to Insert> Call To Existing Action from Expert/Keyword view or right click at any step> Action> Insert Call To Existing.
02.Observe that a window is opened with a combo boxes named as From and Action.
03.From combo box represents the list of tests which contains the resalable action.
04.We can select some other actions by using the browse button which is located just adjacent to From combo box.
05.Action combo box displays all reusable actions in the test we selected.
06.Assume that we selected any one of the action.When we select the action, its type(Reusable Action) and description,if one exists, are displayed.It'll be helpful for us to identify the action you want to call.

Note:External actions that the test calls are also displayed in the list.If the action we want to call is already called from within the selected test,we can select it from the list of actions.This creates another call to the original action.

07.Next step is to decide the insertion place. We can insert either at the end of the test or after the current step.

08.Click on OK button and observe that the action is inserted into the test flow. We can move our action call to another location in our test by dragging it to the desired location.

Note:We can create an additional call to any reusable or external action in our test by pressing Ctrl while you drag and drop the action to another location at a parallel (sibling) level within your test scripts.

Tuesday, 19 June 2012

Call To Copy Of Action in QTP

This article explains about the call to copy of action and the steps to be followed.
We need to remember the following points when using "Call To Copy Of Action" in QTP.

01.When we insert call to copy of an action in a test, the original action is completely copied to the current test.

02.Complete action represents the various checkpoint, parameters, copied actions data table and any defined parameters.

03.If the copied action has objects in Local Object repository, the copied action's local object repository is also copied with the action.

04.The copied action is inserted to the current test as an independent.

05.The copied action will be non reusable even though the original action was reusable.

06.Once the action is copied to the current test, we can perform the operations like add, modify and delete.

07.Changes made to the copied action will not have any impact on the original actions and also the changes made to the actual action will not have any impact on the copied action.

Steps to create a copy of an action:

We need to follow certain steps to copy the action to current test.

01.Make sure that the selected Test is opened.[Ex: Test1].
02.We can navigate to the insert call to copy option by using any one of the following step.

    Method#01: Navigate to Insert> Call To Copy of Action.
    Method#02: Navigate to Keyword view> Selection the Action>Right Click> Insert Call to copy of action.
    Method#03: Navigate to Keyword view> Selection the Action>Right Click> Action> Insert Call to copy of action.

03.A window will be opened once the option "Insert Call To Copy Of Action" is selected.The opened window will have 2 combo boxes. One is named as "From" and another one is named as "Action".

04.The From combo box will have the list of Tests available. We can select a particular Test which contains the action to be copied or we can select a particular test by clicking on the browse button which is located just adjacent to the combo box.

Note: Assume that the browse button is clicked and the Test which contains the Action to be copied is selected. Now the system will ask for the path. We can choose either absolute and relative path.

06.Once the test is selected, we need to select the action to be copied.To do this, we need to click on the Action combo box which is located just below the From combo box.

07.Once the action is selected,the type of copied action[Usable/Non-Reusable] action will also be displayed and also we can find a text box "Exit New Action Properties". We have to select this option if we want to make some changes the copied action.

 Note:Assume that we didn't select "Edit New Action Properties" check box when selecting the action. We can do this later by navigating to Keyword View> Right Click> Action> Action Properties tab.

08.We can also find two more options named as "At The End Of the test" and "After the Current" step. We can select any one of these two options.

09.Once everything is finalized click OK and observe that the action is inserted into the test as a call to independent, non-reusable action.

10.We can move our action call to another location by dragging it to the desired location.

Monday, 21 May 2012

Different Ways To Get And Count Objects In QTP

Getting and counting the number of objects on a web page is important factor as part of Automation testing. This article explains the different ways available to get and count the objects.

Descriptive Programming:
This approach uses Description Object, which contains a mask for objects we would to get.
Code Snippet:
 Set oDesc = Description.Create
 Set Links = Browser("aaa").Page("bbb").Page("ccc").ChildObjects(oDesc)
 MsgBox "Total Links" &Links.count

The method ChildObjects returns the collection of child objects matched the description ("micclass" is "Link") and containted within the object Page("ccc").

Object QTP property Collections:
As we know that QTP can work with Document Object Model(DOM).
Code Snippet:
 Set Links = Browser("aaa").Page("bbb").Page("ccc").Objects.Links
 MsgBox "Links Count" & Links.Length
 We used Object property of a page object which represents the HTML Document in a given browser. The HTML document contains different collections like forms, frames, images, linls. etc. We used Length property to get the number of items in the collection.

Object QTP Property & GetElementByTagName:
We can get access to the HTML Document by using Object property of the page and use its GetElementByTagName method to get the number of links on the page.
Code Snippet:
Set Links = Browser("aaa").Page("bbb").Object.GetElementByTagName("a")
MsgBox "Total Links" & Links.Length
We can use the above methods for finding the images,webedits, list of objects on a web page.

Capturing Tool Tip Of A Link In QTP

As we know that the Tool tip or infotip or a hint is a common graphical user interface element. It's used in conjunction with a cursor,usually a pointer.The user hovers the pointer over an item without clicking it, and a tooltip may appear - a small "hover box" with information about the item being hovered over.

Capturing Toop Tip(TT) in QTP is not a difficult task. We need to follow some steps to achieve this.

01. Place the mouse cursor over the link
02. Wait for tool tip
03. Get Text of the shown tool tip

Use the following code snippet to capture the text of a tool tip.

'Place the mouse cursor over the link
Browser("aaa").Page("bbb").WebElement("text:=Link Name").FireEven "onmouseover"
Wait 3
'Grab the tool tip

Please read the following steps which explains the details about the above code snippet.

01.We use FireEvent("onmouseover") to simulate mouse placing over the link.
02.Function Wait waits for 3 seconds for a tool tip.
03.To get tool tip we used the "("nativeclass:=tooltips_class32").GetROProperty("text")"

We can compare the captured tool tip with the expected if required. I hope this article is helpful in capturing the Tool tip of any link

Monday, 14 May 2012

VBScript Syntax Rules And Guidelines

Case Sensitive:
VBScript is not case sensitive.It means that it doesn't differentiate between upper case and lower case spelling of words, variables, objects and methods names or constants.

For example, Browser("aaa").Page("bbb").WebList("today").Select "131"
Browser("aaa").Page("bbb").WebList("Today").Select "131"will be treated in same way by QTP.

Text Strings:
When a value is entered as a text string, we should add quotation mark before and after the string.But we need to remember that the numbers also should be surrounded by quoatation marks, beacuse it's a text string that represent a number not a numeric value when the number is entered into a text box.

One more should be considered that the variables should not be surrounded by quotation marks.

For example: Browser("aaa").Page("bbb").WaitProperty("variable name", variable,20000)

We can use the variable to store strings,integers,arrays and objects.Using variables is very helpful to make the scripts more readable and flexible.

To achieve the desired result and to avoid errors,it's important that we use parenthesis() correctly in our statements.

We can indent or out-dent our script to reflect the logical structure of the nesting of the statements.

We can add the comments before writing a line or at the end of the statement.We have to use apostrophe(') to represent the comments.It's recommended to add the comments wherever possible, to make our scripts easier to understand and maintain.

We can add spaces in our script to improve clarity. These spaces are ignored by VBScript.

Thursday, 10 May 2012

QTP Driver Script

Actually we are using VBScript in most of the areas in QTP. But the Driver Script is the only QTP script, remaino all are VBscript files(.VBS).

Driver script is mainly useful to organize the Tests Exection and stores Test Logs in the specified file/folder.


adding sheets to runtime data table
datatable.AddSheet ("Module")
datatable.AddSheet ("Testcase")
datatable.AddSheet ("Teststep")

'Adding data sheets to runtime data table

Tcrowcount=datatable.GetSheet ("Testcase").getrowcount
        For j=1 to Tcrowcount step 1
           datatable.SetCurrentRow (j)
           If moduleid=moduleid1 and Ucase(tcexe)="Y" Then
               For k= 1 to Tsrowcount step 1
                   If TcId= TcId1 Then
                       keyword= datatable.Value(3,"Teststep")
                       Select Case keyword
                       Case "ln"
                       Case "ca"
                       Case "op"
                        End Select
                    End If
            End If
    End If
datatable.ExportSheet "D:\Automation\Testlog\results.xls","Teststep"

Sample Initialization Script:

Initialization Script launches QTP Tool and Calls Driver Script, Driver Script execute Tests and Stores Results.
Finally   Initialization Script Closes QTP tool

Option Explicit
Dim qtApp
set qtApp=createobject("QuickTest.Application")
qtApp.Open "D:\Automation\Testscripts\Driver"

Wednesday, 9 May 2012

Input And Output Operations in QTP

Am going to explain some of the input and output functions used in Test Automation script which will be useful in debugging the script as well as giving the input dynamically at run time.

InputBox Function:
This function is used to give the user input at run time.The behavior will be,
01.Displays a prompt will be displayed in a dialog box.
02.Waits for the user input text/click.
03.Returns the content of the text box.

Dim input
input=InputBox("Enter your name:")
MsgBox("You Entered:" & input)

MsgBox Function:
This function is mainly useful when debugging the script.The behavior will be,
01.Displays a message in dialog box.
02.Waits for the user to click a button
03.Returns a value indicating which button the user clicked.

Dim output
output =MsgBox("Hello World!",70,"MsgBox Example!")
Output variable contains either 1 or 2 depending on which button is clicked.

Tuesday, 8 May 2012

Dynamic Handling Of Object Repositories in QTP

This article gives the details about the dynamic handling of Object Repositories.Dynamic Handling of Object Respositories represents the Finding the path of the object repository,Loading the Object Repository and Removing the Object repository during run time.

Dynamic Handling is very helpful to improve the QTP performance.To do this, QTP is providing an object called "RepositoriesCollection".

Loading Object Repository:
Use the following code snippet to load a specific Object Repository.

RepositoriesCollection.Add "Path of the repository file"

Finding Object repository:
Use the following code snippet to find a specific object repository.

RepositoriesCollection.Find("Path of the Object repository")

Removing Object Repositories:
Use the following code snippet to remove the Object Repository during run time.


We can remove all the loaded Object Repositories by using the following code snippet.


SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set "softwaretestingcommunity"
Dialog("Login").WinEdit("Password:").SetSecure "mercury"

Monday, 7 May 2012

Database Connections In QTP

Database connection is a facility in computer service which allows the client software to interact with Database irrespective of the Database location. It means that we can access the database from any of the system.

I am going to give the code snippets which will be useful when writing database connection scripts.

SQL Server Connection Strings:
Standard Security:
"Driver="SQLServer",Server= Your_Server_Name;Database=Your_DB_Name;Uid=Your_User_Name;Pwd=Your_Password;"
Trusted Connection:
SQL OLE DB Strings:
Standard Security:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Data_Base_Name;Uid=Your_user_name;Pwd=Your_Password;'
Trusted Connection:
"Provider=SQLOLEDB;Data Sourcer=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
SQL SqlConnection .NET strings:
Standard Security:
"Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;" < br>2. "Server=Your_Server_Name;Database=Your_Database_Name;UserID=Your_Username;Password=Your_Password;Trusted_Connection=False"Trusted connection:
1."Data Source=Your_Server_Name;InitialCatalog=Your_Database_Name;Integrated Security=SSPI;"

MS Access connection strings:
MS Access ODBC connection strings
Standard Security:
"Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\App1\Your_Database_Name.mdb;Uid=Your_Username;Pwd=Your_Password;"
"Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\App1\Your_Database_Name.mdb; SystemDB=C:\App1\Your_Database_Name.mdw;"
Exclusive "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\App1\Your_Database_Name.mdb; Exclusive=1; Uid=Your_Username; Pwd=Your_Password;"
MS Access OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; User Id=admin; Password="
Open connection to Access database using Workgroup (System database):
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:System Database=c:\App1\Your_System_Database_Name.mdw"
Open connection to password protected Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:Database Password=Your_Password"
Open connection to Access database located on a network share:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\Server_Name\Share_Name\Share_Path\Your_Database_Name.mdb"
Open connection to Access database located on a remote server:
"Provider=MS Remote; Remote Server=http://Your-Remote-Server-IP; Remote Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb"

MySQL connection strings
MySQL ODBC connection strings
Open connection to local MySQL database using MySQL ODBC 3.51 Driver
"Provider=MSDASQL; DRIVER={MySQL ODBC 3.51Driver}; SERVER= localhost; DATABASE=Your_MySQL_Database; UID= Your_Username; PASSWORD=Your_Password; OPTION=3"
MySQL OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to MySQL database:
"Provider=MySQLProv;Data Source=Your_MySQL_Database;User Id=Your_Username; Password=Your_Password;"

Oracle connection strings:
Oracle ODBC connection strings:
Open connection to Oracle database using ODBC
"Driver= {Microsoft ODBCforOracle};;Uid=Your_Username;Pwd=Your_Password;"
Oracle OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to Oracle database with standard security:
"Provider=MSDAORA;Data Source= Your_Oracle_Database;UserId=Your_Username;Password=Your_Password;"
 "Provider= OraOLEDB.Oracle;Your_Oracle_Database;UserId=Your_Username;Password=Your_Password;"

Open trusted connection to Oracle database
"Provider= OraOLEDB.Oracle;DataSource=Your_Oracle_Database;OSAuthent=1;"

Thursday, 19 April 2012

Smart Identification In QTP

As we know that QTP is object based tool. QTP uses the learned object description to identify the objects. It searches for an object that matches with all of the property values in the description. In most of the cases the object description is the simplest way to identify the object, unless the main property values of the object change.

If QTP is unable to find any object that matches the learned object description, or if it finds more than a objects matches the learned description, and uses the Smart Identification mechanism to try to identify the object.

While Smart Identification(SI)  is more complex, it's more flexible. Therefore, the SI is configured logically, Smart Identification definition can probably help QTP to identify an object,if it present even the learned description fails.

Smart Identification mechanism use two types of properties.

Base Filter Properties: These are the fundamental properties of a particular object class.The values of the these properties can't be changed without changing the essence of the original object.
Example: Assume that the web link's tag is changed from {a} to some other value, you could no longer call it the same object.

Optional Filter Properties: Assume that the QTP is not able to identify the object with the help of Base Filter Properties. In that case QTP will use Optional Filter Properties to identify the object of a particular class.These properties are unlikely to changes on a regular basis, but can be ignored if they are no longer applicable.

Smart Identification Steps:
01. QTP forgets the learned test object description and creates a new object candidate list containing the objects that matches all of the properties defined in Base Filter properties.

02.QTP filters out the object in the object candidate list that does not match the first property listed in the Optional Filter Properties list. The remaining objects become the new object candidate list.
03.QTP evaluates the new object candidate list.
 03.00.If the new object candidate list still has more than one object, QTP uses the new object candidate list to repeat step 2 for the next optional filter property in the list.
 03.01.If the new candidate list is empty, QTP ignores this optional filter property, returns to the previous object candidate list, and repeats the step 2 for the next optional filter property in the list.
 03.02.If the candidate list contains only one object then QTP concludes that it has identified the object and performs the statement containing  the object.

04. QTP continues the process described in the step 2 and 3 until it either identifies one object, or runs out of Optional Filter Properties to use.

Assume that QTP is not able to identify the object even after Smart Identification elimination process.In such case QTP will use the learned description plus the ordinal identifier to identify the object.
If third combination is also not able to identify the object, QTP stops the run session and displays the error message.

Tuesday, 10 April 2012

Batch Testing In QTP

Batch Testing or Batch execution represents the execution of series or group of automated tests at a time.QTP provides a tool called "Test Batch Runner" to execute the group of Tests.

We can form a Test Batch by following the below mentioned steps.

01. Navigate to Start > All Programs > Quick Test Professional > Tools > Test Batch Runner
02. Observe that the Bach tool is launched
03. Then click on Batch> Add and Browse the Tests to be added
04. Select the Test and observe that the Test is added to Batch Tool
05. Repeat the above steps to add n-Number of Tests
06. Then the MTB(Module Test Batch with ".mtb" extension
07. Close the Test Batch Runner tool

We can execute the Test Batch by following the below mentioned Tests.

01. Launch the Test Batch Runner tool by navigating to "All Programs > Quick Test Professional > Tools > Test Batch Runner" path
02. Navigate to File> Open > Select the batch to be executed
03. Click on Run icon and observe that QTP is launched
04. QTP will run the Tests one by one

Note: We can execute the tests by using other Mercury tools. To do this we should configure Tools> Options> Run >Select "Allow Other Mercury Products" check box > Apply & OK.

We can also execute only Partial Test Batches by navigating to Test Batch Runner> Open Test Batch> Select or Deselect Tests and Run test.

We need to follow the below mentioned steps when doing Batch Testing.

01. Create individual Tests and execute once
02. Open "Test Batch Runner" Tool and Form Batches
03. Provide Permission to "Test Batch Runner" tool to run tests
04. Run the Tests from Test Batch Runner tool
05. View the Test wise results in Test Result viewer

QTP doesn't provide an option to view the result in Batch wise.

Wednesday, 4 April 2012

Parametrization In QTP

Parametrization is mainly useful when the functionality is tested with different sets/ types of data. This is mainly used in Data Driven Testing.

We have different ways to parametrize the tests.

Loop Statements: We can use the loop statements for passing sequential numbers and Logical Numbers.
Assume that we are going to enter numbers in a sequential manner in a text box.
Example: Flight Application
For i=0 to 20
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.').Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
Window("Flight Reservation").Dialog("Open Order").WinButton("OK').click

We need to remember that strings can't be generated through Loop Statements. But the same can be achieved with the help of Dynamic Data Submission.

Dynamic Test Data Submission:
We can pass the strings thought loop statements. But the user interaction is required.

For i=0 to 20
uName=inputbox("Enter User Name:")
pwd = inputbox("Enter Password:")
'Use the following snippet
Dialog("Login').WinEdit("UserName").Set uName
Dialog("Login').WinEdit("UserName").Type micTab
Dialog("Login').WinEdit("Password").SetSecure pwd
Dialog("Login').WinEdit("Password").Type micTab
Data Table:
As we know that QTP uses one data table for every test. We have the following types when using Data Table for parametrization.

01.Entering test data directly to data  table and use.
02.Importing test data from external spread sheets.
03.Importing test data from external flat files.

Entering Test Data Directly to Data Table and Use:
We need to follow the below mentioned steps when entering and using Test Data directly to Data Table.

01. Generate Test > Open Data Table
Note: The Data Table can be opened by navigating to View> Data Table
02.Click on the column header> Enter the name of the field(Ex:UserName)> Enter Data> Connect data to Test by using the following code snippet.

variable=datatable("column name",sheet id)
Ex: uName = datatable("UserName",1)
03.Run the test

uName= DataTable("UserName',1)
pwd = DataTable("Password",1)

Importing Test Data From External Spread Sheets:
We have to follow the below mentioned steps when using spread sheets for parametrization.
01. Open Data Table> Place the mouse pointer on Data Table and right click> File> Import From File>Click Ok>Browse the path of the excel sheet.
02.Then connect the data sheet to test by using the code snippet "
variable=datatable("column name",sheet id).
03.Execute the test.

Importing Test Data From External Files:
We can also import the data from external flat files by following the below mentioned steps.
01. Open Data Table> Place the mouse pointer on Data Table and right click> File> Import From File>Click Ok>Browse the path of the file sheet.
02.Then connect the data sheet to test
03.Execute the test.
Dim fso,ffile
Set fso=CreateObject("Scripting.FileSystemObject")
Set ffile = fso.opentextfile("D:\Automation\test.txt",1)
While ffile.atendofline<>true
'Write code to launch application here...
'The following snippet is to set the data read from the file to 'variable.
Dialog("Login").WinEdit("UserName").Set b(0)
Dialog("Login").WinEdit("UserName").Type micTab
Dialog("Login").WinEdit("Password").SetSecure b(1)
Dialog("Login").WinEdit("Password").Type micTab

Apart from the above methods we can fetch the data directly from the database as well as we can use the Dictionary object for parametrization.

Using Dictionary Object:

Set inputdata= CreateObject("Scripting.Dictionary")
inputdata.add "Username", "stc"
inputdata.add "pwd", "hp123"
'Write code to launch application here...
'The following snippet is to set the data read from the file to 'variable.
Dialog("Login").WinEdit("UserName").Set inputdata("Username")
Dialog("Login").WinEdit("UserName").Set inputdata("pwd")

Tuesday, 27 March 2012

Data Table Methods In QTP

Data Tables plays major role when using Data/Keyword Driven frameworks. It'll be easy to work with Data tables if we know the methods.We have the following methods in Data Tables.

AddSheet:This method is used to add only one new sheet to the run time data table.
Syntax: DataTable.AddSheet "sheet name"
Example: DataTable.AddSheet "stc"

DeleteSheet:This method is used to delete a single sheet from run time data table.
Syntax:DataTable.DeleteSheet (sheet id)
Example: DataTable.DeleteSheet (3)

GetSheetCount:This method is used to get the number of sheets available in the run time table.

GetRowCount:This method is used to get the number of rows from the run time data table. Obviously it'll return the longest used column count from the data table.

GetSheet: This method is used to return the specific sheet from the run time data table.
Syntax: DataTable.GetSheet(sheet id)

Value: This method is used to set or get the values from a particular cell of the run time data table.
Syntax to set data:
DataTable.Value(Parameter_Name,Sheet_Name) =  value or variable
DataTable(Parameter_Name,Sheet_Name) =  Value
Example: DataTable.Value(5,2)=a

Syntax to get data:
variable = DataTable.Value(Parameter_Name,Sheet_Name)
variable = DataTable.(Parameter_Name,Sheet_Name)
Example: a= DataTable.Value(5,2)

SetCurrentRow:This method is used to set a particular row as current row. By default it's first row of the 1st sheet.
Example: dataTable.SetCurrentRow(3)
dataTable.value(1,1)="software testing community"

SetNextRow:This method is used to set the next row as the new current row after the current row.
DataTable.Value(2,1)="software testing community"

SetPrevRow:This method is to set the row before the current row as the current row in the run time data table.

Import:This method is used to import an Excel file to the run time table.Assume that we have 3 workbooks in the selected file.We can import all 3 worksheets to the run time data table.
Syntax: DataTable.Import "file path"
Example:DataTable.Import "C:\Automation\DataSheet\stc.xls"

ImportSheet: This method is used to import a particular sheet of the selected Excel file to the run time data table.
Syntax: DataTable.ImportSheet "file path","source sheet", "destination sheet"
Example: datatable.ImportSheet "C:\Automation\DataSheet\stc.xls",2,1

Export: This method is used to export a copy of the run time data table to a particular location.
Syntax:DataTable.Export "file path".This will export all the sheets from the run time data table.
Example:DataTable.Export "C:\Automation\DataSheet\stc1.xls"

ExportSheet: This method is used to export copy of a particular sheet in  the run time data table to a particular location.

Syntax:DataTable.ExportShee "file path","source sheet.
Example:DataTable.Export "C:\Automation\DataSheet\stc1.xls",3

Monday, 26 March 2012

Object Identification Configuration in QTP

As most of us are aware of that the Object Identification plays a major role in Automation Testing. So, it's important to know the details about the different Object Identification types.

Generally we have 20-30 different properties for an object. But QTP uses around 3-4 properties to uniquely identify the objects. By default QTP has some default properties for each environment to identify the objects. If those properties are not sufficient we can configure some more properties to identify the objects.

We have the following types of Object Identification mechanisms or methods.
Normal Identification Mechanism: In this mechanism we have Mandatory properties and Assistive Properties. QTP will read all mandatory properties at one shot to identify the objects uniquely. If those properties are not sufficient it'll take first Assistive Property and progress. It'll be keep on going until the object is identified uniquely.
Assume that the objects are not identified uniquely based on the Mandatory and Assistive Properties. Then it'll go for Smart Identification mechanism.

Smart Identification Mechanism: This is helpful to identify the objects in a unique manner if the Normal Identification is not enough. In Smart Identification we have Base Filter and Optional Filter Properties.First QTP will read the Base Filter Properties as a whole and try to uniquely identify the objects. If not required it'll add the first Optional Filter Property and proceed further.The same process will be continued until the object is uniquely identified.

We need to remember that the Smart Identification is optional and mainly used to avoid the Ordinal Identifiers.

Ordinal Identifiers: Assume that the Normal identification and Smart Identification are not enough to identify the objects uniquely.Then we have one more option called Ordinal Identifier. We have 3 types of Ordinal Identifiers.
  • Location: This is mainly based on the location in AUT. Location number usually starts from zero.
  • Index: This represents the sequence of the programs which are opened. This also starts from zero.
  • Creation Time:This represents the loading time of the objects.It starts from zero.
Global Settings: We can't have Global settings in QTP as it's a standalone application. To overcome this we have an option to make the settings same across n-number of installers.

We have settings in 3 places.
  1. File > Settings
  2. Tools > Options
  3. Tools > Object Identification
Once the settings are configured we need to generate the scripts and share it with the team members.So, the tool will be launched with the same settings across n-number of installers when the script is executed.

Wednesday, 21 March 2012

Methods And Operations in QTP

This article gives the details about some of the frequently used QTP methods and its operations. We have the following methods.

  • Activate: This method is to activate Windows/ Dialogs
          Syntax: Object Hierarchy.Activate
           Example: Window("Flight Reservation").Activate
  • Click: This method to click the objects.
          Syntax: Object Hierarchy.Click
          Example:Window("Flight Reservation"). WinButton("Login").Click
  • Close: This method to close the browsers, windows,dialogs etc..
          Syntax: Object Hierarchy.Close

          Example:Window("Flight Reservation").Close
  • dbClick: This method to double click the objects.
  • Set: This method can be for any one of the following operation
          01. Set the values to the edit box 
                Syntax: Object Hierarchy.Set
                Example: Dialog("Login").WinEdit("UserName").Set "STC")
          02. To select the radio buttons
                Syntax: Object Hierarchy.Set
                Example: Window("Flight Reservation").WinRadioButton("Business").Set
          03. To Select or Deselect the checkboxes
       Syntax: Object Hierarchy.Set "ON/OFF"
       Example: Window("Flight Reservation").WinCheckBox("Business").Set "ON"

  • Select Method:It is used for selecting an item from a combo box or list box.
       Syntax: Object “item”
       Example:Window("Flight Reservation").WinComboBox("Fly From:").Select "India"
       Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "1222572
  • GetVisibletext: It returns Text from the specified area.
       Syntax: Variable =object hierarchy.getvisibletext
       Example:bb=Window("Flight Reservation").WinComboBox("Fly From:").GetVisibleText
       msgbox bb
  • GetRoproperty:It returns current object property value. It can be used for getting any object’s, any property value.
       Syntax: Variable = object hierarchy.getroproperty (“property name”)
       Example: aa=Window("Flight Reservation").WinEdit("Tickets:").GetROProperty ("width")
       msgbox aa
  •  Navigate Method:It opens a specified URL in the Browser.
     Syntax: object hierarchy.navigate “URL”
     Example: Browser("Yahoo!").Navigate
  •  Getitemscount: It returns number of items in a combobox.
    Syntax: Variable=object hierarchy.getitemscount
    Example: a=Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
    msgbox a
  • Getcontent: It returns all items from a combobox.
    Syntax: variable=object hierarchy.GetContent
    Example:y=Window("Flight Reservation").WinComboBox("Fly From:").GetContent
    msgbox y
  • Exist property: It checks whether the object is available or not.
    Syntax: Object hierarchy.exist(time in seconds)
    Example: Window("Flight Reservation").Exist(5)

Tuesday, 20 March 2012

Reporting Defects In QTP

QTP is an Object Based Test Automation tool. We can create and execute the tests using QTP. QTP provides varies methods to create and enhance tests.

Once the test are executed QTP provides the result in a result window and also it has the facility to define our own test results. We also have the result exporting facility in QTP Result Window.

The result should be analyzed by the Test Engineer who writes and executes the automation tests. Once the test execution results are analyzed, we can report the defect in any methods.

If we use the QTP Functional Test Automation and defect management manual the defects should be entered in the company described format.

If we are using the defect tracking tools like JIRA, Bugzilla etc., we can enter our defects in the standard templates configured in the tool. It varies from companies to companies.

We can also directly enter the defects into Quality Center if it's integrated with QTP. We have the facility to send the defect directly from Result Window to Quality Center.

Virtual Object Configuration in QTP

Some of the objects looks like standard objects in the Application Under Test but they will not be recognized by QTP. So, we need to configure the objects in such a way that the recognized by QTP. Such objects are called as Virtual Objects.

In Virtual object configuration we need to mark the certain area or the User Defined Object as Virtual object.Virtual object enables us to run the tests on the objects which are not identified by QTP. We can manage the virtual objects by using Virtual Object Manager.

We can configure the Virtual Objects by following the steps mentioned below.
  • Navigate to Tools Menu
  • Go to Virtual Objects
  • Select "New Virtual Object" option
  • Click Next
  • Mark the area of the application with the help of Mark Button Option
  • Click Next
  • Select any one of the following options
               01.Entire Parent Hierarchy
                02.Parent Only
  • Click Next
  • Enter the specified object name (Ex: Login)
  • Specify the collection name
  • Click on Finish
We can create and manage the Virtual Manager feature in QTP.

Monday, 19 March 2012

Measuring Transaction Time In QTP

In some situations we may need to track the time taken for the script execution or need to track the time taken for a functionality to completed. For example, we can take a Networking application. Assume that we are running the discovery service to identify the list of devices available on the selected network. Here we need to measure the time taken to discover all the devices.

QTP provides a Utility object called "Services" which is used to measure the transaction time. Assume that we are going to track the Discovery service of a networking application.

'* Starting transaction Time
Services.StartTransaction "DiscoveryService"
'* Logic for Discovery Service goes here
'* Tracking End time
Services.EndTransaction "DiscoveryService" 

We can find StartTransaction and EndTransaction under Insert menu. We can also have n-number of transaction points in the same script. But we need to make sure that the tracking is happening properly,

We can also measure the time by using Timer function.Timer is VBScript in built function. We can take the same discovery service for example.

'* Starting transaction Time 
starttime= Timer '* It returns the time elapsed since 12 A.M mid night in seconds
'* Logic for Discovery Service goes here 
'* End transaction Time 
endtime = Timer
'* Calculating final time
finalfime = endtime- startrime

Here starttime,endtime,endtime are variables. We can use any variable based on the wish.

Step Generator in QTP

Step Generator is a feature and Library of functions which is used for generating the Recordable or Non-Recordable steps.

We can launch the step generator by anyone of the following methods.

By navigating to Insert Menu > Step Generator.
By pressing F7 short cut key.

The Step Generator enables us to add steps by selecting a wide range context sensitive options and to enter the required values.We can define the steps than can use:
  • Test object operations(Tests only)
  • Utility Object operations
  • Calls to Library functions
  • Calls to VBScript functions
  • Calls to Internal functions
For example, we can create a step to check whether a particular object exists as well as returned value of a function as output value or as part of the conditional statement.

We can parameterize any of the values in out step.Also, we can use the Step Generator to insert steps in function libraries. However we can't use the Step Generator to access the objects names or collections or the list of libraries.

We need to know that where the step needs to be inserted in out script before adding the step.Once the Step Generator is opened we need to select the category for step operation(Test/Utility object, Function) and the required object or the function library. Then we can select the appropriate operation(method, property or function), define arguments and return values.We can parameterizing required by the functions.

The Step Generator is used to insert the correct steps at our test. We can also insert another steps without closing the Step Generator.We can use the Step Generator in Keyword/Expert View or from Active Screen.

Sunday, 18 March 2012

Comments in QTP Script

Comments are statements which are ignored by the host when the script is executed. 
To ensure that the comments statements are not interpreted during the script execution, comment delimiter should be used.We have two type of comments delimiters in VBScript.  They are single quotation mark (') and REM statement.

For example, the following are valid comments.
'This is a valid comment.
REM This is a valid comment.

Even though we have two types of comments delimiters supported by VBScript, most of us are using single quotation mark delimiter.We can use some other character along with the single quotation mark delimiter to show the comments separately.

For example, we can consider '* for commenting statements or lines of code.Ex: '* This is a valid comment.The main advantages when using a character along with single quotation mark are: makes the comment to stand out from other text, single quotation mark is difficult to read.

We need to remember the following points when using comment delimiters. Comments can be included along with the lines i.e., at then end of the line which becomes difficult for the user to read. For easy reading we have to make sure that the comments are added just above the line.

For example we can see both type of comments.
MsgBox "Welcome to Software Testing Community Blog!!!" 'Commented on the same line
 'Commented on a  separate line
MsgBox "Welcome to Software Testing Community Blog!!!" 
So, we can easily understand that the second type of commenting is much easier to read.

Code Commenting Conventions:

  • All procedures should begin with the proper comments saying that what they do.
  • We should not explain the implementation of the behavior.Because the implementation may change.So,it'll cause the unnecessary comment maintenance.
  • If necessary we can have inline comments by describing the implementation.
  • Return values of the procedure that are often changed by should be clearly described.
  • Every important variable declaration should be included in inline comments.
  • Variables, controls, and procedures should be named clearly to ensure that inline comments are only needed for complex implementation details.
  • At the beginning of your script, you should include an overview that describes the script, enumerating objects, procedures, algorithms, dialog boxes, and other system dependencies. Sometimes a piece of pseudocode describing the algorithm can be helpful.
  • Procedure header comments should include the following section headings.
              Section Heading:
              Comment Contents:

Thursday, 15 March 2012

QTP Action Template

Most of might have seen that some of the information are displayed by default when creating new action. Basically this is called "Action Template". Action Template is a mechanism which used to add some text by default whenever a new action is created.  Suppose we want to add some of the text for a test suite whenever a action is created. Instead of manually adding the same information again and again we can have the template to add the text by default. 

Assume that we need to have the following information whenever the Action is created.

'Action Name:
'Purpose :
'Created By:
'Created Date
'Modified By:
'Modified Date:

Steps to create Action Template:
Step#01:Open a Notepad and paste the above mentioned information.
Step#02:Save it as "ActionTemplate.mst".
Step#03"Navigate to QTP's dat folder which resides under "C:\ProgramFiles\HP\QuickTest Professional\." directort\y.
Note: This path may change based on the installation, QTP version or OS
Step#04:Copy and place the template created in Step#02.
Step#05:Then create a new action and observe that the above mentioned information is added to the action by default at the top.

Sometimes we may not see the action template items when creating new action. The main problem may be the extension of ActionTemplate file. It should be ".mst". The common mistake is the file name be saved as "ActionTemplate.mst.txt". So, we can eliminate this problem by deselecting the option "Hide extensions for known file types" option under "Any Folder >Tools> Folder Options > View tab".

Working With Multiple Browsers Using QTP

We are aware of that multiple instances of QTP can't be running on a single machine. But by using QTP we can work with multiple instances of the Application Under Test. For example, QTP can handle multiple browsers or multiple applications at a time.

We can work with 2 applications at a time even without stopping the recording. We should make sure that we configured both Record and Run on any opened applications(Both Windows and Web) under Automation>Record And Run Settings> Select the radio button "Record and Run on any application for both Windows and Web".

We have to keep it in our mind that we can't run multiple instances of QTP on a single machine.But we can handle multiple browsers or applications by using single QTP instance.

MsgBox Vs Print in QTP

This articles gives the details about the MsgBox and Print functions in QTP.

Most of us might have came across the function MsgBox which is used to display the variable values,text values etc., during our script execution. But from QTP 9.x series HP has introduced a statement called "Print". The purpose of the Print statement is similar to the MsgBox. 

MsgBox: It's a VBScript function which is used to display the information during run session in the form of pop up. The script execution will be stopped automatically once the MsgBox pop up is displayed. Because the pop up window will not be closed automatically. We may need to close it manually or can have driver script to close the pop up.So, we can't expect that the run session will be completed automatically when used MsgBox.So, when running batch session, we need to make sure that MsgBox function is not used in our script.

Print: Print statement is used to print the information in a print log during run session and it'll not affect the script execution. It means that the Print log will be printed along with the run session.So, while running the batch session we can use Print statement which will not pause the script execution.

Syntax: Print "<<msg>>" & <<variable name>>
Ex: Print "User Name is :"& Uname

Back To Top