-->Batch Test

The purpose of the batch test is to execute a group of rebated scripts one by one without any user interaction.
Precautions that need to be taken care for creating the batch test.
1.Ensure that all the individual scripts are up & running properly without any problem
2.Ensure that each individual scripts taking care of its resources by object repository file, Environment file, library file, recovery files, external actions, etc.
3.Ensure that each script is handling Recovery scenario’s i.e, exception handling
4.Don’t use options like message box, input box etc, which requires a user interaction

Steps to Create a Batch Test:
1.Select Programs --> QTP --> Tools --> Test Batch Runner
2.Select Batch --> Add --> Select the required first file to execute
3.Repeat the above 2 steps to add the required scripts to the batch test --> Save the batch file (.mtb --> mercury test batch)
4.Select Batch --> Run
5.To run the batch test incase of any permission issue, follow these steps.
I.Go to QTP window --> Select Tools
II.Options --> Click on Run tab
III. Check the check box of 'Allow other mercury products to run tests & components'
IV.Click on Apply & OK.

-->Debug Options

You can set breakpoints, and you can temporarily enable and disable them. After you finish using them, you can remove them from your test or function library.
You can use breakpoints to:
1.suspend a run session and inspect the state of your site or application
2.Mark a point from which to begin stepping through a test or function library using the step commands
The debug options available in QTP are:
1.Break Points (F9)
2.Step Into (F11)
3.Step Over (F10)
4.Step Out
5.Watch list
6.Pause
7.Run from step
8.Run to step
Note: Breakpoints are applicable only to the current QuickTest session and are not saved with your test or function library.
Break Point:
You can use breakpoints to instruct QuickTest to pause a run session at a predetermined place in a test or function library. QuickTest pauses the run when it reaches the breakpoint, before executing the step.
Steps to insert the Break point:
I.Place the cursor where the break point needs to be inserted
II.Select Debug --> Insert/Remove break point (Alternatively right click on the line & select ‘Insert/Remove’ break point)
or
Click in the left margin of a step in the test or function library where you want the run to stop.
III.We can insert multiple break points in one script.

Step Into:
Choose Debug > Step Into, click the Step Into button , or press F11 to run only the current line of the active test or function library. If the current line of the active test or function library calls another action or a function, the called action/function is displayed in the QuickTest window, and the test or function library pauses at the first line of the called action/function.

Step Over:
Choose Debug > Step Over, click the Step Over button , or press F10 to run only the current step in the active test or function library. When the current step calls another action or a user-defined function, the called action or function is executed in its entirety, but the called action or function script is not displayed in the QuickTest window. This is used to execute the script line by line.

Step Out:
Choose Debug > Step Out, click the Step Out button, or press Shift+F11 only after using Step Into to enter an action or a user-defined function. Step Out runs to the end of the called action or user-defined function, then returns to the calling test or function library and pauses the run session.

Watch List:
1.Select View --> Debug viewer
2.Add the required variables to the watch list
3.Provide the break point in the 1st line of the script
4.Execute the script step by step
5.Analyze the values of the execution during playback

Pause:
You can temporarily suspend a run session by choosing Debug > Pause or by clicking the Pause button. A paused test or function library stops running when all previously interpreted steps have been run.

-->Difference between Actions & Functions

Actions:
1. When we reuse an action, we get all the resources like source code, data table contents & object repository.
2. When the source action is modified, the target script will get effected incase of ‘Call to Existing’ & it will not get effected incase of ‘Call to Copy’.
3. If we have to reuse a code with out any modification along with the object repository, then we use ‘Call to Existing’. And if we want to reuse with modification, then we use ‘Call to Copy’.
4. Actions are designed by QTP.
5. Most of the time actions contain the QTP script. i.e, the GUI objects, methods & properties, etc.

Functions:
1. When we reuse a function, we can reuse only the source code & not the data table contents or object repository.
2. When the source function is modified the target script will have the impact.
3. When we want to just reuse a code without any modification, then we can go for functions.
4. Functions are designed by Microsoft as part of VB Script.
5. Most of the time functions contain the VB script code like conditional & control statements, file system objects, etc.

-->Recovery Scenario manager (Cont...)

Test Run Error:
During the execution of the script, QTP throws an error if an object is not found (or) object description match more than one object (or) object not visible (or) item in the list or menu are not found (or) item in the list or menu are not unique, etc.
Steps to handle test run error:
1.Select Resources --> Recovery Scenario Manager
2.Click on New Scenario --> Click on Next
3.Select the trigger event as ‘Test run error’ --> Click on Next
4.Select the error message from the drop-down (if the exact message is not available, select any error) --> Click on Next
5.Select the recovery operation as “Function Call” --> Click on Next
6.Provide the library file path
7.Define the required function definition --> Click on Next
8.Select the post recovery operation as “Proceed to next step” --> Click on Next
9.Provide the name & description
10.Click on Finish --> Save the recovery file

