QTP10.com is a new and completely free website that offers help in all the versions of HP QTP (including latest version 10). More importantly, it offers free code for users of HP QuickTest Professioal. This site helps you in learning the basics of QTP and descriptive/advanced programming in (QTP) on various environments like - .Net, Infragistics, Web, Windows, etc.

Note -
This blog is NOT affiliated with HP / Hewlett-Packard in any way. The data/questions come from various sources and we have our own testing questions. I am just another Software Tester like you.

Dictionary Object and QTP

A little introduction about Dictionary Object:

 

The Dictionary object is used to store information in name/value pairs (referred to as key and item). The Dictionary object might seem similar to Arrays, however, the Dictionary object is a more desirable solution to manipulate related data.

Comparing Dictionaries and Arrays:

  • Keys are used to identify the items in a Dictionary object
  • You do not have to call ReDim to change the size of the Dictionary object
  • When deleting an item from a Dictionary, the remaining items will automatically shift up
  • Dictionaries cannot be multidimensional, Arrays can
  • Dictionaries have more built-in functions than Arrays
  • Dictionaries work better than arrays on accessing random elements frequently
  • Dictionaries work better than arrays on locating items by their content

    Read more on..

Dictionary Object & QTP

As an alternative to using environment variables to share values between actions, you can use the Dictionary object. The Dictionary object enables you to assign values to variables that are accessible from all actions (local and external) called in the test in which the Dictionary object is created.

 

'In order to have IntelliSense for the Dictionary object, and have it recognized by other actions, it is added to the registry 
Dim WshShell
Set WshShell =CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\GlobalDictionary\ProgID", "Scripting.Dictionary","REG_SZ"
Set WshShell = Nothing

'
After updating the registry, you must close and reopen QuickTest Professional.
' ***********************************************************************************
'
Available methods
' -----------------------------
'
Exists
GlobalDictionary.Exists(<Key Name>) ' Returns True or False

'
Remove
GlobalDictionary.Remove(<Key Name>) ' Remove a specific key

'
RemoveAll
GlobalDictionary.RemoveAll ' Removes all keys

'
Add
GlobalDictionary.Add <Key Name>, <Value> ' Create a new key and assigns its value

'
Item
GlobalDictionary.Item(<Key Name>) ' Gets/Sets a key value



Sending Keyboard Input to an Application by QTP

The example below uses the PressKey method to send keyboard input to an application.

 

The PressKey method uses the ASCII value for the key.
63 is the ASCII value for F5.

ASCII values for other keys:
F1 - 59
F2 - 60
F3 - 61
F4 - 62
F5 - 63
F6 - 64
F7 - 65
F8 - 66
F9 - 67
F10 - 68
F11 - 87
F12 – 88

 

   1: 'An example that presses a key using DeviceReplay. 



   2:        Set obj = CreateObject("Mercury.DeviceReplay") 



   3:        Window("Notepad").Activate 



   4:        obj.PressKey 63 


Web application performance testing using QTP

QTP is a functional automated testing tools, and the page loading time or  response time of a web application should be a performance testing thing.But as a matter of fact, QTP can also get page load time statistics by some functions. Because QTP using a VBS script and VBS script is so powerful that it can call any windows of the COM components and objects. So the idea of getting page load time is very simple, that is, we want to use VBS for IE page and get statistics of the page load time.

Call external file and applications in QTP

There are various ways through with we can call files and applications in QTP. Below are the four very simple ways:

Method 1. Use "InvokeApplication" command - Invokes an executable application.

Note: In most situations, you should use a SystemUtil.Run statement to run applications or to open files in their default application.  The InvokeApplication statement is supported primarily for backward compatibility.

Example:
The following example uses the InvokeApplication function to open Internet Explorer.

InvokeApplication "E:\Program Files\Plus!\Microsoft Internet\IEXPLORE.EXE".

 

Method 2. The use of "SystemUtil.Run" command - Runs a file or application.

When specifying a non-executable file, the file opens in the associated application.

Note: A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test.

Tip: You can also use this method to perform operations on the specified file, similar to the usage of the Windows ShellExecute command.

 

You can directly run the windows applications by just giving the application name. No need to give complete path.

Example:

SystemUtil.Run “IEXPLORE.EXE”

 

Note – The difference between SystemUtil.Run and InvokeApplication is – In SystemUtil.Run No need to give complete path for windows shell applications. But in InvokeApplication you need to give path for each application.

 

Example -
Open a Text File in the Default Text Application (Notepad)

Sub CloseDescendentProcesses_Example()
'The following example uses the Run method to open a file named type.txt
'in the default text application (Notepad). It then types "happy days",
'saves the file using shortcut keys, and then closes the application.

SystemUtil.Run "C:\type.txt", "", "", ""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close

End Sub

 

Method 3. ExecuteFile function - Executing Externally-Defined Functions from Your QTP Test scripts.

 

If you decide not to associate a function library (any VBScript file) with a test, but do want to be able to call its functions, subroutines, and so forth from an action in your test or from another function library, you can do so by inserting an ExecuteFile statement in your action.

When you run your test, the ExecuteFile statement executes all global code in the function library making all definitions in the file available from the global scope of the action's script.

 

Note: You cannot debug a file that is called using an ExecuteFile statement, or any of the functions contained in the file. In addition, when debugging a test that contains an ExecuteFile statement, the execution marker may not be correctly displayed.

Tip: If you want to include the same ExecuteFile statement in every action you create, you can add the statement to an action template.

 

To execute an externally-defined function:

1. Create a VBScript file using standard VBScript syntax. For more information, see the Microsoft VBScript Language Reference (Help > QuickTest Professional Help > VBScript Reference > VBScript).
2. Store the file in any folder that you can access from the computer running your test.
3. Add an ExecuteFile statement to an action in your test using the following syntax:
ExecuteFile FileName

where FileName is the absolute or relative path of your VBScript file.

4. Use the functions, subroutines, and so forth, from the specified VBScript file as necessary in your action.

 

