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.

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

    Create Actions in QTP - Step by Step Tutorial

    You can create new actions and add calls to them, as needed.

    You can call the new action from your test flow as a top-level action, or you can call the new action from within another action in your test as a sub-action (or nested action).

     

    You can also split an existing action into two actions.

     

    To create a new action in your test:

    1. If you want to insert a call to the new action from an existing action in your test, click the step after which you want to insert the new action. To insert a call to the new action from the test flow as a top-level action, click any step.

    2. Select Insert > Call to New Action or click the Insert Call to New Action button on the Insert toolbar. The Insert Call to New Action dialog box opens.Create Actions             
    3. In the Name box, type a new action name or accept the default name. If you rename the action, make sure that the action name is unique (within the test), does not exceed 1023 characters, does not begin or end with a space, and does not contain the following characters:  \ / : * ? " < > | % ' ! { }

    4. In the Description box, add a description of the action. You can also add an action description at a later time using the Action Properties dialog box.

      Tip: Descriptions of actions are displayed in the Select Action dialog box. The description makes it easier for you to choose an existing action you want to call.

    5. Ensure Reusable Action is selected if you want to be able to call the action from other tests or multiple times from within this test. By default, this option is selected. You can also set or modify this setting at a later time using the Action Properties dialog box.

       

    6. Decide where to insert the call to the action by selecting At the end of the test or After the current step. Choosing At the end of the test creates a call from the test flow to a top-level action. Choosing After the current step inserts the call to the action from within the current action (nests the action).

      Note: If the currently selected step is a reusable action from another test, the new action is added automatically to the end of the test (the location options are disabled).

       

       

    7. Click OK. A new action is stored with your test and the call to it is displayed at the bottom of the test or after the current step. You can move your action call to another location at a parallel (sibling) level within your test by dragging it to the desired location. For more information on moving actions, see Using the Test Flow Pane.

    8. If you inserted the call to the new action while editing your test, make sure your new action is selected before adding steps to it.

    Go Back to: Working with Actions in QTP 

    Smart script creation with QTP's Action Toolbar in the Keyword View

    The Action toolbar contains options that enable you to view the top-level actions in the test flow or to view any action stored with your test (whether or not the action is actually called in the test). The Action toolbar is automatically displayed above the Keyword View when a reusable or external action is included in test.

     

    Tip: You can display or hide the Action toolbar in the Keyword View by choosing View > Toolbars > Action.

    In the Expert View, the Action List is always visible and the Expert View always displays the steps for the selected action.

    The Action List enables you to view either the test flow (the calls to the top-level actions in the test) or you can view the steps for a selected reusable or external action. Selecting Test Flow in the Action List displays the overall flow of your test with all the calls to the top-level actions in your test. The test flow also enables you to view and edit the individual steps of non-reusable actions. An action view displays all the details of the selected reusable or external action.

     

    Actions Toolbar in QTP

     

    In the test flow, reusable actions are not expandable. You can view the expanded steps of a reusable action by selecting the action from the Action List.

     

    There are several ways to open the action view for a reusable or external action in the Keyword View:

    • In the Test Flow pane, double-click the action you want to view.
    • Use the Action toolbar to display the top-level Test Flow and then double-click the call to the action you want to view.
    • Use the Action toolbar to display the top-level Test Flow and then highlight the call to the action you want to view and click the Show button.
    • Select the name of the action from the Action List.

    You may have actions that are stored with your test, but are not currently called from your test. (They may be called by other tests, and you can insert calls to these actions from within your test, if needed).

     

    Actions that are not called in your test are not displayed in the Test Flow pane, but they are displayed in the Action List. You can select these actions to view or edit their contents.

     

    If an action is stored with your test but is not called by the test, and you are sure that you do not need the action for this test or any other test, you can delete the action from the test.

     

    Go Back to: Working with Actions in QTP

    Test Flow pane in QTP

    The Test Flow pane uses the following icons to indicate the different types of item in the hierarchy:

     

    TEST Flow pane in QTP

     

    Tips:

  4. You can right-click in the Test Flow pane title bar to view available display options and decide how to display the Test Flow pane. For example, you can auto hide the pane, dock it, or close it.

  5. You can click the Test Flow Pane toolbar button to hide or show the Test Flow pane view.
  6.  

    Working with Actions in Test Flow Pane

    You can perform the following operations in the Test Flow pane:

    • Display an action in the Keyword View and Expert View. Double-click an action in the Test Flow pane to show only that action in the Keyword View and Expert View.
    • View or hide the sub-nodes in the test. Right-click the Test node in the tree and select Expand All or Collapse All to view or hide the sub-nodes in the tree. You can also select the Test node and press + or * on the keyboard to expand all the nodes in the test, and - to collapse the nodes.
    • Display the test properties. Right-click the Test node in the tree and then select Settings to display the Test Settings dialog box. Details of the test and its path are displayed.
    • View or hide the sub-nodes of an action. Right-click an action in the tree and then select Expand Sub Tree or Collapse Sub Tree to view or hide the sub-nodes in the action. You can also select a sub-node and press + or * on the keyboard to expand the node and - to collapse the node.
    • Display the action properties. Right-click an action in the tree and then select Action Properties to display the Action Properties dialog box. The name of the action and its path are displayed.
    • Display the action call properties. Right-click an action in the tree and then select Action Call Properties to display the Action Call Properties dialog box.
    • Work with the Object Repository. Right-click an action in the tree and then select Object Repository to open the Object Repository window, which displays a tree containing all objects in the current test.
    • Manage Actions. Right-click an action in the tree and then select Copy or Delete.
      • Select Copy to open the Select Action dialog box and create a copy of the action in your test.
      • Select Delete to remove the action from your test.

    • Run the test. Right-click an action in the tree and then select Run from Action or Run to Action to start a run session from the beginning of the selected action, or to run the test until the beginning of the selected action and then pause the run session.
    • Debug your test. Right-click an action in the tree and then select Debug from Action to begin (and pause) a debug session at the beginning of the selected action.
    • Change the run order of actions. You can perform either of the following steps to move a top-level action (a direct child of the test) in the Test Flow Pane tree, and change the run order of the test accordingly. The action and any sub-actions are moved.
      • Right-click a top-level action in the tree and then select Move Up or Move Down. You can also press Ctrl+Up arrow or Ctrl+Down arrow to move an action and its sub-actions.
      • Drag a top-level action in the tree up or down to the required location. When you drag a selected action, a line is displayed, enabling you to see the location in the tree to which the action will be moved. You can only drag top-level actions. Selecting the parent action automatically includes all its sub-actions. You cannot drag a sub-action, nor can you drag a parent action together with only some of its sub-actions.
      •  

        If a test contains a call to an action that does not exist or cannot be found, the action still appears in the tree in the Test Flow pane, and QTP lists the action in the Missing Resources pane.

      Go Back to: Working with Actions in QTP

    Using Global and Action Data Sheets in QTP

     

    When you output a value to the Data Table or add a Data Table parameter to your test, you can specify whether to store the data in the Global data sheet or in the action data sheet.

    • Choosing Global sheet enables you to create a new column or select an existing column in the Global sheet in the Data Table. When you run your test, QTP inserts or outputs a value from or to the current row of the Global data sheet during each global iteration. You can use the columns in the Global data sheet for Data Table output values or Data Table parameters in any action. This enables you to pass information between actions.
    • Each action also has its own sheet in the Data Table so that you can insert data that applies only to that action. Choosing Current action sheet (local) enables you to create a new column or select an existing column in the corresponding action sheet in the Data Table. Note that the name of the action sheet is the same as the name of the relevant action. When you run your test, QTP inserts or outputs a value from or to the current row of the current action (local) data sheet during each action iteration.

    When there are parameters or output value steps in the current action's sheet, you can set QTP to run one or more iterations on that action before continuing with the current global iteration of the test. When you set your action call properties to run iterations on all rows, QTP inserts the next value from or to the corresponding action parameter or output value during each action iteration, while the values of the global parameters stay constant.

     

    Note: If you create Data Table parameters or output value steps in your action and select to use the Current action sheet (local) option, be sure that the run settings for your action are set correctly in the Run tab of the Action Call Properties dialog box. You can set your action to run without iterations, to run iterations on all rows in the action's data sheet, or to run iterations only on the rows you specify.

     

    For example, suppose you want to test how a flight reservation system handles multiple bookings. You may want to parameterize the test to check how your site responds to multiple sets of customer flight itineraries. When you plan your test, you plan the following procedures:

    1. The travel agent logs into the flight reservation system.
    2. The travel agent books five sets of customer flight itineraries.
    3. The travel agent logs out of the flight reservation site.

    When you consider these procedures, you realize that it is necessary to parameterize only the second step—the travel agent logs into the flight reservation system only once, at the beginning, and logs out of the system only once, at the end. Therefore, it is not necessary to parameterize the login and logout procedures in your test.

     

    By creating three separate actions within your test—one for logging in, another for booking a flight, and a third for logging out—you can parameterize the second action in your test without parameterizing the others.

     

    Go Back to: Working with Actions in QTP

    Insert Multiple Actions in a QTP Script

    When you create a QTP Script, it includes one action. All the steps you add and all the modifications you make while editing your test are part of a single action.

    You can divide your test into multiple actions by creating new actions and inserting calls to them, by inserting calls to existing actions, or by splitting existing actions. The actions used in the test, and the order in which they are run, are displayed in the Test Flow pane.

    There are three kinds of actions:

    • Reusable action. An action that can be called multiple times by the test with which it is stored (the local test), as well as by other tests.

    • Non-reusable action. An action that can be called only in the test with which it is stored, and can be called only once.

    • External action. A reusable action stored with another test. External actions are read-only in the calling test, but you can choose to use a local, editable copy of the Data Table information for the external action. By default, new actions are reusable. You can mark each action you create in a test as reusable or non-reusable. Only reusable actions can be called multiple times from the current test or from another test. You can store a copy of a non-reusable action with your test and then insert a call to the copy, but you cannot directly insert a call to a non-reusable action saved with another test. Inserting calls to reusable actions makes it easier to maintain your tests, because when an object or procedure in your application changes, it needs to be updated only one time, in the original action.
      Two or more tests can call the same action and one action can call another action (this is known as nesting an action). Complex tests may have many actions and may share actions with other tests.

     

    When you run a test with multiple actions, the test results are divided by actions within each test iteration so that you can see the outcome of each action, and you can view the detailed results for each action individually.

     

    Go Back to: Working with Actions in QTP

    Introduction to QTP Actions

    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 comprises 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.

    An action consists of its own test script, including all of the steps in that action, and any objects in its local object repository.

     

    Each action is stored together with the test in which you created it. You can insert a call to an action that is stored with the test and, depending on the properties of the action, you may also be able to call an action stored with another test.

     

    When you open a test, you can choose to view the test flow (calls to actions) or you can view and edit the individual actions stored with your test.

     

    If you work with tests that include many steps or lines of script, it is recommended that you use actions to divide your test steps. Actions should ideally contain no more than a few dozen test steps.

     

    For example, suppose you want to test several features of a flight reservation system. You plan several tests to test various business processes, but each one requires the same login and logout steps. You can create one action that contains the steps required for the login process, another for the logout steps, and other actions for the main steps in your test. After you create the login and logout actions, you can insert those actions into other tests.

    If you create a test in which you log into the system, book one flight, and then log out of the system, your test might be structured as shown—one test calling three separate actions:

     

    Actions in QTP

     

    Actions enable you to parameterize and iterate over specific elements of a test. They can also make it easier to modify steps in one action when part of your application changes.

     

    For every action called in your test, QTP creates a corresponding action sheet in the Data Table so that you can enter Data Table parameters that are specific to that action only.

     

    Go Back to: Working with Actions in QTP