Application Crash:
During the execution of the script, the application (AUT) crashes will interrupt the execution of the script.
Steps to handle Application Error:
1.Select Resources --> Recovery Scenario Manager
2.Click on New Scenario --> Click on Next
3.Select the trigger event as “Application Crash” --> Click on Next
4.Select the application from the “Running Process” list
5.Click on Add button (Then that application will be displayed in ‘Processes’ list --> Click on Next
6.Select the recovery operation as “Function Call” --> Click on Next
7.Provide the library file path
8.Define the required function definition --> Click on Next
9.Select the post recovery operation as “Proceed to next step” --> Click on Next
10.Provide the name & description
11.Click on Finish --> Save the recovery file

Object State\ Object Event:
The property value of an object in an application match with specific values can be specified at the object hierarchy.
Steps to handle Application Error:
1. Select Resources --> Recovery Scenario Manager
2. Click on New Scenario --> Click on Next
3. Select the trigger event as “Object State” --> Click on Next
4. Click on the hand icon & select the required object --> Click on Next
5. Click on ‘/Remove’ button to add or remove properties
6. Provide the expected values of the properties (Implement the Regular Expression if required) --> Click on Next
7. Select the recovery operation as “Function Call” --> Click on Next
8. Provide the library file path
9. Define the required function definition --> Click on Next
10. Select the post recovery operation as “Proceed to next step” --> Click on Next
11. Provide the name & description
12. Click on Finish --> Save the recovery file
On Error Resume Next: This option is used to proceed from the next line, when error occurs during the execution on the script without any interruption.
Eg: On error Resume next
- - - - - - - - - -
- - - - - - - - - -
Msgbox Err.number & Space(2) & Err.description & Space(2) & Err.Source
- - - - - - - - - -
- - - - - - - - - -
On Error go to 0
On Error Go to 0: It will turn off On Error Resume Next

-->Recovery Scenario Manager(OR)Exception Handling

Using Recovery scenario manager, we can handle the exceptions (unexpected errors) in the QTP script.
Using the Recovery Scenario Manager dialog box, you can then select any recovery file to manage all of the recovery scenarios stored in that file. This enables you to edit a selected recovery scenario, associate specific recovery scenarios with specific tests or components to instruct QuickTest to implement the recovery scenarios when specified trigger events occur, and so forth.
The following are the possible exceptions that can occur in the QTP script:
1.Pop-Up
2.Test Run Error
3.Application crash
4.Object State\Object Event

Pop-Up Exception: During the execution of the script some dialog box pop-up suddenly occurs which interrupts the execution of the script
Steps to handle Pop-up exception:
1.Ensure that the pop-up window is available
2.Select Resources --> Recovery Scenario Manager
3.Click on New Scenario(Image)--> Click on Next
4.Select the radio button ‘Pop-Up Window’ --> Click on Next
5.Click on the Hand icon
6.Click on the required pop-up window (captures the title & the message)
7.Implement the Regular Expression if required --> Click on Next
8.Select the Recovery operations ‘Keyboard or mouse operation’ --> Click on Next
9.Select the radio button ‘Click button with the label’ & click on the required button with the label --> Click on Next
10.Uncheck the check button ‘Add another recovery operation’--> Click on Next
11.Select the post recovery operation as ‘Repeat the current step & continue’ or ‘Proceed to next step’ (or as per the requirement)--> Click on Next
12.Provide the name & description --> Click on Next
13.Enable the check box ‘Add scenario to current test settings’
14.Click on Finish
15.Save the Recovery file.
Note: The recovery file will be saved as .qrs (QuickTest Recovery Scenario)

Steps to associate the recovery scenario file to the QTP script:
1.Select File --> Settings
2.Click on Recovery Tab --> Click on Add (+)
3.Select the required Recovery file
4.Click on ‘Add Scenario’ button
5.Click on Apply & OK

Script to associate the recovery scenario file to the QTP script:
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
App.Test.Settings.Recovery.Enabled = True
App.Test.Settings.Recovery.SetActivationMode "OnError"
App.Test.Settings.Recovery.Add "D:\Practise\QTP Testing\popupRS.qrs", "popupRS", 1
App.Test.Settings.Recovery.Item(1).Enabled = True

Steps to handle Pop-up exception by calling a Function:
1.Create an empty library file or use an existing library file
2.Select Resources --> Recovery Scenario Manager
3.Click on New Scenario --> Click on Next
4.Select the radio button ‘Pop-Up Window’ --> Click on Next
5.Click on the Hand icon
6.Click on the required pop-up window (captures the title & the message)
7.Implement the Regular Expression if required --> Click on Next
8.Select the recovery operation ‘Function Call’ radio button --> Click on Next
9.Select the required library file & define the required function --> Click on Next
10.Select the post recovery operation as ‘Repeat the current step & continue’ or ‘Proceed to next step’ --> Click on Next
11.Provide the name & description --> Click on Next
12.Enable the check box ‘Add scenario to current test settings’
13.Click on Finish --> Save the Recovery file.

-->Descriptive Programming & Description Objects

Providing the description of an object in the script itself (rather than maintaining them in the object repository) is called ‘Descriptive Programming’.

Scenarios in which Descriptive Programming can be used:
1.The object repository is full (saturated) & doesn’t want to add any new objects to it.
2.The object repository is read-only, where we can’t add any new objects
3.To increase the performance of the script execution. (Performance increases because there is no searching time for the object in the object repository during playback)
4.The application is still under development & test team wants to develop the automation script based on the proto type or by just having the properties of the object.

Eg: Dialog(“text:=Login”).WinEdit(“Attached Text:=Agent Name:”).Set “Rafi”
Dialog(“text:=Login”).WinEdit(“Attached Text:=Password:”,“height:=20”).Set “mercury”
Dialog(“text:=Login”).WinButton(“Text:=OK”).Click

Description Object:
It is used to define an object with its unique properties & use the object name in the scripting whenever it is required.

Eg: Set Dialog1=Description.Create
Dialog1(“text”).Value= “Login”
Set Dialog2= Description.Create
Text2(“Attached Text”).Value =“Password”
Text2(“Height”).Value=20
Dialog (Dialog1).WinEdit(“Attached Text:=Agent Name:”).Set “Rafi”
Dialog(Dialog1).WinEdit(Text2).Set “mercury”
Dialog(Dialog1).WinButton(“Text:=OK”).Click

Eg: Script which uses both DP & DO
Browser("Title:=.:OpenEnquiry:.").Page("Title:=.:OpenEnquiry:.").Link("Text:=Administration").Click
Browser("Title:=OpenEnquiry").Page("Title:=OpenEnquiry").Link("Text:=forum threads","Class:=menuheadlink").Click
Browser("Title:=OpenEnquiry_Threads").Page("Title:=OpenEnquiry_Threads").WinButton("name:=sort").Click
Set oDesc=description.CreateCreate()
oDesc("Micclass").Value="webList"
Set lists=Browser("Title:=OpenEnquiry_Threads").Page("Title:=OpenEnquiry_Threads").ChildObjects(oDesc)
NumberOfLists=Lists.Count()
msgbox NumberOfLists

-->Regular Expressions

Regular expressions are mathematical expressions used in QTP to generalize object properties which are consistently changing (dynamically changing) so that execution will be successful.
For eg-1; Say there is an application with classname javawindow and Edit box 'Title' and application belongs to version 1
In this case QTP captures test object info while learning as:
Class name : JavaWindow
Title : Customer details
Version : 1.0

And if we playback on the same application with a different version (say 1.1), the execution fails because of version mismatch. To generalize this we need to implement a regular expression for the version properties.
Eg: Regular expression to playback on the application with the version starting 1
Class name : JavaWindow
Title : Customer details
Version : 1.[0-9]*
Eg: Regular expression to playback on the application with any version
Class name : JavaWindow
Title : Customer details
Version : *.*
Or
Version : .*

Steps to implement Regular Expression:
1.Select Resources --> Object Repository
2.Select the required object from the left panel.
3.Select the required property from the right panel.
4.Click on configure the value option
5.Provide the regular expression for the value option
6.Enable the check button ‘Regular Expression’
7.Click on ‘No’ to not to add \ before & after special character
8.Click on OK --> Click on OK

Regular Expression Syntax:
* --> Matches the preceding character zero or more times.
Eg: "zo*" matches either "z" or "zoo".

+ --> Matches the preceding character one or more times.
Eg: "zo+" matches "zoo" but not "z".

. --> Matches any single character except a new line character

.* --> Any thing can repeat any number of times

? --> Matches the preceding character zero or one time only.
Eg: "a?ve?" matches the "ve" in "never".

x/y --> Matches either x or y.
Eg: "z|wood" matches "z" or "wood". "(z|w)oo" matches "zoo" or "wood".

{n} --> n is a non-negative integer which matches exactly n times.
Eg: "o{2}" does not match the "o" in "Bob," but matches the first two o's in "foooood".

{n,} --> n is a non-negative integer which matches at least n times.
Eg: "o{2,}" does not match the "o" in "Bob" and matches all the o's in "foooood." "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".

{n,m} --> m and n are non-negative integers which matches at least n and at most m times.
Eg: "o{1,3}" matches the first three o's in "fooooood." "o{0,1}" is equivalent to "o?".

[xyz] --> A character set which matches any one of the enclosed characters in the set.
Eg: "[abc]" matches the "a" in "plain".

[^xyz] --> A negative character set which matches any characters that are not enclosed.
For example, "[^abc]" matches the "p" in "plain".

[a-z] --> A range of characters which matches any character in the specified range.
Eg: "[a-z]" matches any lowercase alphabetic character in the range "a" through "z".

[^a-z] --> A negative range of characters which matches any character not in the range.

\b --> Matches a word boundary, that is, the position between a word and a space.
Eg: "er\b" matches the "er" in "never" but not the "er" in "verb".

\B --> Matches a non-word boundary.
Eg: "ea*r\B" matches the "ear" in "never early".

\d --> Matches a digit character.
\d is equivalent to [0-9].

\D --> Matches a non-digit character.
\D is equivalent to [^0-9]

\w --> Matches any word character including underscore ( _ ).
\w is equivalent to [0-9 a-z A-Z _]

\W --> Matches any non-word character
\W is equivalent to [^ 0-9 a-z A-Z _]

Script to work with the Regular Expressions:
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(strng)
For Each Match in Matches
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))

Eg: Regular Expression to validate an email id.
username@domainname.com
[0-9 a-z A-Z _ .]+ @ \w+ . [a-z A-z .]{2,3}

-->Regular Expressions

Regular expressions are mathematical expressions used in QTP to generalize object properties which are consistently changing (dynamically changing) so that execution will be successful.

Incase of the eg-1; QTP captures test object info while learning as
Class name : JavaWindow
Title : Customer details
Version : 1.0
And if we playback on the same application with a different version (say 1.1), the execution fails because of version mismatch. To generalize this we need to implement a regular expression for the version properties.
Eg: Regular expression to playback on the application with the version starting 1
Class name : JavaWindow
Title : Customer details
Version : 1.[0-9]*
Eg: Regular expression to playback on the application with any version
Class name : JavaWindow
Title : Customer details
Version : *.*
Or
Version : .*

Steps to implement Regular Expression:
1. Select Resources --> Object Repository
2. Select the required object from the left panel.
3. Select the required property from the right panel.
4. Click on configure the value option
5. Provide the regular expression for the value option
6. Enable the check button ‘Regular Expression’
7. Click on ‘No’ to not to add \ before & after special character
8. Click on OK --> Click on OK

Regular Expression Syntax:
Matches the preceding character zero or more times.
Eg: "zo*" matches either "z" or "zoo".

Matches the preceding character one or more times.
Eg: "zo+" matches "zoo" but not "z".

Matches any single character except a new line character

Any thing can repeat any number of times

?  Matches the preceding character zero or one time only.
Eg: "a?ve?" matches the "ve" in "never".

x/y  Matches either x or y.
Eg: "z|wood" matches "z" or "wood". "(z|w)oo" matches "zoo" or "wood".

{n}  n is a non-negative integer which matches exactly n times.
Eg: "o{2}" does not match the "o" in "Bob," but matches the first two o's in "foooood".

{n,}  n is a non-negative integer which matches at least n times.
Eg: "o{2,}" does not match the "o" in "Bob" and matches all the o's in "foooood." "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".

{n,m}  m and n are non-negative integers which matches at least n and at most m times.
Eg: "o{1,3}" matches the first three o's in "fooooood." "o{0,1}" is equivalent to "o?".

[xyz]  A character set which matches any one of the enclosed characters in the set.
Eg: "[abc]" matches the "a" in "plain".

[^xyz]  A negative character set which matches any characters that are not enclosed.
For example, "[^abc]" matches the "p" in "plain".

[a-z]  A range of characters which matches any character in the specified range. Eg: "[a-z]" matches any lowercase alphabetic character in the range "a" through "z".

[^a-z]  A negative range of characters which matches any character not in the range.

\b  Matches a word boundary, that is, the position between a word and a space. Eg: "er\b" matches the "er" in "never" but not the "er" in "verb".

\B  Matches a non-word boundary.
Eg: "ea*r\B" matches the "ear" in "never early".

\d  Matches a digit character.
\d is equivalent to [0-9].

\D  Matches a non-digit character.
\D is equivalent to [^0-9]

\w  Matches any word character including underscore ( _ ).
\w is equivalent to [0-9 a-z A-Z _]

\W  Matches any non-word character
\W is equivalent to [^ 0-9 a-z A-Z _]

(27/2/09)
Script to work with the Regular Expressions:
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(strng)
For Each Match in Matches
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))

Eg: Regular Expression to validate an email id.
username@domainname.com
[0-9 a-z A-Z _ .]+ @ \w+ . [a-z A-z .]{2,3}

-->Smart Identification

If the recorded description does not enable QuickTest to identify the specified object in a step, and a Smart Identification is enabled for the object, then QuickTest tries to identify the object using the Smart Identification mechanism.
Smart identification comes to action in 2 possible scenarios.
1.No Object Matches the Recorded Description
2.Multiple Objects Match the Recorded Description
Note: If the Smart Identification mechanism cannot successfully identify the object, the test fails and a normal failed step is displayed in the Test Results.
With smart identification mechanism, QTP learns 2 more categories of properties.
1.Base Filter Properties
2.Optional Filter Properties
Inorder to use the smart identification logic during playback, first of all smart identification should be enabled while learning the objects itself. By default smart identification is enabled only for the web controls & it is disabled for all other controls.
Steps to configure Smart Identification:
1. Select Tools --> Object Identification
2. Select the required environment from the list
3. Select the required test object class from the left panel
4. Enable the check button “Smart Identification”’
5. Click on configure --> Click on Add\Remove button
6. Add the properties under base filter properties
7. Add the properties for optional filter properties also
8. Click on OK --> Click on OK
9. Learn the object either by recording or manually selecting the object