Method 4. The use of "WshShell.Exec" method - Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.

Remarks
The Exec method returns a WshScriptExec object, which provides status and error information about a script run with Exec along with access to the StdIn, StdOut, and StdErr channels. The Exec method allows the execution of command line applications only. The Exec method cannot be used to run remote scripts. Do not confuse the Exec method with the Execute method (of the WshRemote object).

Example
The following example demonstrates the basics of the Exec method.

[VBScript]
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("calc")

Do While oExec.Status = 0
     WScript.Sleep 100
Loop

WScript.Echo oExec.Status
[JScript]
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("calc");

while (oExec.Status == 0)
{
     WScript.Sleep(100);
}

WScript.Echo(oExec.Status);

QTP 10 Release Updates

New - QuickTest Professional 10.00 Release Update

The QuickTest Professional 10.00 Release Update (Patch QTP_00626) is a cumulative patch that updates your QuickTest installation with the latest files from a set of patches and hotfixes that have been released over QTP 10.
You can install the Release Update even if you have already installed one or more of the individual patches or hotfixes it contains.
http://support.openview.hp.com/selfsolve/document/FID/DOCUMENTUM_QTP_00626
A detailed description of each patch and hotfix can be found in the 'HP QTP 10 Release Update - Release Notes' file, available at:
http://update.external.hp.com/quicktest/10.0/QTP10RU_ReleaseNotes.html

 

 

New Web 2.0 Feature Pack for HP Functional Testing 10.0 – Available Now!

Modern Web 2.0 technologies are becoming very common and no enterprise testing tool available today addresses it very well. Customers need to be able to test these new Web 2.0 applications “out of the box” and be able to easily extend their existing tools to support future Web 2.0 development by end-users or partners.


The new Web 2.0 Feature Pack for HP Functional Testing (FT 10.0) is available in two versions from SSO. FT 10.0 and the Web 2.0 Feature Pack are also available as an integration to HP Quality Center on SaaS.


Web 2.0 Feature Pack with Pre-requisites: http://h20230.www2.hp.com/selfsolve/document/FID/DOCUMENTUM_QTPWEB_00044
(Select this file if you do not have both Microsoft Visual Studio 2008 SP1 and .NET Framework 3.5 SP1 installed on your computer.)


Web 2.0 Feature Pack without Pre-requisites:
http://h20230.www2.hp.com/selfsolve/document/FID/DOCUMENTUM_QTPWEB_00045
(Select this file if you already have both Microsoft Visual Studio 2008 SP1 and .NET Framework 3.5 SP1 installed on your computer.)


This new feature pack will enable FT 10.0 to become the market leader in terms of breadth of Web 2.0 support and ability to address key Web 2.0 challenges in two key ways:
1. “Out of the box” support for the most common Web 2.0 technologies, including:
- Silverlight 3.0 (the hot new Rich Internet Application technology  from Microsoft)
- Ajax (the following toolkits are the most commonly adopted):
i. ASP.NET AJAX (from Microsoft)

ii. GWT (from Google)

iii. YUI (from Yahoo)

iv. Dojo (open source)


Together with the Flex add-in available through HP’s partnership with Adobe, this new functionality will provide the most comprehensive “out of the box” support for Web 2.0 offered by any functional testing tool on the market.


2. New Extensibility Accelerator (EA) for Functional Testing to provide fast and easy FT add-in extensibility . The new EA has a wizard-like user interface which makes it easier and faster to extend any FT add-in to support any control that is not supported “out of the box”. This capability is achieved by automating some of the tasks in the process and opening up the architecture to allow adding any AJAX toolkit or custom controls of other technologies.

 
To see a demo about the Extensibility Accelerator click here:
http://www.youtube.com/watch?v=Dttt_P1D4EU

QTP Vs Selenium

An excellent article on QTP vs Selenium




A very informative article by Eddie : Click Here to read



Related Posts:
Selenium Tutorials
Selenium for Functional testing of web applications

How to face Interview Questions in QTP

Note – These are the General QTP Questions which are applicable to all QTP Versions.

Q. What are test objects?
Test objects are objects created and maintained by QTP in its object repository. Each test object has a name and a set of properties to uniquely identify the actual object in the application.


Q. how does QTP identifies the objects during the script run?
During script run QTP searches for a run-time object that has the similar description of the test object in the object repository.


Q. How can i check the properties of an object in an application without using checkpoints? For Example how will you check whether a button is enabled?
Answer: GetROProperty method is used to retrieve the properties of the object in an application.It is very useful method and can be used to retrieve almost any of the property that can be seen while spying the object with object spy. For Example‘To get whether button is enabled or not.

Val = Browser("QA Friends").Page("QA Friends"). WebButton("Login"). GetROProperty("disabled")

‘To get whether a checkbox is on or off.

Val =Browser("QA Friends").Page("QA Friends").WebCheckBox("Test").GetROProperty("Value")


Q. How can I modify the properties values of test objects in Object Repository during runtime?
A. You can use SetTOProperty method of test object.Object(description).SetTOProperty Property, Value - The values of test object properties are used to identify the objects. Sometimes the properties of the object in the application change dynamically. For example text of a link in a webpage is the username used to login to that page.Text property is used by test object to identify the link. So in order to identify the actual object we can manipulate the value of “text” property of link using SetTOProperty.

 

Q. How do you synchronize your scripts in QTP?
A. For waiting until navigation of web page completes we can use Sync method. For waiting until an object appears we can use Exist method. For waiting until a property of object changes we can use WaitProperty method. You can set browser navigation timeout in: Click Test > Settings menu Select web tab in Test Settings window. Enter the timeout in Browser Navigation Timeout text box. You can set global object synchronization timeout in: Click Test > Settings menu Select Run tab in Test Settings window. Enter the timeout in Object Synchronization Timeout text box.

 

Download the complete Document from here.

This is a .pdf file. Open this file in Adobe Acrobat Reader.

 

Related Posts:

QTP Interview Questions in IBM

QTP Interview Questions for Beginners - Part 1

QTP Interview Questions Set 1

QTP Interview Questions Set 2

QTP Interview Questions Set 3

QTP Interview Questions Set 4

QTP Interview Questions Set 5

QTP Interview Questions Set 6

QTP Interview Questions Set 7

QTP Interview Questions Set 8

QTP Interview Questions Set 9

QTP Interview Questions Set 10

QTP Interview Questions Set 11

QTP Interview Questions Set 12

Using Action Parameters in QTP

Action parameters enable you to transfer input values from your test to a top-level action, from a parent action to a nested action, or from an action to a sibling action that occurs later in the QuickTest Profession test. Action parameters also enable you to transfer output values from a step in an action to its parent action, or from a top-level action back to the script or application that ran (called) your test. For example, you can output a value from a step in a nested action and store it in an output action parameter, and then use that value as input in a later step in the calling parent action.

 

You can use action parameters in any step in your action (including function calls). You define the parameters that an action can receive and the output values that it can return in the Parameters tab of the Action Properties dialog box (Edit > Action > Action Properties or right-click an action and select Action Properties). You specify the actual values that are provided to these parameters and the locations in which the output values are stored using the Parameter Values tab in the Action Call Properties dialog box (opened by right-clicking an action and choosing Action Call Properties).

 

You can specify input parameters for an action so it can receive input values from elsewhere in the test. Input values for an action parameter can be retrieved from the test (for a top-level action), from the parameters of the parent action that calls it (for a nested action), or from the output of a previous action call (for a sibling action). You can also specify output parameters for an action, so that it can output values for use later in the test, or pass values back to the application that ran (called) the QTP test script.

For example, suppose you want to take a value from the external application that runs (calls) your test and use it in an action within your test. In the test below, you would need to pass the input test parameter from the external application through Action2 and Action3 to the required step in Action4.

 

Using Action Parameters 

 

You would do this as follows:

  1. Define the input test parameter (File > Settings > Parameters node) with the value that you want to use later in the test.

  2. Define an input action parameter for Action2 (Edit > Action > Action Properties > Parameters tab) with the same value type as the input test parameter.

  3. Parameterize the input action parameter value (Edit > Action > Action Call Properties > Parameter Values tab) using the input test parameter value you specified above.

  4. Define an input action parameter for Action3 (Edit > Action > Action Properties > Parameters tab) with the same value type as the input test parameter.

  5. Parameterize the input action parameter value.
    • Select Edit > Action > Action Call Properties > Parameter Values tab and select the input action parameter value you specified for Action2.

    • Use the Parameter utility object to specify the action parameter as the Parameters argument for the RunAction statement in the Expert View.

  6. Define an input action parameter for Action4 (Edit > Action > Action Properties > Parameters tab) with the same value type as the input test parameter.

  7. Parameterize the input action parameter value.
    • Select Edit > Action > Action Call Properties > Parameter Values tab and select the input action parameter value you specified for Action3.

    • Use the Parameter utility object to specify the action parameter as the Parameters argument for the RunAction statement in the Expert View.

  8. Parameterize the value in the required step in Action4.
    • Click the parameterization icon  and specify the parameter in the Value Configuration Options dialog box using the input action parameter you specified for Action 4.

    • Use the Parameter utility object in the Expert View to specify the value to use for the step.
    An action's parameters are stored with the action and are the same for all calls to that action. If you modify an action parameter's name, type, or description, and then view the action properties for a call to that same action in a different part of the test, you will see that the action parameter has changed.

 

The actual value specified for an input action parameter and the location specified for action output parameter can be different for each call to the action. When you insert a call to a copy of an action, the copy of the action is inserted with the action parameters and action call parameter values that were defined for the action you copied. When you split an action, the action parameters are copied to both actions. The action call values for the second action are taken from the default values of that action's parameters.

 

For information on defining action parameters and the values used in action calls, see Setting Action Parameters. For more information on working with action parameters, see Guidelines for Working with Action Parameters.

 

Go Back to: QTP Tutorial 8 - Working with Advanced Action Features in QTP

Specify Action's Input Parameters in QTP

You can specify input parameters for an action so that steps in the action can use values supplied from elsewhere in the test. Input values for an action parameter can be retrieved from the test (for a top-level action) or from the parameters of the parent action that calls it (for a nested action), or from the output of a previous action call (for a sibling action).

You can specify output parameters for an action, so that it can return values for use later in the test. For example, you can output a parameter value to a parent action so that a later nested action can use the value.

 

For each input or output action parameter, you define a name (case sensitive), a type, and optionally, a description. You can also specify a default value for each action input parameter, or you can use the default value that QTP provides for the parameter value type that you choose. The default value is saved with the action and is used by the action if a value is not defined for a parameter in the action call. You can define, modify, and delete input and output parameters in the Parameters tab of the Action Properties dialog box (Edit > Action > Action Properties or right-click an action and select Action Properties).

 

Action Parameters

 

