Thursday 24 September 2015

Actions in QTP


QTP Action is a placeholder or a component in which you can write your scripts or code. You can write your code in QTP actions in the same way you do in a function library or scripted business component. Actions help divide your test into "logical units" or "Business Processes". Actions help to create a script which is more modular and efficient. When a script is newly created it consists of only one action. But you can add more Actions to your QTP Script as per requirements.  In fact, a QTP test script is itself a collection of one or more actions.
There are four types of Actions
  • External Actions
  • Internal Actions
  • Reusable actions
  • Non Reusable actions

Reusable Actions: The actions that can be used in other Tests are called as reusable actions. They can also be used in the same Test Script multiple times.
Non-Reusable Actions: The actions which can not be used in other Tests are called as Non-Reusable . They can be called in the same script only once.
External Actions: A reusable action stored with another test is called External actions. These 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.
Internal Actions: With reference to a QTP test case, an internal action is one that is stored within that test case. This action can be reusable as well as non-reusable depends upon the requirement.

At times, if an action becomes big, its a nice practise to split it. You can split an existing action in two ways
  • Independent Actions
  • Nested Actions

Independent Actions:  These actions are independent of each other which splits the selected action into two sibling actions
Nested Action: These are the actions which splits the selected action into a parent action whose last step calls the second, child action

Actions can access test-data stored in datasheets. QTP provides 2 type of datasheets 
  • GLOBAL Datasheet: It is Unique for the entire test. Any Action can access and write data into Global Datasheet. Sheet is named "GLOBAL"
  • LOCAL Datasheet: Equal to number of Actions in the sheet. An Action can read and write data into its own local Datasheet only. Sheet name =  "ACTION NAME". 
The entire purpose of creating Actions is to use them in other Test Scripts. There are two methods to import Actions into a Test
  • Call to COPY of an Action: When you make a Copy of an Action , the action is copied in its entirety, including checkpoints, parameterization, and the corresponding action tab in the Data Table into the calling test . When you insert a copy of an existing action, you can make changes to the copied action, and your changes will not affect nor be affected by any other test. You can insert copies of both reusable and non-reusable actions
  • Call to an EXISTING Action: Calls to actions are read-only in the calling test. They can only be modified in the test in which they were created. It enables you to use the same action in several tests and makes it easy to maintain tests. You can  make  calls to only "Reusable" actions.
Just like functions or methods in programming languages you can also create input and output parameters for an action. This parameter has no relation with Test Data Parameterization
If required you can use the following statement to exit an Action

  • ExitAction.
  • ExitActionIteration
  • ExitRun
  • ExitGlobalIteration


No comments:

Post a Comment