Note:
1) We can’t directly enable the smart identification during playback. Rather it must be learn with smart identification properties. During playback if QTP fails to identify the object with the mandatory & Assestive properties, it will automatically use smart identification logic.
2) We can check in the QTP test results, what are the properties used for identifying the object uniquely when the smart identification is used.

-->Virtual Object Manager & Virtual Object Wizard

The error message “Object is not identified” will be displayed in 2 situations.
1.While Recording
2.While Playback

To overcome this error during Recording, we can follow the below options:
1.Low Level Recording
2.Virtual Object Wizard

To overcome this error during Playback, we can follow the below options:
1.Smart Identification
2.Regular Expressions

GUI Objects are of 2 types.
1.Standard GUI objects (Window, Dialog, Button, List, Table, etc…)
2.Non-Standard GUI objects

About Virtual object wizard:
1.Virtual object wizard is used to map a virtual object (Non standard GUI-object to a standard class
2.It is also used to capture the co-ordinates of the object
3.We can also assign a unique logical name to the object

Steps to map a virtual object to a standard class:
1.Ensure that the required virtual object is available
2.Select Tools --> Virtual Objects --> New Virtual Object --> Click on Next
3.Select the required standard class name from the drop-down (choose the closet one) --> Click on Next
4.Click on mark object
5.Select the required area of the object --> Click on Next --> Click on Next
6.Provide a unique name to the object
7.Select the radio button ‘YES’ to learn another object otherwise Select ‘NO’
8.Click on Finish

Note:
1) When we map a virtual object to a standard class, it will identify the objects using co-ordinates. So if the location is changed, the script execution will fail.
2) When we map virtual objects, they will be added to a collection in virtual object manager. Hence mapping done in 1 test can be used in a different test also.

-->Output Checkpoints (or) Output Value Statement

This option is used if the output of one operation is required as input for another operation.

Steps to work with Standard Output Value:
1.Ensure that the required object\window is available
2.Place the cursor where output checkpoint is to be inserted
3.Click on Record
4.Select Insert --> Output Value --> Standard Output Value
5.Take the hand icon --> Click on the required object\window
6.Select the required property, which needs to be generated as output
7.Click on Modify
8.Provide the parameter name & column name
9.Click on OKjavascript:void(0)

Steps to work with Text Output Value:
This option is used to generate the text from an object\window as an output either the data table or environment variable.

1.Ensure that the required object with the required text is available
2.Click on Record
3.Select Insert --> Output Value --> Text Output Value
4.Take the hand icon --> Click on the required object
5.Click on OK
6.Click on modify --> Provide the parameter name --> Click on OK

Steps to work with Text Area Output Value:
1.Click on Record
2.Select Insert --> Output Value --> Text Area Output Value
3.Select the required area from the object with cross-hairs --> Click on OK
4.Click on Modify
5.Provide the parameter name --> Click on OK

Steps to insert Database Output Value:
1.Select Insert --> Output Value --> Database Output Value
2.Select the radio button
3.Specify the SQL statement manually --> Click on Next
4.Click on ‘Create’ to create the connection string or select if it is already available
5.Provide the SQL statement --> Click on Finish
6.Select the required cell, whose value needs to be generated as an output.
7.Click on Modify
8.Provide the parameter name --> click on OK
9.Repeat the above 3 steps for each cell, whose value needs to be generated as an output

Steps to insert XML Output Value from resource:
1.Select Insert --> Output Value --> XML Output value from resource
2.Provide the path of the XML file --> Click on OK
3.Select the required nodes & the required attributes, whose value needs to be generated as output --> Click on Modify
4.Provide the parameter name --> Click on OK

Steps to insert XML Output Value from Application:
1.Ensure that the XML file is opened
2.Click on Record
3.Select Insert --> Output Value --> XML Output value from application
4.Click on the required XML file
5.Select the required nodes from the left panel
6.Select the required attributes & the values, which needs to be generated as output --> Click on Modify
7.Provide the parameter name --> Click on OK

-->Method to Add Parameter to the Local sheet

Method to Add Parameter to the Local sheet
DataTable.LocalSheet.AddParameter “Time”, “5:45”

Steps to import the data from database table:
1.Right click on the required sheet of the data table
2.Select Sheet --> Import --> From database
3.Select the radio button “Specify SQL statement manually”
4.Provide maximum number of rows if required
5.Click on Next
6.Create the connection string and provide the SQL statement
7.Click on Finish

Different Ways to Parameterization:
We can parametrize the script in 3 different ways
1.Using the Data Driver Wizard
2.Using the Keyword view
3.Using the Object Repository

Note: Using the Data Driver Wizard & Keyword view, we can parametrize the test data value. Where as Object Repository is used to parametrize any physical property of the text.

Steps to Parametrize using DDN:
Refer to pg no-

Steps to Parametrize using Keyword View:
1.Create the required basic script
2.Go to keyword view
3.Select the required value to be parametrize
4.Click on configure the value option
5.Select the radio button ‘Parameter’
6.Provide the parameter name & the location as Global or Local sheet
7.Click on Finish
8.Repeat the above steps to parametrize any values from the keyword view

Steps to Parametrize using Object Repository:
1.Select Resources --> Object Repository
2.Select the required object from the left panel
3.Select the required property from the right panel
4.Click on configure the value option
5.Select the radio button parameter
6.Provide the parameter name & location
7.Click on Finish

Parameter Types:
While parameterizing a value, we can select the parameter type to be one of the following 3 types:
1.Data table
2.Environment
3.Random Number


Steps to work with parameter type Data table:
Refer to Pg no-

Steps to work with parameter type Environment:
1.Create the required basic script
2.Select Tools --> Data Driver
3.Select the value to be parameterize --> Click on Parameterize Button
4.Click on Next --> Click on Parameter options
5.Select the parameter type as ‘Environment’
6.Provide environment variable or select from the drop-down for any system defined variable
7.Click on OK --> Click on Finish

Eg: Vbwindow(“VbWindow”).VbEdit(“VbEdit”).Set Environment(“Num1”)

Steps to work with parameter type Random Numbers:
1.Create the required basic script
2.Select Tools --> Data Driver
3.Select the value to be parametrize --> Click on Parametrize Button
4.Click on Next --> Click on Parameter options
5.Select the parameter type as ‘Random Number’
6.Provide the range for the random number to be generated.
7.Provide the parameter name --> Click on OK

-->Data Table Object Methods

AddSheet: This method is used to add a new sheet to the data table.
Syntax: DataTable.AddSheet(“Sheet Name”)
Eg: DataTable.AddSheet(“MySheet”)
Note: All the methods of data table object will have impact only during Runtime

DeleteSheet: This method is used to delete a sheet from the data table.
Syntax: DataTable.DeleteSheet(“” or )
Eg: DataTable.DeleteSheet(“Global”)
(OR) DataTable.DeleteSheet(1)

Import: This method is used to import the contents of an excel file into data table. While importing from an excel file we need to ensure the following things:
1.The number of sheets in excel file & in data table should be equal or more.
2.The sheet names may not be same. (We can modify the sheet names after importing)
3.The parameters names should be same.
Syntax: DataTable.Import(“”)
Eg: DataTable.Import(“D:\QTP\input.xls”)
Steps to import the data manually:
1.Right click --> Import from file --> Click on OK
3.Select the file name from which the data needs to be imported
4.Click on Open

ImportSheet: This method is used to import the data from the specific sheet of the excel file to the specific sheet of the data table.
Syntax: DataTable.ImportSheet “”,,
Eg: DataTable.ImportSheet “D:\QTP\input.xls”,2,1

Steps to import manually:
1.Right click in the required sheet of data table
2.Select Sheet --> Import --> From File --> Click on OK
3.Select the required file from which the data needs to be imported
4.Select the required sheet name from the dropdown
5.Click on OK

Export: This method is used to export the contents of the data table to an excel file. Even if the file is not available, it will create the file & export. If the file is available it will over ride.
Syntax: DataTable.Export(“”)
Eg: DataTable.Export(“D:\QTP\output.xls”)

Steps to export manually:
1.Right click in the data table
2.Select File --> Export
3.Provide the File Name --> Click on Save

ExportSheet:
This method is used to export the contents of a specific sheet of the data table to the excel file.
Syntax: DataTable.ExportSheet “”,
Eg: DataTable. ExportSheet “D:\QTP\output.xls”,2

Steps to import manually:
1.Right click in the required sheet of data table
2.Select Sheet --> Export
3.Provide the File Name --> Click on Save

GetCurrentRow: This method is used to identify the current active row number
Eg: ActRow=DataTable.GetCurrentRow
msgbox ActRow

GetRowCount: This method is used to get the number of records available in the data table.
Eg: RowCnt=DataTable.GetRowCount
msgbox RowCnt
Note: Methods like GetCurrentRow, GetRowCount, etc defaultly works on global sheets.


LocalSheet:
This method is used to work with the corresponding local sheet from which action we execute the script.
Eg: RowCnt=DataTable.LocalSheet.GetRowCount
msgbox RowCnt

GetSheetCount: This method is used to get the number of sheets available in the data table.
Eg: SheetCnt=DataTable.GetSheetCount
msgbox SheetCnt