To add a new input or output action parameter:

  1. Click the Add button above the Input parameters or Output parameters lists to add a new parameter to the appropriate list. A row for the new parameter is added to the relevant list.
  2. Click in the Name box and enter a name for the parameter. (Action parameter names are case sensitive.)
  3. Select the value type for the parameter in the Type box. You can select one of the following types:
    • String. A character string enclosed within a pair of quotation marks, for example, "New York". If you enter a value and do not include the quotation marks, QTP adds them automatically when the value is inserted in the script during the test run. The default value is an empty string.
    • Boolean. A true or false value. If you select a Boolean value type, you can click in the Default Value column and click the arrow to select a True or False value. The default value is True.
    • Date. A date string, for example, 3/2/2005. If you select a Date value type, you can click in the Default Value column and click the arrow to open a calendar from which you can select a date. The default value is today's date.
    • Number. Any number. The default value is 0.
    • Password. An encrypted password value. If you select a Password value type, the password characters are masked when you enter the password in the Default Value field. In the action, however, the value appears encrypted. The default value is an empty string, which also appears as an encrypted value in the actual action.
    • Any. A variant value type, which accepts any of the above value types. Note that if you select the Any value type, you must specify the value in the format that is required in the location where you intend to use the value. For example, if you intend to use the value later as a string, you must enclose it in quotation marks. When you specify a value of Any type, QTP checks whether it is a number. If the value is not a number, QTP automatically encloses it in quotation marks. If you are editing an existing value, QTP automatically encloses it in quotation marks if the previous value had quotation marks. The default value is an empty string.

  4. If you are defining an input action parameter, click in the Default Value box and enter a default value for the parameter. Alternatively, you can leave the default value provided by QTP for the parameter value type. The default value is required so that you can run the action without receiving parameter values from elsewhere in the test.
  5. (Optional) Click in the Description box and enter a description of the parameter, for example, the purpose of the parameter in the action. QTP displays this description together with the name of the parameter in any dialog box in which you can choose an action parameter, including the Output Options, Parameter Options, and Value Configuration Options dialog boxes.
  6. To modify an existing action parameter:
  7. Select the parameter you want to modify from the Input parameters or Output parameters list.
  8. Modify the values as necessary in the edit boxes of the parameter row.
  9. To delete an existing action parameter:
  10. Select the parameter you want to delete from the Input parameters or Output parameters list.
  11. Click the Delete button. The parameter is removed from the list.
  12. Note: When you delete an action parameter, make sure that you also delete any steps that use the action parameter.

     

    Go Back to: QTP Tutorial 8 - Working with Advanced Action Features in QTP

Inserting a Call to an Existing Action in QTP Scripts

You can insert a call to a reusable action that is stored in your current test (local action), or in any other test (external action). Inserting a call to an existing action is similar to linking to it. You can view the steps of the action in the action view, but you cannot modify them. The called action's local object repository (if it has one) is also read-only.

 

If the called external action has data in the Data Table, however, you can choose whether you want the data from the action's data sheet to be imported as a local, editable copy, or whether you want to use the (read-only) data from the original action. (Columns and data from the called action's global data sheet is always imported into the calling test as a local, editable copy.)

 

To modify a called, external action, you must open the test with which the action is stored and make your modifications there. The modifications apply to all tests that call that action. If you chose to use the original action's data when you call an external action, then changes to the original action's data are applied as well.

Tip: You can view the location of the original action in the General tab of the Action Properties dialog box.

To insert a call to an existing action:

  1. Select Insert > Call to Existing Action, right-click an action icon and select Insert Call to Existing Action, or right-click any step and select Action > Insert Call to Existing. The Select Action dialog box opens.

    Inserting a Call to an Existing Action
  2. Use the From test browse button to find the test that contains the action you want to call. The Action box displays all reusable actions in the test you selected.

    Note: You can enter a Quality Center folder or a relative path in the From test box.

    • If you enter a relative path, QuickTest Professional searches for the test in the folders listed in the Folders pane of the Options dialog box. For more information, Using Relative Paths in QuickTest. (Refer Last Section)

    • If you are working with the Resources and Dependencies model with Quality Center 10.00, specify an absolute Quality Center path.

  3. In the Action list, select the action you want to call. When you select an action, its type (Reusable Action) and description, if one exists, are displayed. This helps you identify the action you want to call. For more information on action descriptions, see Setting General Action Properties.

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

    Note: QuickTest Professional disables the Action list if the selected test does not contain any reusable or external actions.

  4. Decide where to insert the call to the action and select At the end of the test or After the current step.

    Note: If the currently selected step is a reusable action from another test, the call to the action is added automatically to the end of the test (the After the current step is disabled).

     

  5. Click OK. A call to the action is inserted into the test flow. You can move your action call to another location in your test by dragging it to the desired location.

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

  6. Go Back to: Call to Existing Actions.

     

    Go Back to: Tutorial 8 - Working with Advanced Action Features in QTP

 

Calls to Copies of Actions in QTP test scripts

When you insert a call to a copy of an action into a test, the original action is copied in its entirety, including checkpoints, parameterization, the corresponding action tab in the Data Table, plus any defined action parameters. If the test you are copying has objects in the local object repository, the copied action's local object repository is also copied together with the action.

 

The action is inserted into the test as an independent, non-reusable action (even if the original action was reusable). After the action is copied into your test, you can add to, delete from, or modify the action just as you would with any other non-reusable action. Any changes you make to this action after you insert it affect only this action, and changes you make to the original action do not affect the copied action.

 

To create a copy of an action and call the copy in your test:

  1. In your test, select Insert > Call to Copy of Action, right-click an action icon and select Insert Call to Copy of Action, or right-click any step and select Action > Insert Call to Copy. The Select Action dialog box opens.

    call to copy of actions
  2. Use the From test browse button to find the test containing the action you want to copy. The Action box displays all local actions (actions that are stored with the test you selected).

    Note: You can enter a Quality Center folder or a relative path in the From test box.

    • If you enter a relative path, QuickTest Professional searches for the test in the folders listed in the Folders pane of the Options dialog box. For more information, see Setting Folder Testing Options and Using Relative Paths in QuickTest. (Refer Last Section)

    • If you are working with the Resources and Dependencies model with Quality Center 10.00, specify an absolute Quality Center path.

  3. In the Action list, select the action you want to insert. When you select an action, its type (Non-reusable Action or Reusable Action) and description, if one exists, are displayed. This helps you identify the action you want to copy. For more information on action descriptions see Setting General Action Properties.

  4. If you want to modify the copied action's properties, select the Edit new action properties check box. If you select this option, the Action Properties dialog box is displayed when you click OK. You can then modify the action properties.

    Note: If you do not select this option, you can modify the action's properties later by right-clicking the action icon in the Keyword View and selecting Action Properties.

  5. Decide where to insert the call to the copy of the action and select At the end of the test or After the current step.

    Note: If the currently selected step is a reusable action from another test, the call to the copy of the action is added automatically to the end of the test (the After the current step option is disabled).

  6. Click OK. The action is inserted into the test as a call to an independent, non-reusable action. You can move your action call to another location in your test by dragging it to the desired location.

