Using Multiple Actions In QTP

Using Multiple Actions in a Test

When you create a test, 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.
For more information on creating and calling new actions, see Creating New Actions. For more information on inserting calls to existing actions, see Nesting Actions.
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, described in Nesting Actions). 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. For more information on the Test Results window, see Viewing Run Session Results.

Nesting Actions

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 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, or for inserting a call to a copy of an action or a call to an existing action as described in Inserting Calls to Existing Actions.

Post a Comment

Previous Post Next Post