SetCurrentRow: This method is used to set the focus to the specified row of the ‘data table-global sheet’.
Syntax: Datatable.SetCurrentRow()
Eg: Datatable.SetCurrentRow(17)

SetNextRow: This method is used to set the focus to the immediate next row of the current active row.
Syntax: DataTable.SetNextRow

SetPrevRow: This method is used to set the focus to the previous row of the current active row.
Syntax: DataTable.SetPrevRow

Value: This method is used for 2 purposes.
1. To read the value from the data table.
Syntax: Val=DataTable.Value(“”,“”)
Eg: Val=DataTable.Value(“Num1”,2)
msgbox Val
Note: We will not define the row number. By default it will pick the value of the current focus row.

2. To write the value into the data table.
Syntax: DataTable.Value(“”,“”)= “Value”
Eg: DataTable.Value(“Result”,”Action1”)=“Pass”
(OR) DataTable.Value(3,2)=“Pass”

Script to perform DDT manually:

DataTable.Import("D:\Practise\QTP Testing\input.xls")
RC=DataTable.GetRowCount
msgbox RC
For i=1 to RC
DataTable.SetCurrentRow(i)
VbWindow(“VbWindow”).VbEdit(“VbEdit”).SetDataTable.Value (“num1”,1)
VbWindow(“VbWindow”).VbEdit(“VbEdit_2”).SetDataTable.Value(“num2”,dtGlobalSheet)
VbWindow(“VbWindow”).VbButton(“Add”).Click
ExpVal=Datatable.Value(“ExpRes”,1)
ActVal=VbWindow(“VbWindow”).VbEdit(“VbEdit_3”).GetROProperty(“text”)
DataTable.Value(“ActRes”,1)=ActVal
If ExpVal=ActVal Then
DataTable.Value(“Result”,1)=”Pass”
Else
DataTable.Value(“Result”,1)=”Fail”
End If
Next
DataTable.Export(“D:\Practise\QTP Testing\output.xls”)

-->Data Driven Test (or) Parameterization

In order to test an application with multiple sets of test data, we need to parametrize the script. And the multiple test data can be drive through an excel sheet called data table.

In order to create a DDT, first we need to create a basic script on the application either by recording or manually writing/ generated. Then we can parametrize the script using the “Data Driver Wizard” or “Data Table Object Methods”.
The test data should be available in the data table to execute a DDT.

Steps to create a DDT using Data Driver Wizard:
1.Create basic script on the application
2.Select Tools --> Data Driver (it automatically displays the values which needs to be parametrized)
3.Select a value to be parametrized & click on parameter button
4.Click on Next --> Click on Parameter options button
5.Provide the parameter name
6.Select the location in the data table as Global sheet
7.Click on OK --> Click on Finish
8.Repeat the above steps for each value to be parametrized

Eg: Window(“Form1”).VbEdit(“Text1”).Set datatable(“num1,dtglobalsheet)
Window(“Form1”).VbEdit(“Text2”).Set datatable(“num2,dtglobalsheet)
Window(“Form1”).VbButton(“Add”).Click

Logic behind DDT:
When we execute a DDT
1. It counts the number of records in the data table
2. It forms a loop internally with the record s count from the data table
3. For each iteration the corresponding record is selected from the data table
4. For each selected record, it will execute all the parametrized values.
Steps to edit data table iteration option:
1. Select File --> Settings
2. Click on num tab
3. Select the required data table iteration option
4. Click on Apply & OK.

Eg:
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set DataTable("Uid", dtGlobalSheet)
Dialog("Login").WinEdit("Password:").Set DataTable("Pwd", dtGlobalSheet)
Dialog("Login").WinButton("OK").Click
If Window("Flight Reservation").Exist Then
Window("Flight Reservation").Close
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End If
If Dialog("Login").Dialog("Flight Reservations").Exist Then
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist Then
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
End If
If Dialog("Login").Exist<>true Then
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End If
End If

-->Steps to work with Global Procedures: (.vbs or .txt)

1. Open a notepad
2. Define the required functions & procedures
3. Save the file either with .vbs or .txt extensions. (This file is called as library file in QTP)
4. Go back to QTP script editor
5. Go to File --> Settings --> Click on Resource tab
6. Click on add library file button (+) in library section
7. Click on Apply and OK
8. Call the required function or procedure from the library file

Steps to work with function library editor: (this is available from QTP_9.0)
1. File --> New --> Function library
2. Define the required procedure in the library file
3. Save the file either with .qfl or .vbs or .txt extensions.
4. Go back to QTP script editor
5. Go to File --> Settings --> Click on Resource tab
6. Associate the library file.
7. Click on Apply and OK
8. Call the required function or procedure from the library file

Note: .qfl --> Quicktest Function Library
.vbs --> VB Script
.txt --> text

Characteristics of a Library file:
1. We can define any number of functions, procedures in any order in a library file
2. We can have 2 functions with a same name & with same arguments also in a single library file. In that case it will call the function or procedure which is defined at the end
3. We can define classes in a library file
4. A library file can have any executable code. That can be just declaration of a variable, set of functions\ procedures\ classes, etc.
5. Functions can be nested and recursive.

Associating a library file to QTP script:
Dim App
Set App=CreateObject(“QuickTest.Application”)
App.Test.Settings.Resources.Libraries.Remove All
App.Test.Settings.Resources.Libraries.Add(“D:\QTPTesting\Function.vbs”)
Note:
1. The above code set is used from QTP_6.5 to QTP_8.2. This is not being used from the versions then after.
2. The above methods can be used only if the library file has functions or procedures. If the library file has classes also, then the below syntax should be used:
ExecuteFile “D:\QTPTesting\Function.vbs”
(This is one being used by the latest QTP versions)
3. If the library file has classes, we should use ExecuteFile syntax only. And if there are no classes, we can use ExecuteFile syntax or we can associate it manually.

Class:
It is a collection of member variables & methods.
Methods can be function procedures or sub procedures.
Note: Inorder to use a single method present in a class, we need to create an Instance (called as Object) & then we can use that.

Eg: ExecuteFile “D:\QTPTesting\Function.qfl”
Obj=New Maths
Obj.Calc 7,8,x,y
msgbox x
msgbox y
Obj.Sample
Library file for above script:
Class Maths
Function calc(ByVal a,ByVal b,Byref c,ByRef d)
c= a*b
d=a+b
End function
Sub sample()
Msgbox “Hi All”
End Sub
End Class

-->Functions, Procedures, Classes

Procedures: The procedures are of 2 types.
1. Function procedures
2. Sub procedures
Function can return the value, where as procedure can't return the value

Syntax of Function:
Function(Arg1,Arg2)
Dim c
C= Arg1*Arg2
End function

Syntax of procedure:
Sub (Arg1, Arg2)
Dim c
C = Arg1*Arg2
End sub
Call (a,b)
(a,b)

Local Procedure: Defining a procedure and reusing it in the same script is called local procedure
Global procedure: Defining a procedure in a library file and reusing it across multiple scripts is called global procedure

Eg:1 Function with single return value
Function calc(a,b)
Dim c
C= a*b
calc = c
End function
Res = calc(7,8)
msgbox res

Note: To return the value from a function we need to assign the return value to the name of a function. When ever we are returning the value, parenthesis () is must.


Eg:2 Function with multiple return values
Function calc(ByVal a,ByVal b,Byref c,ByRef d)
c= a*b
d=a+b
End function
Calc 7,8,x,y
msgbox x
msgbox y

Eg:3 Function & procedure with multiple return values
Function calc(ByVal a,ByVal b,Byref c,ByRef d)
c= a*b
d=a+b
End function
Sub sample()
Msgbox “Hi All”
End Sub
Calc 7,8,x,y
msgbox x
msgbox y
call sample

Note: Save the function or procedure in notepad & save it as .vbs file

-->Actions with Parameters:

An action can have 2 types of parameters.
1. Input Parameter
2. Output Parameter
A parameter can be of type string, number, boolean, date, password, etc

Steps to declare the parameters for an action:
1. Select an action from the drop-down in the expert view
2. Select Edit --> Action --> Action Properties
3. Click on Parameter tab
4. Add the parameters for input & output sections by providing the parameter name, type & description --> Click on OK

Eg:
Test2
X=inputbox(“enter 1st value:”)
Y=inputbox(“enter 2nd value:”)
RunAction “Action1[TEST!]”,OneIteration,x,y,res
msgbox res

Test1
Action1 (reusable action)
a= Parameter(“i1”)
b= Parameter(“i2”)
c=a*b
Parameter(“o”)=c

Eg:
Test1
Userid = Parameter(“i1”)
Password = = Parameter(“i2”)
Dialog("Login").WinEdit("Agent Name:").Set "Userid"
Dialog("Login").WinEdit("Password:").Set "Password"
Dialog("Login").WinButton("OK").Click
If Window("Flight Reservation").Exist Then
Parameter("o")="Pass"
Else
Parameter("o")="Fail"
End If

Test2
Uid=inputbox(“Enter userid value:”)
Pw= inputbox(“Enter password value:”)
RunAction “Action1[Test1]”,OnceIteration,Uid,Pw,res
msgbox res

-->Difference between ‘Call to existing’ & ‘Call to Copy’:

Call to existing
1. In this all the resources like source code, data table contents & object repository contents are non-editable
2. If source action is modified, it will have impact on the target script as it is still referring to the source script.
3. While trying to use this, user can select only the reusable actions.
4. If we have to reuse an action as it is without any modification, we should go for this.

Call to Copy
1. In this all the resources like source code, data table contents & object repository contents are editable
2. If source action is modified, it will not have impact on the target script as it is making a copy with the target.
3. While trying to use this, user can select both reusable & non-reusable actions
4. If we have to reuse an action with any modification, we should go for this.