Go Back to: Call to Existing Actions.

 

Go Back to: Tutorial 8 - Working with Advanced Action Features in QTP 

Call Existing Actions in QTP Scripts

When you plan a suite of QuickTest Professional test scripts, you may realize that each test requires some identical activities, such as logging in. Rather than inserting all of the login steps three times in three separate tests and enhancing this part of the script (with checkpoints, parameterization, and programming statements) separately for each test, you can create an action that logs into a flight reservation system and store it with one test. After you are satisfied with the action you created, you can insert calls to the existing action into other tests.

You can insert calls to an existing action by inserting a call to a copy of the action, or by inserting a call to the original action.

For example, suppose you want to create the following three tests for the Mercury Tours site—booking a flight, modifying a reservation, and deleting a reservation. While planning your tests, you realize that for each test, you need to log in and log out of the site, giving a total of five actions for all three tests.

You would initially create three tests with five actions. Test 1 would contain two reusable actions (Logging In and Logging Out). These actions can later be called by Test 2 and Test 3.

Call Existing Actions in QTP 1

You would then finish creating Test 2 and Test 3 by inserting calls to the reusable actions you created in Test 1

Call Existing Actions in QTP 2

For more information, see:

Advanced Action Features in QTP - QTP Tutorial 8

You can divide your QTP Test Scrits into actions to streamline the process of testing your application. This section covers the advanced use of actions in your test. Using basic action-related features is described in Working with Actions.

This section includes:

    Section 1:
    About Working with Advanced Action Features:

Actions help divide your test into logical units, such as the main sections of a Web site, or specific activities that you perform in your application.

A test is comprised of calls to actions. When you create a new test, it contains a call to a single action. By creating tests that call multiple actions, you can design tests that are more modular and efficient.

You can pass information between actions in several ways. You can also specify input parameters for actions, so that steps in an action can use values supplied from elsewhere in the test. You can also output values from actions to be used in steps later in the test, or to be passed back to the application that ran the test. For more information, see Using Action Parameters.

Go Back to –> QTP Tutorial Learn QTP – Design QTP Scripts

QTP Interview Questions in IBM

 

Following are the Interview questions asked at IBM for an Automation Test Engineer position. One of our reader attended it and shared the questions with us.

 

1. Can I use recovery scenario without using recovery scenario wizard?


2. What is the actual difference in Text/Text Area checkpoint. (Explain in detail with proper example)


3. Code for reading the data of a particular cell from an external excel file using COM.


4. Can I use datatable of Action1 in the Action2.


5. Can I import a excel sheet in Action1 datatable? How?


