-->Actions

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

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

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

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

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

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

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

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

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

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