Split Actions:
Split is used to divide an action into two parts & while splitting we can specify whether the actions should be independent or Nested.
(Action2 being called from Action1 is called Nested)

Steps to split an Action:
1.Select the required action from the drop-down in expert view
2.Select Edit --> Action --> Split Action
3.Click on Yes to confirm the split
4.Provide the names for the splitted actions
5.Select whether the action is to be independent or nested
6.Click on OK

Note: When we split an action, the data table contents & object repository contents are maintained separately for the splitted actions. (Infact object repository will be duplicated for the two actions.

Delete Actions:

Steps to delete an action:
1.Select the required action from the drop-down in expert view
2.Select Edit --> Action --> Delete
3.Click on Yes to confirm the delete

-->Actions

Creating QTP script with a set of logical modules are called Actions. By default each test will have an action called “Action1”.

Advantages of using Actions:
1.Actions increase the readability. (i.e, It is easy to read & understand action by action, rather than the entire script)
2.Debugging is also easy. (We can debug the action directly)
3.Reusability (i.e, the actions created in one script can be reused in the same script or in a different script)

Types of Actions:
1.Non-reusable Actions (Default)
2.Reusable Actions
Internal Actions
External Actions

Internal Action: Creating an action and reusing it in the same script is called as Internal Action
External Action: Creating an action in one script and reusing it in another script is called External action.

Steps to create a script with multiple Actions:
1.Open a new test in QTP (By default there will be an action called Action1)
2.Click on Record --> Create a script for Action1
3.Select Insert --> “Call to New Action” option from menu
4.Provide the name of the action, description, reusability & location --> Click on OK
5.Create the script for the action
6.Repeat the above 3 steps to create multiple actions in the script.

Note:
1)Apart from “Action1” we can create 255 actions in one single script.
2)When we create a script with multiple actions, the object repository contents are maintained separately for each action. (i.e., Per Action Object repository)
3)For each action, the data table sheets are also maintained separately
4)The expert view lists the actions in the alphabetic order. To understand the order in which actions get executed, check it in the keyword view not in Expert view.
5)To change the order of the actions execution, drag & drop the action in the required place from keyword view.

Steps to edit the properties of an action:
1.Select an action from the drop-down in the expert view
2.Select Edit --> Action --> Action Properties
3.Edit the properties like Name, description, & re-usability.
4.Click on OK

Reusing of Actions:
We can reuse an action in the same script in which it is created or in a different script.
To reuse an action we have 2 options
1.Call to Existing action
2.Call to Copy action

Steps to Reuse an action using ‘Call to Existing’:
1.Ensure that the source script is available in the shared location
2.Go to the target script in which an action needs to be called
3.Select Insert --> Call to Existing action (OR) Right Click --> Action --> Insert Call to existing
4.Provide the path of the test. (It automatically displays all the reusable actions from the script)
5.Select the required actions from the list
6.Select the location --> Click on OK
Eg: RunAction “StuReg[ActionsExp]”,OneIteration

Note:
1)We can also reuse an action by using “Call to Copy Action”
Eg: RunAction “Copy of StaffReg”,OneIteration
2)When ever we reuse an action, we get all the resources required like source code, data table contents & object repository contents.

-->Transactions

Transactions are used to calculate the time taken for the particular scenario (calculating the response time)

Steps to work with Transactions:
1.Place the cursor where transaction to begin
2.Select Insert -> Start Transaction
3.Provide the transaction name -> Click on OK
4.Create the script for scenario to measure the response time
5.Place the cursor where the transaction to end
6.Select Insert -> End transaction
7.Select the transaction name from the list -> Click on OK

Eg1: Services.Start transaction “t1”
Invoke application “CALC”
Services.End transaction “t1”
The above script calculates the time taken for invoking the calculator application, which will be displayed in the results window of QTP.

Eg2: Dialog (“login”).Win edit (Agent name”).Set “Kiran”
Dialog (“Login”).Win edit (“Password).Set secure “3345hfdr234”
Dialog (“Login”).Win button (“ok”).click
Services.Start transaction “login”
IF window (“Flight reservation”).Exist (30) then
Services.End transaction “login”
End if
The above script calculates the time taking for logging in to the application.

Can we use QTP to do performance testing?
We can only calculate the response time for single user scenarios only and for the complete performance testing we should use Load Runner tool.

INTEGRATING WITH WIN RUNNER

Steps to call up WinRunner test:
1.Ensure that the Win Runner test is available
2.Select Insert -> Call to win runner test
3.Provide the test path -> Click on OK

Eg: TSL Test.Run test.exe”D:\QTP testing\WR test1”,True,False

Steps to call WinRunner Functions:

1.Ensure that the WR compile Module is available
2.Select Insert -> Call to WR Function
3.Provide the path of the compile module
4.Provide the function name -> Click the arguments in the (It automatically displays Arguments)
5.Select an Argument -> Select the type
6.Provide the value incase of type ‘In’ (or) ‘Inout’ -> Click on OK

Eg: TSL Test. Call Exe”D:\QTP Testing\w mod1”,”Calc”, true, False,”8”,”5,”c
msgbox c

-->User Defined Environment Variables

Steps to work with User defined Environment Variable (Local variable):
1.Go to File -> Settings -> Click on Environment Tab
2.Select the “User defined” option from the variable type
3.Click on Add variable button
4.Provide the name and value -> Click on OK
5.Repeat the above steps to add all the required environment variables
6.Go back to QTP Script editor
7.Use the following syntax to read the values of radio button

msgbox Environment (“DB Server”)

Note: The variables declared with the above steps are local to the script, which they are defined. We can’t use them for another script.

Steps to work with Global Variables (.ini format):
1.Open a notepad file -> Declare the environment variable as below
[Environment]
App path = C:\Programfiles\Mercury\Interactive\ Quicktestprofessional\samples\Flioght41.exe”
URL = http://localhost/Enquirysetup/index.aspx
User Id = Rafi, Password = Mercury
2.Save the file with .ini extension -> Go back to QTP script editor
3.Use the following code to retrieve the values of Environment variables
Environment.Load from file (“D:\QTP Teesting\Env.ini “)
App path = Environment (“app path”)
Invoke application App path
User = Environment (“user ID”)
User Val = Split (User,” “)
Log (“login”).Win edit (“Agent name”)
Val (Random given (0, u bound (user cal)))
Log (“Login”).Win edit (“Password”).set environment (“Password”)
Log (“Login”).Win button (“O.K”).Click

Steps to associate Environment file to the script:
1. File -> Settings -> Environment -> User defined
2. Enable the check button -> Load values & Variables from external file
3. Provide the path of the file -> Click on Apply and OK

Steps to work with Global variables (.XML Format):
1. Select File -> Settings -> Click on Environment tab
2. Select user defined from the variable type
3. Add the variable name and value->Click on Export
4. Save the file (save as .XML)
5. Open XML file -> Right click on it -> Select view source
6. Edit the file for adding or removing the variable -> Save the file
7. Go to QTP script editor
8. Use the following syntax to read the values
Environemnt.Load from file (“D:\QTP Testing\Env.XML”)
App path = Environment (“App path”)
Invoke application App Path
User – Environment (“user ID”)
User Val = split (user,” “)

External File name: This method is used check weather an environment file is already associated
Eg: f= environment. External file name
If f= "then"
Environement.Load from file (“D:\QTP Testing\Env.XML”)
f = Environment external file name
msgbox f
End if

-->Environment Variables

Inorder to execute the QTP script on any of the particular environments, we need to edit the values of the variables like URL, Userid, Password, etc. So, it is better to maintain in a separate file rather than maintaining them in the script. And these variables are called environment variables.

Different Types of Environment Variables:

1. Built-In Environment Variables
2. User Defined Environment Variables
Local Environment Variables
Global Environment Variables
.ini format
.xml format

Built-In Environment Variables:
We can find all the built-in environment variables from the location:
File -> Settings -> Environment Tab -> Select the variable type “Built-In”.

Syntax to read the value of the variable:
Environment.Value(“Variable Name”)
OR
Environment(“Variable Name”)
Eg: EnvVal= Environment.Value(“OS”)
msgbox EnvVal
OR msgbox Environment(“OS”)

-->Methods specific to Grid

RowCount: This method is used to get the number of rows available in the grid

Eg: RC = SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).RowCount

CoulmnCount: This method is used to get the number of columns available in the grid.

Eg: CC = SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).ColumnCount

SelectCell: This method is used to active or select a cell by providing Row, Column index

Eg: SC = SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).SelectCell 1,0

SetCellData: This method is used to write the data to a particular cell by mentioning the row and column index.

Eg: SCD= SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).SetCellData 1,0,“143”
GetCellData: This method is used to get the data from a particular cell by mentioning the row and column index

Eg: GCD=SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).GetCellData(1,0)

Eg: Write a script to check a particular value is available in the grid or not
ExpVal = “143”: found = false
RC = SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).RowCount
CC = SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).ColumnCount
For i=0 to RC-1
For j=0 to CC-1
ActVal =SwfWindow(“Enquiry”).SwfTable(“DataGrid1”).GetCellData(i,j)
If ExpVal=ActVal Then
msgbox “The Value Exists in the Grid”
found=true
Exit for
End If
Next
If found=True Then
Exit for
End If
Next

-->Other Pre-defined Methods

Set: This method is used to set the value to a text box or edit box, editor, Radio Button, Check button, etc.