6. How to use regular expression in DP. (I don't have any Object Repository in my test)


7. What are pros and cons of DP?

 

Readers – Give a try and Post your answers in comments.

Action Templates in QTP

If you want to include one or more statements in every new action in your test, you can create an action template. For example, if you always enter your name as the author of an action, you can add this comment line to your action template. An action template applies only to actions created on your computer.

 

To create an action template:

  1. Create a text file containing the comments, function calls, and other statements that you want to include in your action template. The text file must be in the structure and format used in the Expert View.

  2. Save the text file as ActionTemplate.mst in your <QTP Installation Folder>\dat folder. All new actions you create contain the script lines from the action template.

    Note: Only the file name ActionTemplate.mst is recognized as an action template.

Go Back to: Working with Actions in QTP 

Removing Actions from a Test Script in QTP

If an action is no longer needed in QTP Test Script, you can remove it from your test. If the action is stored with your test (reusable or non-reusable action) and is called only once in the test, then removing the action deletes it entirely. Alternatively, if the action is stored in another test (external action), or is called more than once in this test (reusable action), removing the action deletes the selected call to the action, without affecting the source action.

 

The following table illustrates what happens when you delete an action:

Delete Actions

 

Tips for Removing Action Calls and Deleting Actions

  • QTP provides several locations from which you can remove calls to actions:

    Resources pane. Use to simultaneously remove all calls to a specific action.

    • If you remove a reusable or non-reusable local action, QTP removes all calls to the action in this test and deletes the action in its entirety.

    • If you remove an external action, QTP removes all calls to the action from the test, but does not affect the source action in any way.

    Test Flow pane or the Keyword View. Use to remove specific calls to an action.

    • If a test contains multiple calls to a single reusable action, and you remove some—but not all—of the calls, QTP removes the calls to the action in the specified locations, but does not delete the action itself. This means that the action can continue to be called by this test and by other tests, as needed.

    • If you remove all calls to an action, the result is the same as removing the action from the Resources pane. For reusable and non-reusable actions, QTP removes all calls to the action in this test and deletes the action in its entirety. For external actions, QTP removes all calls to the action from the test, but does not affect the source action in any way.

  • When QTP deletes an action in its entirety, the corresponding action sheet is removed from the Data Table, but columns related to this action that are located in the Global sheet are not removed.

  • If you open a test containing a call to an action you removed, QTP informs you that the action is missing.

To remove a call to an action or delete an entire action:

  1. In the Resources pane, the Test Flow pane, or the Keyword View:
    • Right-click the action you want to remove and select Delete.

    • Select the action you want to remove and press the Delete key on your keyboard.

    • Select the action you want to remove and select Edit > Delete.

  2. Click Yes in the confirmation message box.

    Note: If an action stored in this test is called by other tests, deleting the action in this test may cause other tests to fail.

Go Back to: Working with Actions in QTP 

QTP Object Repository automation object model

Manipulate QTP Object Repositories Using the Object Repository Automation Objects and Methods.
Download the code sample (PDF Version).

Download the code sample (Text file Version).

The QTP Repository automation object model enables you to manipulate QTP shared object repositories and their contents from outside of QTP. The automation object model enables you to use a scripting tool to access QTP shared object repositories via automation.

Automation programs are especially useful for performing the same tasks multiple times or on multiple shared object repositories. You can write your automation programs in any language and development environment that supports automation. For example, you can use VBScript, JavaScript, Visual Basic, Visual C++, or Visual Studio.NET.

Just as you use the QTP object model to automate your QTP operations, you can use the objects and methods of the Object Repository automation object model to write programs that manipulate shared object repositories, instead of performing these operations manually using the Object Repository Manager. For example, you can add, remove, and rename objects; import from and export to XML; retrieve and copy objects; and so forth.

After you have retrieved an object, you can manipulate it using the methods and properties available for that test object class. For example, you can use the GetTOProperty or SetTOProperty methods to retrieve and modify its properties.

Note: You can use the Object Repository automation object model to manipulate shared object repositories saved in the file system. If you want to manipulate a shared object repository stored in Quality Center, you must download the shared object repository and save it to the file system, before using the Object Repository automation object model to manipulate it.

ObjectRepositoryUtil Object

Description: ObjectRepositoryUtil Object enables you to manipulate object repository files (shared and local) from outside of QTP.

Methods:
AddObject
- Adds the specified object to the object repository under the specified parent object.
You can use this method to add a copy of an object that you retrieved from a different object repository.

Tip: Before adding an object to the object repository, you can modify its description properties using the SetTOProperty method.

Syntax: object.AddObject (Object, Parent, [Name])


Convert
- Converts the specified object repository file (version 8.2.1 or earlier) to the current format.

You must convert object repository files from QuickTest Professional 8.2.1 or earlier to the current format before you can use them in QuickTest Professional 9.0 or later.

Note: You do not need to use the Load method to load the object repository before converting it.

Syntax: object.Convert (OldFile, NewFile)


CopyObject
- Creates a copy of the specified object in the object repository.
To copy an object from one object repository to another, first create a copy of the object using this method. Then load another object repository, and use the AddObject method to add the returned (copied) object to the other repository.

Syntax: object.CopyObject (Object)

ExportToXML
- Exports the specified object repository to the specified XML file.
- Only test objects are exported to the XML file. If your object repository contains checkpoint or output objects, they are not exported to the XML file.
- This method can be used only to export shared object repositories (*.tsr files). Local object repositories cannot be exported.
- The object repository you want to export must be in QuickTest version 9.0 or later format. If the object repository is in an earlier format, you can use the Convert method to convert it before exporting it.

Syntax: object.ExportToXML (SourceFile, TargetFile)


GetAllObjects
- Retrieves all objects under the specified parent object.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetAllObjects ([Parent])

GetAllObjectsBy
- Class Retrieves all objects of the specified class under the specified parent object.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetAllObjectsByClass (Class, [Parent])


GetChildren
- Retrieves all direct children of the specified parent object.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetChildren ([Parent])

GetChildrenByClass
- Retrieves all direct children of the specified class under a specified parent.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetChildrenByClass (Class, [Parent])


GetLogicalName
- Retrieves the name of the specified object.
Retrieves the name of the specified object.

Syntax: object.GetLogicalName (Object)

GetObject
- Retrieves the object according to the specified path.
This method is similar to the GetObjectByParent method, but it enables you to supply the entire object path (including the parent object information) as a string. This is useful when you do not have access to an object containing the parent.

If you do have access to the parent as an object (rather than a string), it is recommended to use the GetObjectByParent method for better performance.

Syntax: object.GetObject (ObjectPath)


GetObjectByParent
- Retrieves the object according to the specified parent object and object name.
This method is similar to the GetObject method, but enables you to supply an object for the parent argument (if available) rather than a string.

Supplying an object results in better performance.

Syntax: object.GetObjectByParent (Parent, Object)


ImportFromXML
- Imports the specified XML file to the specified object repository.
This method can be used only to import XML files into new shared object repositories (*.tsr files). It cannot be used with local object repositories.
Object repository XML files contain only test objects. They do not contain checkpoint or output objects.

Syntax: object.ImportFromXML (SourceFile, TargetFile)


Load
- Loads the specified object repository file.
You must load an object repository file before performing any other object repository automation steps.
All object repository automation steps in your script that follow a load statement, perform the operations on the loaded object repository file.
If your script contains more than one Load statement on the same RepositoryUtil object, the second Load statement effectively unloads the first repository.

To load more than one repository at once, create multiple RepositoryUtil objects and load the repositories using different objects.


Syntax: object.Load FileName

RemoveObject
- Removes the specified object from the object repository.
You can remove objects from an object repository if they are no longer needed. Removing unnecessary objects helps to simplify maintenance and improves object repository performance.

Syntax: object.RemoveObject Parent, Object

RenameObject
- Renames the specified object in the object repository.
You can rename an object to provide a more descriptive name, which makes it easier to read your test or component steps.

Syntax: object.RenameObject (Object, Name)


Save
- Saves any changes made while running an object repository automation script.
Saves any changes made while running an object repository automation script.

Syntax: object.Save


UpdateObject
- Updates the object repository with any changes made to the specified object.
You should call this method after any object change (for example, rename, copy, and so forth).

Syntax: object.UpdateObject Object

TOCollection Object
A collection of object repository objects, returned by methods of the ObjectRepositoryUtil object.

Example: Manipulate Object Repositories Using the Object Repository Automation Objects and Methods.
The following example retrieves an object repository's objects and properties, looks for specific test objects using several methods, and copies a test object to another object repository.

Download the code sample (PDF Version).

Download the code sample (Text file Version).


Rename QTP Actions

To rename an action in the Rename Action dialog box:

  1. In the Keyword View, select the call to the action you want to rename and select Edit > Action > Rename Action. In the Expert View, display the action that you want to rename and select Edit > Action > Rename Action. The Rename Action dialog box opens.

    Renaming Actions
  2. Enter a new name for the action in the New name box. Make sure that action name is unique within the test, does not begin or end with a space, does not exceed 1023 characters, and does not contain the following characters:  \ / : * ? " < > | % ' ! { }

  3. Click OK to save the change.

    Tip: You can also press Shift + F2 to open the Rename Action dialog box.

To rename an action in the Action Properties dialog box:

  1. In the Test Flow pane or in the Keyword View, right-click the action and select Action Properties. Alternatively, in the Keyword View or in the Expert View, select an action and select Edit > Action > Action Properties. The Action Properties dialog box opens.
    Renaming Actions2
  2. Enter a new action name in the Name box of the General tab. Each action name within a test must be unique. Make sure that action name is unique within the test, does not begin or end with a space, does not exceed 1023 characters, and does not contain the following characters:  \ / : * ? " < > | % ' ! { }
  3. Click OK to save the change.
  4. Go Back to: Working with Actions in QTP

Splitting Actions in QTP

You can split an action that is stored with your test into two sibling actions or into parent-child nested actions. When you split an action, the second action starts with the step that is selected when you perform the split action operation.

You cannot split an action, and the option is disabled when:

  • an external action is selected

  • the first step of an action is selected

  • you are working with a read-only test

  • recording a test

  • running a test

When you split an action in your test that uses a local object repository:

  • QTP makes a copy of the local object repository.

  • The two actions have identical local object repositories containing all of the objects that were in the original local object repository.

  • If you add objects to one of the split actions, the new objects are added only to the corresponding local object repository.

To split an action:

  1. Select the step before which you want the new (second) action to begin.

  2. Select Edit > Action > Split Action, click the Split Action button, or right-click the step and select Action > Split. The Split Action dialog box opens. Split Actions
  3. Select one of the following options:
    • Independent of each other. Splits the selected action into two sibling actions.

    • Nested (the second action is called by the first). Splits the selected action into a parent action whose last step calls the second, child action.

  4. If you want, modify the name and description of the two actions in the Name and Description boxes.

    Note: If a reusable action is called more than once in a test and you split the action into two independent actions, each call to the action within the test will be followed by a call to the new (reusable) action. If a reusable action is called from another test, however, splitting it may cause the calling test to fail.

  5. Go Back to: Working with Actions in QTP

    Nesting Actions in QTP

    Sometimes you may want to call an action from within an action. This is called nesting. By nesting actions, you can:

    • Maintain the modularity of your test.
    • Run one or more actions based on the results of a conditional statement.

    For example, suppose you have parameterized a step where a user selects one of three membership types as part of a registration process. When the user selects a membership type, the page that opens depends on the membership type selected in the previous page. You can create one action for each type of membership. Then you can use If statements to determine which membership type was selected in a particular iteration of the test and run the appropriate action for that selection.

    In the Keyword View, your test might look something like this:

     

    Nested Actions

     

    In the Expert View, your test might look something like this:

    Browser("Membership Preference").Page("Membership Preference").WebRadioGroup("MemType").Select DataTable("memtype", dtGlobalSheet)

    Mem_Type=Browser("Membership Preference").Page("Membership Preference").WebRadioGroup("MemType").GetROProperty ("value")

    If Mem_Type="paid" Then

           RunAction "Paid_Mem", oneIteration

    ElseIf Mem_Type = "free" Then

           RunAction "Free_Mem", oneIteration

    Else

           RunAction "Preferred", oneIteration

    End If

     

    To nest an action within an existing action:

    1. Highlight the step after which you would like to insert the call to the action.
    2. Follow the instructions for inserting a call to a new action as described in Creating New Actions.

    Go Back to: Working with Actions in QTP

    Associating Object Repositories with Actions

    You can associate object repositories with actions in several ways:

    • You can associate a single action with an object repository by right-clicking the action in the Resources pane and choosing Associate repository with action from the context menu. This opens the Open Shared Object Repository dialog box, enabling you to associate an object repository with the selected action.

    • You can use the Associated Repositories tab of the Action Properties dialog box to associate one or more object repositories with the current action. (Right-click an action in the Test Flow pane and select Action Properties, or select Edit > Action > Action Properties to open the Action Properties dialog box.)

    Associate Object Repositories to Actions

     

    Tip: You can associate shared object repositories with multiple actions simultaneously, using the Associate Repositories dialog box.

     

    QTP searches these files to locate test object descriptions when identifying objects in your application. You can associate object repositories that are saved in your file system or in a Quality Center project.

     

    Note: QTP uses associated object repositories from Quality Center project folders only when you are connected to the corresponding Quality Center project. If you are not connected to the relevant Quality Center project, all associated object repositories that are stored in your Quality Center project are listed as missing in the Missing Resources pane. (QTP always lists any associated object repository that cannot be found in the Missing Resources pane.)

     

    In addition, if an object repository cannot be found, QTP displays a warning message when you click the Associated Repositories tab in the Action Properties dialog box. QTP also adds a question mark to the missing object repository icon  to the left of the missing object repository in the Associated object repositories list.

    You can associate as many object repositories as needed with an action, and the same object repository can be associated with different actions as needed. You can also set the default object repositories to be associated with all new actions in all tests.

    The order of the object repositories in the list determines the order in which QTP searches for a test object description. If there are test objects in different object repositories with the same name, object class, and parent hierarchy, QTP uses the first one it finds based on the priority order defined in the Associated Repositories tab. The local object repository is always listed first and cannot be moved down the priority list or deleted.

     

    You can enter an associated object repository as a relative path. During the run session, QTP searches for the file in the folders listed in the Folders pane of the Options dialog box, in the order in which the folders are listed.

     

    Note: If you want other users or HP products to be able to run an action on other computers, and the action's associated object repositories are stored in the file system, you can set the file path as a relative path (click the path once to highlight it, and then click it again to enter edit mode). Any users who want to run this action should then specify the drive letter and folder in which QTP should search for the relative path in the Folders pane of the Options dialog box (Tools > Options> Folders node).


    Important: If you are working with the Resources and Dependencies model with Quality Center 10.00, you should store the action's associated object repositories in the Quality Center Test Resources module and specify an absolute Quality Center path in the Folders pane.

     

    You can add, delete and prioritize the object repositories associated with the action using the following buttons:

    Associate Object Repositories to Actions2

    Go Back to: Working with Actions in QTP

    Configuring Actions in QTP

    Setting Action Properties:

     

    The Action Properties dialog box enables you to define options for the stored action. These settings apply each time the action is called. You can modify an action name, add or modify an action description, and set an action as reusable or non-reusable. For an external action, you can set the Data Table definitions.

    The Action Properties dialog box also enables you to define input and output parameters to be used by the action, and specify the object repositories that are associated with the action. For more information, see Associating Object Repositories with Actions.

     

    Note: The following sections describe how to define action properties using the Action Properties dialog box. You can also define actions and action parameters in the Expert View.

     

    You can open the Action Properties dialog box while working with your test by:

    • Right-clicking an action node in the Test Flow pane and selecting Action Properties.
    • Choosing Edit > Action > Action Properties when an action node is highlighted in the Keyword View or displayed in the Expert View.
    • Right-clicking an action node in the Keyword View and selecting Action Properties.

    The Action Properties dialog box always contains the General tab, the Parameters tab, the Associated Repositories tab, and the Used By tab:

     

    QTP Action Properties

     

    Note: In addition to the tabs shown above, the Action Properties dialog box for a called external action also contains an External Action tab, and the other tabs are read-only.

     

    Setting General Action Properties

     

    You can use the General tab of the Action Properties dialog box to modify the name of an action, add or edit an action's description, or change the reusability status of the action.

     

    To open the Action Properties dialog box, right-click an action in the Test Flow pane and select Action Properties, or select Edit > Action > Action Properties.

     

    Note: The name of the action and its path are displayed in the tab. If it was defined with a relative path in QTP, then the path is displayed as .\<name of action>. If the action is a reusable action or an external action, then Reusable action or External Action is displayed next to the action name.

    The General tab includes the following options:

    Option

    Description

    Name

    The name of the action. By default, the action name is the internal name provided by QTP, such as Action 1. This number is incremented by 1 for each new action that is added to the test.

    You can rename the action, as needed. The action name must be unique (within the test), cannot begin or end with a space, cannot exceed 1023 characters, and cannot contain the following characters:   \ / : * ? " < > | % ' ! { }

    Location

    The folder or Quality Center path where the action is stored.

    Description

    You can insert comments about the action. An action description helps you and other testers know what a specific action does without reviewing all the steps in the action. The description is also displayed in the description area of the Select Action dialog box. This enables you and other testers to determine which action you want to call or copy from another test without having to open it.

     

    Note: You can also add a description when inserting a call to a new action.

    Reusable action

    Indicates whether the action is a reusable action. By default, this check box is selected. A reusable action can be called multiple times within a test and can be called from other tests. Non-reusable actions can be copied and inserted as independent actions, but cannot be inserted as calls to the original action.

    When you change this setting, the action icon changes to a non-reusable action icon or reusable action icon as appropriate. If the steps of the action were expanded, they collapse after changing a non-reusable action to a reusable action. You can view the steps of the reusable action by selecting the action name in the Test Flow pane.

     

    Notes:

  1. If the action is called more than once within the test flow or if the action is called by a reusable action, the Reusable action option is read-only. If you want to make the action non-reusable, remove the additional calls to the action from the test.
  2. You cannot expand reusable actions from the test flow view. You can view details of a reusable action by double-clicking the action in the Keyword View, or selecting the action from the Action List. For more information on the test flow and action views, see Using the Action Toolbar in the Keyword View.
  3.  

    Setting Properties for an External Action

    When you insert a call to an external action, you can choose where you want QTP to store the Data Table data. You can specify this in the External Action tab of the Action Properties dialog box.

    To open the Action Properties dialog box, right-click an action in the Test Flow pane and select Action Properties, or select Edit > Action > Action Properties.

     

    QTP Action Properties2

     

    The External Action tab includes the following options:

    Option

    Description

    Data Table parameters

    Indicates where to store the action's Data Table data:

    • To use the original action's data, select Use data stored with the original action (read-only). If you select this option, the data is read-only when viewed from the calling test, and all changes to the original action's data sheet apply when the action runs in the calling test.
    • To use an editable copy of the data in the test's Data Table, select Use a local, editable copy. If you select this option, a copy of the called action's data sheet is added to the calling test's Data Table and is independent of the original action.

    Changes to the original action's data sheet do not affect the calling test even if you insert another call to this action after the action's data sheet is modified.

    If the called action has parameterized steps that rely on new information in the original action's data sheet, enter the relevant column names and required data to the action sheet in the calling test manually.

    Note: When you call an external action, the global data sheet columns and data from the called action's test are always imported as a local, editable copy in the calling test's global data sheet.

    Changes to the original action's global data sheet do not affect the calling test even if you insert another call to this action after the called action's global data sheet is modified.

    If the called action has parameterized steps that rely on new information in the global data sheet, enter the relevant column names and required data to the calling test's global data sheet manually.

     

    Viewing a List of the Tests and Actions Using this Action

    If your tests are stored in Quality Center and are using the resources and dependencies model, the Action Properties dialog box displays the Used By tab. This enables you to view a list of the tests and actions that contain calls to this particular action. This is the same list that is displayed in the Dependencies tab of the Test Plan module in Quality Center.

     

    To open the Action Properties dialog box, right-click an action in the Test Flow pane and select Action Properties, or select Edit > Action > Action Properties.

    QTP Action Properties3

    The Used By tab includes the following options:

     

    Option

    Description

    Test

    Indicates the Quality Center path of the test containing a call to this action.

    Action

    Indicates the internal name of the action containing a call to this action. The internal name is the name that QTP applies to an action by default when the action is created, for example, Action 1. The internal name of the action calling this action is displayed even if the calling action was renamed.

     

    Go Back to: Working with Actions in QTP