Eg: VbWindow(“Material”).VbCheckbox(“Solid”).Set “ON”
VbWindow(“Material”).VbEdit(“Material number”).Set “45654”
VbWindow(“Material”).VbRadioButton(“QualityCheck”.Set

Eg: VbWindow(“Form”).VbButton(“Student Reg”)
CheckVal=VbWindow(“Form”).VbWindow(“FrmStudent”).VbCheckBox (“Concession”).GetROProperty(“Checked”)
If CheckVal = “OFF” then
VbWindow(“Form”).VbWindow(“FrmStudent”).VbCheckBox (“Concession”).Set “ON”
Else
VbWindow(“Form”).VbWindow(“FrmStudent”).VbCheckBox (“Concession”).Set “OFF”
End if

SetSecure: This method is used to set the value to a text box like password, pin, authentication code, etc in the encrypted format.
To generate the encrypted value
Go to programs -> QTP -> Tools -> Password encoder

Eg: Javawindow ("Login").Javaedit ("Password").Setsecure"YTV68866666$"

SetSecure: This method is used to set the value to a text box like password, pin, authentication code, etc in the encrypted format.
To generate the encrypted value
Go to programs -> QTP -> Tools -> Password encoder

Eg: Javawindow ("Login").Javaedit ("Password").Setsecure"YTV68866666$"


ChildObjects: This method is used to create a reference object for the child objects of the parent window/ dialog/ web page, etc.

Eg: Script to work with child objects method:
Set Children = Dialog(“Login”).ChildObjects
ChildCnt = Children.Count
msgbox ChildCnt
for i = 0 to ChildCnt-1
msgbox Children(i).GetROProperty(“Text”)
Next

Eg: Script to work with objects of type “buttons”
Set ODesc = Description.Create
ODesc = (“Class Name”).Value= “WinButton”
Set Children = Dialog(“Login”).ChildObjects(ODesc)
ChildCnt = Children.Count
msgbox ChildCnt
for i = 0 to ChildCnt-1
msgbox Children(i).GetROProperty(“Text”)
Next

Eg: Script to work with links from a web page
Set ODesc = Description.Create()
ODesc = (“micclass”).Value= “Link”
Set Children = Browser(“OpenEnquiry”).Page(“OpenEnquiry”)
.ChildObjects(ODesc)
ChildCnt = Children.Count
msgbox ChildCnt
for i = 0 to ChildCnt-1
msgbox Children(i).GetROProperty(“Text”)
Next

Note: For Web applications the property used is “micclass”
For Windows applications the property used is “Class Name”

-->Other Pre-defined Methods cont...

Select: This method is used to select an item from a list or a combo box or menu or a group of objects (like radio buttons group or a tree view, etc).
We can use Select method either by providing the index or value of the item itself.

Eg: VbWindow(“Material”).VbComboBox(“Mtype”).Select “Chemical”.Select 0
Eg: VbWindow(“Material”).VbMenu(“Menu”).Select “File;New”. VbRadioButtonGroup(“Class”).Select “A”

GetItemsCount: This method is used to get the total number of items from a list or a combo box or menu or radio button group or tree view, etc.
Note: This method can be used for all technologies except Web application.

Eg: ItemsCnt=VbWindow(“Material”).VbComboBox(“Mtype”).GetItemsCount
For i=0 to ItemsCnt-1
VbWindow(“Material”).VbComboBox(“Mtype”).Select i
Next

Eg: Write a script to check a particular item exists in a list or combo box
ExpItem = “Test”
ItemsCnt = Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).GetROProperty(“ItemsCount”)
For i=0 to ItemsCnt-1
Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).Select i
ActItem = Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).GetROProperty(“Value”)
msgbox ActItem
If ExpItem = ActItem then
msgbox = “Item found at index” & i
Exit For
End If
Next

Note: A Web list box doesn’t support the method “GetItemsCount”. But it supports the property “ItemsCount”

GetItem: This method is used to get an item value from a list or a combo box by providing the index number.

Eg: ActItem=Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).GetItem(2)
Msgbox ActItem
ExpItem = “Test”
ItemsCnt = Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).GetROProperty(“ItemsCount”)
For i=1 to ItemsCnt
ActItem=Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).GetItem(i)
msgbox ActItem
If ExpItem = ActItem then
Msgbox “Item found at index” & i
Exit for
End If
Next

Eg: Script to select an Item randomly from a list or a combo box.
ItemsCnt = Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).GetROProperty(“ItemsCount”)
ItemSel = RandomNumber(0,ItemCnt-1)
mgbox ItemSel
Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).Select ItemSel
Msgbox Browser(“OpenEnquiry”).Page(“OpenEnquiry_thread”).WebList(“List Topics”).GetROProperty(“Value”)

Note: ‘ or rem are used to comment a single line code
Cntrl+M is used to comment multiple lines code
Ctrl+Shft+M is used to uncomment multiple lines code

-->Other Pre-defined Methods

Exist:
This method is used to check a particular object is available or not, if the object is available it returns true otherwise it returns false
Eg: Invoke application “C:\Programfiles\Alerter\Alerter.exe “
If VbWindow (“Login”).exist then
Msgbox “Application launched “
Else
Msgbox “Application not launched “
End if

Reporter.Report Event:
This option is used to define a user defined message to the result window of QTP based on a step passes or failed
Eg1: Reporter.Report event micpass “login step”, “Login Successful”
Reporter.Report event micfail, “Login step”,” login failed”
(OR)
Eg2: Reporter.reportevent micdone, “Login step”, “Login successful”
Reporter.reportevent micwarning, “Login step”, “Login failed”
0 for MicPass
1 for MicFail
2 for MicDone
3 for MicWarning
4 for information

Wait Property (Synchronization point):
This method is used to synchronize the script execution with application execution.
Synchronization is of 2 types
Global Synchronization
Local synchronization

Global Synchronization:
The default value of global synchronization is 20 seconds, which is applicable to entire script, i.e. any step that requires the time less than 20 seconds QTP takes care of it , but if any step requires more than 20 seconds, then we have 2 steps
1.Increase the Global Synchronize value (Not a recommended option).
2.Insert local synchronization point

Steps to edit the Global Synchronization value:
1.Select File -> Settings
2. Click on Run tab
3. Edit the value “Object synchronization timeout” (in seconds)
Eg: Dim App
Set App = Create Object (“Quick test. Application”)
App.Test.Settings.Run.Object Sync Timeout = 10000

Wait property:
In this case the qtp will wait until the defined time gets complete.
Syntax: wait(time is millisec)
Eg: wait(200)

Local Synchronization:
Steps to insert local Synchronization point:
1. Place the cursor where synchronization point needs to be inserted, in the script
2. Ensure that required object /window is available based on whose property synchronization works
3. Click on Record -> Select insert -> Synchronization point
4. Take the hand icon -> Click on Required object window
5. Select the required property and expected value
6. Provide the time value in Milliseconds
7. Click on Apply and OK
Eg: Window (“material”).WaitProperty “Enabled”, True 20000

Note1: The time value in Synchronization point is required, because if there is any problem with object, it will wait for the maximum value given in the synchronization
Note2: If Application is taking less than what is provided in synchronization, script waits for as per application time
Note3: If application is waiting more time than what is provided in Synchronization, then synchronization fails. (Take maximum value in the synchronization as 2 or 3 times than actual value)

Difference between Wait Statement and Synchronization point:
Wait statement simply waits till the amount of the time is relaxed, where as synchronization point works intelligently and wait until the property of the object is matched. Hence we prefer Synchronization point.

Note: With exist method we can give a time like
If window (“Material”).Exist (30), it also works like a synchronization point

->Difference between Invoke application and SystemUtil.Run

Invoke Application:
This method is used to launch an application by proving the .exe file path from the QTP script itself.
Eg: Invoke application “Application_path”
SystemUtil.Run:
Eg: SystemUtil.Run “Application_path”

Difference between Invoke application and SystemUtil.Run.

Invoke application is used to invoke any .exe file, where as SystemUtil.Run works with any system utilities like “I-explore” apart from .exe file

How can we launch multiple instances of a web application?
Set IE1=CreateObject("InternetExplorer.Application")
IE1.Visible=True
IE1.Navigate "http:\\Yahoomail.com"
Set IE2=CreateObject("InternetExplorer.Application")
IE2.Visible=True
IE2.Navigate "http:\\Rediffmail.com"

--> Working with Predefined Objects and Methods

Methods common to various objects:
GetROProperty:
This method is used to get any one standard property or physical property of the GUI object.
Eg: Dialog(“login”).Winbutton(“OK”).GetROProperty(“Enabled”)
Note: To insert standard checkpoint we can use this method
ExpVal = False
ActVal = Dialog (“login”).win button (“ok”).GetRoProperty (“Enabled”)
Msgbox ActVal
If ExpVal = ActVal then
Msgbox ”Pass”
Else
Msgbox ”Fail”
End If

GetTOProperties:
This method is used to get the property value of a test object (An object learned by QTP and available in OR).

Difference between GetROProperty and GetTOProperty
GetROProperty is used to get any standard property, physical property of the Run Object (Object against which the script is expected to playback).
Where as GetTOProperty can get a property value of a test object (Object in Object Repository)
Note: Control space will give you all keywords

GetTOProperties:
This method is used to get all the properties of the Test Object.
Set Props = Vbwindow (“customer name”).GetTOProperties
PropsCnt = Props.Count( )
Msgbox PropsCnt
For i = 0 to PropsCnt-1
PropsName = props(i).Name
PropsVal = Props(i).Value
Msgbox PropsName & “=” & PropsVal
Next

-->Check Points (Cont...)

Database Checkpoint:
This option is used to verify the contents of a database table.
Steps to Insert Database Checkpoint (Ms-Access):
1. Ensure that the required database is available
2. Select Insert option from menu -> Checkpoint -> Database checkpoint
3.Select your database selection preferences. You can choose from the following options: *Create query using Microsoft Query. Opens Microsoft Query, enabling you to create a new query. After you finish defining your query, you return to QuickTest. This option is available only if you have Microsoft Query installed on your computer.
*Specify SQL statement manually. Opens the Specify SQL statement screen in the wizard, which enables you to specify the connection string and an SQL statement.
*Maximum number of rows. Select this check box if you would like to limit the number of rows and enter the maximum number of database rows to check or output. You can specify a maximum of 32,000 rows.
*Show me how to use Microsoft Query. Displays an instruction screen when you click Next before opening Microsoft Query. (Enabled only when Create query using Microsoft Query is selected).
4. Select the radio button Specify the sql statement manually.
5. Click on Next
6. Click on Create (To Create a New Connection String)
7. Click on New (To Create a New DSN)
8. Select the database driver in Microsoft Access Driver (*.mdb)
9. Click on browse -> Provide the name of the DSN
10. Click on Save -> Click on Next -> Click on Finish
11. Click on Select database
12. Select the required drive name & navigate to the location where the database file exists
13. Select the required “.mdb” file -> Click on OK
14. Select the DSN which we have created -> Click on OK
15. Provide the required SQL command (Select * from order)
16. Click on Finish
17. Select the required cell & edit the expected value required -> Click on OK

XML Checkpoint:
This option is used to verify the contents schema, attributes, etc of an XML file.

We can create XML checkpoints in 2 ways
1. XML checkpoint from Resource
2. XML checkpoint from Application

Steps to Insert XML Checkpoint From Resource:
1. Ensure that the path of the XML file is available
2. Select Insert -> Checkpoint -> XML checkpoint
3. Provide the path of the XML checkpoint -> Click on OK
4. Select the required mode from the left panel & Select the required attribute from the right panel.
5. Edit the expected value from the attributes
6. Enable the check button “Number of attributes”
7. Click on OK


Steps to Insert XML Checkpoint From Application:

1. Ensure that the XML file is open
2. Click on record
3. Select insert -> Checkpoint -> XML checkpoint from application
4. Take the hand icon -> Click on the XML file
5. Select the required nodes and required attributes
6. Edit the expected values from the attributes
7. Click on OK

-->Check Points(cont...)

Image Checkpoint:
This option is used to verify the properties of an image like name, source, HTML tag, etc…

Steps to insert Image check point:
1. Ensure that the required webpage is available
2. Click on record -> Select insert -> Checkpoint -> Standard checkpoint
3. Take the hand icon -> Click on the required image
4. Select required image from the hierarchy -> Click on OK
5. Select the required properties
6. Provide the expected value -> Provide the timeout value
7. Click on OK

Text Checkpoint:
This option is used to verify the text from an object or window
Steps to insert Text check point:
1. Ensure that the required object is available
2. Click on record -> Insert -> Checkpoint -> Text checkpoint
3. Click on the required object -> Click OK
4. Edit the expected value -> Select the verification objects like space, match case, exact match etc……
5. Click on configure -> Click text before and text after -> Click on OK
6. Provide the time out value -> Click OK

Text Area Check point:
This option is used to verify the specific text string with a defined area.
Steps to insert Text Area Check point:
1. Ensure that the requires object is available
2. Click on Record -> Select insert -> Check point -> Text area check point
3. Select the required text area from the object with the cross hairs
4. Select the required verification option like exact match, match case, ignore space etc...
5. Click on configure -> Click on text before and text after -> Click on OK

Bitmap Checkpoint:
It is a part of standard checkpoint; this is used to verify the content of an image either by selecting the complete image or only the required area

Steps to insert Bitmap checkpoint:
1. Ensure that the required bitmap window is available
2. Click on record -> Select insert -> Checkpoint -> Bitmap checkpoint
3. Take the hand icon -> Click on the required bitmap/image
4. To verify only the part of an image, Click on select area button
5. Select the required area of an image with cross hairs
6. Enable the check button -> Save the selected area
7. Click on Yes to delete the area which is not selected
8. Provide the timeout value -> Click on OK button

Difference between Bitmap and Image Checkpoint?

1. Using image checkpoint, we can verify the properties of an image like name, type, source, HTML tag, and the content also, where as in bitmap checkpoint, we can verify only the content of the image and not the properties..
2. In bitmap checkpoint, we can verify only the required part of an image where as in Image Check point we can not verify only the required part of an image.
3. Image checkpoint is only for Web based applications, but bitmap checkpoint is used for both windows and web based applications.

-->Check Points

A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property. This enables you to identify whether your Web site or application is functioning correctly.
Note: If you want to retrieve the return value of a checkpoint (a boolean value that indicates whether the checkpoint passed or failed), you must add parentheses around the checkpoint argument in the statement in the Expert View. For example:
a = Browser("MyBrowser").Page("MyPage").Check (CheckPoint("MyProperty"))

Adding Checkpoints to a Test
You can add checkpoints during a recording session or while editing your test.
To add checkpoints while recording or editing:
Use the commands in the Insert > Checkpoint menu, or click the Insert Checkpoint button on the toolbar.
To add a checkpoint while editing only
Right-click the step where you want to add the checkpoint and choose Insert Standard Checkpoint.
Select the step where you want to add the checkpoint and choose Insert > Checkpoint > Standard Checkpoint.
Right-click any object in the Active Screen and choose the relevant checkpoint option:
Insert Standard Checkpoint
Insert Bitmap Checkpoint
Insert Accessibility Checkpoint
These options can be used to create checkpoints for any object in the Active Screen (even if the object is not part of any step in the Keyword View).

Standard Checkpoint:
This option is used to verify the physical properties and standard properties of an object or a window. It can be used on both windows and web applications.
Steps to insert Standard check point:
1. Ensure that the requires object is available
2. Click on Record -> Select insert -> Checkpoint -> Standard checkpoint
3. Take the hand icon -> Click on the required object
4. Select the required property -> Provide the expected value for each property
5. Provide the time out value for the checkpoint in seconds -> Click on OK
--> Using this checkpoint we can verify properties of one object only, but we can verify one or more properties of that single object.
Setting General Standard Checkpoint Options
The bottom part of the Checkpoint Properties dialog box contains the following options:
Checkpoint timeout. Specifies the time interval (in seconds) during which QuickTest attempts to perform the checkpoint successfully. QuickTest continues to perform the checkpoint until it passes or until the timeout occurs. If the checkpoint does not pass before the timeout occurs, the checkpoint fails.
For example, suppose it takes some time for an object to achieve an expected state. Increasing the checkpoint timeout value in this case can help ensure that the object has sufficient time to achieve that state, enabling the checkpoint to pass (if the data matches) before the maximum timeout is reached.
If you specify a checkpoint timeout other than 0, and the checkpoint fails, the Test Results window displays information on the checkpoint timeout.
Insert statement. Specifies when to perform the checkpoint in the test. Choose Before current step if you want to check the value of the object property before the highlighted step is performed. Choose After current step if you want to check the value of the property after the highlighted step is performed.
Note: The Insert statement option is not available when adding a checkpoint during recording or when modifying an existing object checkpoint. It is available when adding a new checkpoint to an existing test while editing it.

Page Checkpoint:
This option is used to verify the properties of webpage like Load time, number of images, number of links, HTML source ,HTML tag, source of that images, URL of that links and broken links
Note: This is applicable for WebPages only
Steps to insert Page check point:
1. Ensure that the required webpage is available -> Click on record
2. Select insert -> Checkpoint -> Standard checkpoint
3. Click on the required webpage
4. Select page option from hierarchy of the object
5. Select he required properties to be verified
6. Provide the expected values from properties
7. Provide the value -> Click on OK

To insert the page checkpoint automatically for each webpage, while recording, use the following step:
Tools -> Options -> Click on web tab -> Click on advance tab -> Enable the checkpoint or automatic page checkpoint -> Select the required properties to verify -> Click on apply -> Click on OK.

-->Script Creation

QTP Considers every thing in an application as an OBJECT.
For easy understanding and writing a script this example will help you.
Each OBJECT belongs to a CLASS. Each CLASS has a PROPERTY. Each PROPERTY has VALUE.
For ex: Here i describe a Mango with respective to QTP
Mango is an OBJECT
It belongs to CLASS Fruit
It has a PROPERTY color
It has VALUE Yellow. This is how the qtp recognizes the Mango.

The script in QTP can be created in 3 ways
1. Using the Recording option
2. Using step generator
3. Manually writing the script

QTP provides 3 types of recording methods
1. Normal Recording or General Recording or Context sensitive Recording (Default one)
2. Analog Recording
3. Low-Level Recording

Normal Recording:
In this method of recording, qtp Records the user command actions like activating a window, minimizing or restoring a window, setting a value to text box, selecting an item form Combo box or list box, click on a button, etc.
Steps to perform Normal Recording:
1. Ensure that record and run setting are provided
2. Click on Automation(from menu) --> Record\F3
3. Perform required navigation's on the application
4. Click on stop recording\ Select Automation --> stop\F4

Analog recording:
In this method of recording, qtp records the mouse moments, keyboard operations, apart from user command actions, in relation to either the screen or the application window. This type of method is used to automate digital signatures, CAD/CAM, MS paint etc..
Steps to perform Analog Recording:
1. Ensure that record and run setting are provided
2. Click on Automation(from menu) --> Record\F3
3. Select Automation --> Analog Recording
4. Select the option to record relative to the screen or relative to the window
5. Click on hand icon and select the window
6. Perform required navigation's on the application
7. Click on stop recording\ Select automation stop\ F4
Note: You cannot edit Analog Recording steps from within QuickTest.
You can record in Analog Recording mode relative to the screen or relative to a specific window.
When you are finished and want to return to normal recording mode, click the Analog Recording button or choose Automation > Analog Recording to turn off the option.
If you chose to Record relative to the screen, QuickTest inserts the RunAnalog step for a Desktop item. For example:
Desktop.RunAnalog "Track1"
If you chose to Record relative to the following window, QuickTest inserts the RunAnalog step for a Window item. For example:
Window("Microsoft Internet Explorer").RunAnalog "Track1"
The track file called by the RunAnalog method contains all your analog data and is stored with the current action.

Record relative to a specified window
If the operations you perform are on objects located within one window and that window does not move during the analog recording session. This ensures that during the run session, QuickTest will accurately identify the window location on which the analog steps were performed even if the window is in a different location when you run the analog steps. QuickTest does not record any click or mouse movement performed outside the specified window. When using this mode, QuickTest does not capture any Active Screen images.
Record relative to the screen
If the window on which you are recording your analog steps moves during recording or if the operations you perform are on objects located within more than one window. This can include dragging and dropping an object from one window to another. When using this mode, QuickTest captures only the Active Screen image of the final state of the window on which you are recording.

Low-Level Recording:
This method is used, if an object is not identified with normal recording or analog recording. In case of low level recording QTP identifies the object using the Co-Ordinates(x, y, width, height) and it provides minimum set of methods to work with objects.
This mode records at the object level and records all run-time objects as Window or WinObject test objects. You can also use low-level recording if the exact coordinates of the object are important for your test.
Note: Steps recorded using Low Level Recording mode may not run correctly on all objects.
Steps to perform Low-Level Recording:
1. Ensure that record and run setting are provided
2. Click on Record button\ Select automation record option from menu\ F3
3. Select automation low-level recording
4. Perform required steps on the application (AUT)
5. Click on stop recording
When you are finished and want to return to normal recording mode, click the Low Level Recording button or choose Automation > Low Level Recording to turn off the option.
->Use analog recording or low-level recording only when normal recording mode does not accurately record your operation.
->Analog recording and low-level recording require more disk space than normal recording mode.
->You can switch to either Analog Recording or Low Level Recording in the middle of a recording session for specific steps. After you record the necessary steps using analog recording or low-level recording, you can return to normal recording mode for the remainder of your recording session.
When you are finished and want to return to normal recording mode, click the Low Level Recording button or choose Automation > Low Level Recording to turn off the option.

Difference between the same operations recorded using normal mode and Low Level Recording mode.
Suppose you type the word mercury into a user name edit box and then click the Tab key while in normal recording mode. Your test is displayed as follows in theExpert View:
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "mercury"
If you perform the same action while in Low Level Recording mode, QuickTest records the click in the user name box, followed by the keyboard input, including the Tab key. Your test is displayed as follows in the Expert View:
Window("Microsoft Internet Explorer").WinObject("Internet Explorer_Server").Click 564,263
Window("Microsoft Internet Explorer").WinObject("Internet Explorer_Server").Type "mercury"
Window("Microsoft Internet Explorer").WinObject("Internet Explorer_Server").Type micTab

Steps to work with Step generator:
1. Ensure that required objects are added to the OR
2. Place the cursor in the expert view, where a step needs to be generated
3. Select insert from Menu -> Step generator\ F7
4. Click on select object icon -> select the requires object -> if the object is not available -> click on the hand icon -> Click on the object from the application
5. Select the method name or operation -> Provide the value, if required -> Click on OK
6. Repeat for all the steps of Test scenario

Steps to create the script manually:
1. Add all the required objects to the OR
2. Spy on the parent object and view it’s class name
3. Spy on the child object and view it’s class name
4. In QTP Script editor (Expert View), use the following syntax to understand.
* Parent object class name (“Name”) Child object class name (“Name”), Method “Value”

-->Steps to Associate an Object Repository file to an Action of the Script

1. Ensure that the shared object repository file is available
2. Select Resources -> object repository -> Tools -> Associate Repository
3. Select the required object repository file using the + button
4. Select the required action from the list
5. Click on associate button (>)
6. Click on OK
Note: By default the objects in the associated object repository file are non-editable. To make it editable, right click on the required object and select “Copy to Local”
Script to associate an object repository file to an action of the script:
Dim App
Set App=CreateObject(“QuickTest.Application”)
Set Repositories=App.Test.Actions(“Action1”).ObjectRepositories
If Repositories.Find(“D:\QTPTesting\stureg.tsr”)=-1
Then Repositories.Add “D:\QTPTesting\stureg.tsr”,1
End if
Note:If we want to assign for multiple actions, we need to write the code set multiple times

Alternative code (Available from QTP_9.2)
If RepositoriesCollection.Find(“D:\QTPTesting\stureg.tsr”)=-1
RepositriesCollection.Add(“D:\QTPTesting\stureg.tsr”),1
End If
Note: RepositoriesCollection.Count (Method to count object repositories)
RepositoriesCollection.Remove (Method to remove object repositories)

Sample Script:
VBWindow(“Login”).VBEdit(“User id”).Set “Pass”
VBWindow(“Login”).VBEdit(“Password”).SetSecure “sunil”
VBWindow(“Login”).ACXCalender(“DTPicker”).Setdate “20-july-2009”
VBWindow(“Login”).VBButton(“OK”).Click

We can use “With” statement to reduce the repeating of the parent windows code every time:

With VbWindow(“Login”)
.VBEdit(“User id”).Set “Pass”
.VBEdit(“Password”).SetSecure “sunil”
.ACXCalender(“DTPicker”).Setdate “3-feb-2009”
.VBButton(“OK”).Click
End With

To apply “With” Statement:
Edit -> Advanced -> Apply “with” to Script (Remove “With” from Script)

If the AUT is Java & Java Add-in is selected, the script would be like below:
With JavaWindow(“Login”)
.JavaEdit(“User id”).Set “Pass”s
.JavaEdit(“Password”).SetSecure “sunil”
.JavaCalender(“DTPicker”).Setdate “3-feb-2009”
.JavaButton(“OK”).Click
End With

If the AUT is .Net & .Net Add-in is selected, the script would be like below:
(Swf means Shake Wave Form)
With SwfWindow(“Login”)
.SwfEdit(“User id”).Set “Pass”
.SwfEdit(“Password”).SetSecure “sunil”
.SwfCalender(“DTPicker”).Setdate “3-feb-2009”
.SwfButton(“OK”).Click
End With

If the AUT is Web application & Web technology Add-in is selected, the script would be like below:
With Browser(“name”).Page(“Login”).Frame(“login”)
.WebEdit(“User id”).Set “Pass”
.WebEdit(“Password”).SetSecure “sunil”
.WebCalender(“DTPicker”).Setdate “3-feb-2009”
.webButton(“OK”).Click
End With
Note: The path where we can see the controls of all the languages is “Tools --> Object Repository”
“Nested with” also works in QTP

If no language is selected, then QTP identifies the objects as standard windows controls, like below:
With Dialog(“Login”)
.WinEdit(“User id”).Set “Pass”
.WinEdit(“Password”).SetSecure “sunil”
.WinCalender(“DTPicker”).Setdate “3-feb-2009”
.WinButton(“OK”).Click
End With

-->Object Repository Manager Menu Options

File -> Enable Editing: This option is used to enable the contents of object repository for editing, when we open the Object Repository file with File --> Open.

Steps to Export to & Import from XML:
File -> Export to XML/ import from XML
1. Open the required object repository file in the object repository manager
2. Select File -> Export to XML
3. Provide the name of the file
4. Click on Save
5. Click on OK
6. To import the file, Go to object repository manager
7. Select File -> Import from XML
8. Select the required XML file
9. Click on Open

Object -> Navigate & learn: This option is used to learn all the objects which fall under navigation from a parent object. (Its available from QTP_9.2)
Steps to work with Navigate & Learn:
1. Ensure that the AUT window is available
2. Select Object -> Navigate & Learn
3. Click on the required object window
4. Click on parent window
5. Click on Learn Button. (It takes few seconds to learn the window)
6. Close the navigate & learn window

Tools -> Object repository Comparison Tool: This option is used to compare two different object repository files to view if any differences exist.
Steps to work with object repository comparison tool:
1. Ensure that the two individual object repository files are available
2. Select Tools -> Object repository Comparison Tool from object repository manager
3. Provide the path of the primary & secondary file
4. Click on OK

Tools -> Object Repository Merge Tool: This option is used to merge the contents of two object repository files into one. (Can’t merge more than two object repository files)
Steps to work with object repository merge tool:
1. Ensure that the two individual files are available
2. Select Tools -> Object repository merge tool
3. Select the path of the primary file
4. Select the path of the secondary file
5. Click on OK
6. Save the merged file.

-->Object Spy & Shared OR

Object Spy option is used to view the properties and the methods applicable to an object
Steps to work with Object Spy:
1. Ensure that the required object is available
2. Select Tools -> Object spy from option menu
3. Click on hand icon
4. Take the hand icon & click on required object or window
5. It displays the properties & the methods applicable to an object

Difference between Object Repository & Object Spy:
1. An Object repository (is similar to Database, but not DB)maintains only the unique information about the object. Where as Object spy displays all the properties of the object.
2. The contents of object repository are editable. Where as the contents of object spy are not editable.

Shared Object Repository:
It can be only created manually. It can’t be created by recording.
Steps to create Shared Object Repository:
1. Ensure that the required AUT is available
2. Select Resources -> Object Repository Manager
3. Select Object -> Add Objects
4. Take the hand icon
5. Click on the required object
6. Incase of parent object select the required objects to learn
7. Click on OK
8. Select File -> Save. (to save the Object repository file). The file will be saved with the extension of .tsr