What is Actions?
Types of Actions in QTP?
What is the Difference Between Actions & Functions?
Re Usable Actions:
In this tutorial we will see how to use more than one action in a test and how to call one action from another with in the same test.
Open a blank test. By default it will have Action1 in it (make sure you are in
the keyboard view).
Make sure that Action1 is selected/highlighted and click on the Expert View tab.
In the Expert View type:
msgbox ("my action 1")
Again when you go to keyword View and expand Action1 it will show you function call under it.
In that keyword View itself go to Insert (Menu) ->Call to New Action. 'Insert Call to New Action' Dialog box opens with Action2 as a default name of a new action. By default it will be added at the end of the test as this radio button is selected in the location area.
Click ok.
It will add Action2 to your test.
Make sure that Action2 is selected and click on the Expert View tab.
In the Expert View type:
msgbox ("my action 2")
Similarly insert a third Action.
After third action is added, select Action1(keyword view), right click on it and choose 'Action Properties'.
In the Action properties window that opens, check the 'Reusable action' checkbox at the bottom.
Click ok.
Now again highlight Action3 right click on it and choose 'Insert Call to Existing action'.
'Select action' dialog box appears. In this dialog box in the 'action' dropdown box it will have Action1 by default since we made only that action as reusable.
Just click ok.
In the keyword View where you can see all the three actions, make sure against Action3 it shows "Call to Action1 action" under Documentation.
Run the test. Three message boxes appear in succession showing 'my action 1', 'my action 2', and again 'my action 1'.
Types of Actions in QTP?
What is the Difference Between Actions & Functions?
Re Usable Actions:
In this tutorial we will see how to use more than one action in a test and how to call one action from another with in the same test.
Open a blank test. By default it will have Action1 in it (make sure you are in
the keyboard view).
Make sure that Action1 is selected/highlighted and click on the Expert View tab.
In the Expert View type:
msgbox ("my action 1")
Again when you go to keyword View and expand Action1 it will show you function call under it.
In that keyword View itself go to Insert (Menu) ->Call to New Action. 'Insert Call to New Action' Dialog box opens with Action2 as a default name of a new action. By default it will be added at the end of the test as this radio button is selected in the location area.
Click ok.
It will add Action2 to your test.
Make sure that Action2 is selected and click on the Expert View tab.
In the Expert View type:
msgbox ("my action 2")
Similarly insert a third Action.
After third action is added, select Action1(keyword view), right click on it and choose 'Action Properties'.
In the Action properties window that opens, check the 'Reusable action' checkbox at the bottom.
Click ok.
Now again highlight Action3 right click on it and choose 'Insert Call to Existing action'.
'Select action' dialog box appears. In this dialog box in the 'action' dropdown box it will have Action1 by default since we made only that action as reusable.
Just click ok.
In the keyword View where you can see all the three actions, make sure against Action3 it shows "Call to Action1 action" under Documentation.
Run the test. Three message boxes appear in succession showing 'my action 1', 'my action 2', and again 'my action 1'.
Q. The Difference between Actions and Functions in QTP?
Actions | Functions |
1. Actions are designed by QTP. Action is a collection of VB statements in QTP. It does not return any values. 2. We can call functions within actions. 3. Actions are saved into QTP with ".mts" extension. We can use Action with QTP only. 4. Action can have a object repository associated with it automatically when record the script. 5. Actions can be called by sytax: RunAction “ActionName”, oneIteration 6. Action is internal with QTP; Action can have more than one output parameters. 7. Every Action will have its own Datatable. 8. Actions we can use with Or without Reusable 9. Action Parameter have default Values. 10. Action parameter type is ByValue only. 11. Reusable Actions can return multiple values directly through Output Parameters (ie., directly through a value into different variables). 14. Action can be called for multiple iterations. 15. Action can have associated DataTable, Object Repository, Active Screen, Input/Output Parameters and return values. | 1. Functions are designed by Microsoft as part of VB Script feature. Functions are generic & collection of VB statements in QTP. It returns single value. 2. We can't call actions within functions. 3. Generally functions are saved with ".vbs" extension. We can use functions anywhere. (i.e, store outside & associate to the QTP test) 4. If a function creates in the .vbs file have does not associate object repository automatically. 5. Function can be call by syntax: Call Function_Name 6. A function is just lines of code, with Or without parameters and a single return value. 7. Whereas function does not have any Datatable. 8. Whereas functions are always reusable. 9. Whereas VB script function does not have any default values. 10. Whereas VB script functions can be passed ByVal and ByRef also. Functions can return multiple values through arrays (i.e, ByRef) 11. Whereas function can return only single value. 14. Function we need to write a loop structure to execute it multiple times. 15. Whereas function do not have these features. Functions on the other hand can only have input/output parameters (using ByVal or ByRef) and return values. |
Difference between Actions & Functions in Real Time:
Actions | Functions |
Passing Data: Actions - can only accept primitive data types as parameters (strings, integers, etc) Resource Usage: Actions - For each action, there’s a folder, three separate .vbs files, a local Object Repository, a subfolder containing snapshots, an Excel spreadsheet, and a few seconds of load time. API: Actions - You cannot insert calls to Existing Actions through the QTP API, you can only do it through the interface. Return Values: Actions - Return values are difficult to understand and read in the syntax. 1. When we reuse an action, we get all the resources like source code, data table contents & object 2. When the source action is modified, the target script will get affected in case of ‘Call to Existing’ & it will not get affected in case of ‘Call to Copy’. 3. If we have to reuse a code without any modification along with the object repository, then we use ‘Call to Existing’. And if we want to reuse with modification, then we use ‘Call to Copy’. 4. In the case of call copy of action it won’t reflect into the child action to parent action. 5. Most of the time actions contain the QTP script. i.e, the GUI objects, methods & properties, etc. | Passing Data: Functions - can accept arrays, dictionary objects and test Objects (i.e. Pages, Frames, WebRadioGroups, etc.) Resource Usage: Functions - There’s the code contained in the Function, and That’s all. API: Functions - You can attach Function Libraries to Test Scripts through the QTP API. Return Values: Functions - Return values work like they do in other languages (i.e. as lvalues). 1. When we reuse a function, we can reuse only the source code & not the data table contents or object repository. 2. When the source function is modified the target script will have the impact. 3. When we want to just reuse a code without any modification, then we can go for functions. 4. In the functions it will reflect into the child action to parent action. 5. Most of the time functions contain the VB script code like conditional & control statements, file system objects, etc. |
Guidelines for Working with Actions in QTP (QuickTest Professional)
1. If your action runs more than one iteration, the action must end at the same point in your application as it started, so that it can run another iteration without interruption. For example, suppose you are testing a sample flight reservation site. If the action starts with a blank flight reservation form, it should conclude with a blank flight reservation form.
2. A single test may include both global Data Table parameters and action (local) Data Table parameters. For example, you can create a test in which a travel agent logs into the flight reservation system, books three flights, and logs out; the next travel agent logs into the flight reservation system, books three flights, logs out, and so forth.
To parameterize the `book a flight' action, you choose Current action sheet (local) in the parameterization dialog box and enter the three flights into the relevant Action tab in the Data Table. To parameterize the entire test, you choose Global in the parameterization dialog box and enter the login names and passwords for the different agents into the Global tab in the Data Table.
Your entire test will run one time for each row in the Global data sheet. Within each test, each parameterized action will be repeated depending on the number of rows in its data sheet and according to the run settings selected in the Run tab of the Action Properties dialog box.
3. You may want to rename the actions in your test with descriptive names to help you identify them. It is also a good idea to add detailed action descriptions. This facilitates inserting actions from one test to another. You can rename an action by choosing Edit > Action > Rename Action. (Make sure you follow the naming conventions for actions.)
4. If you plan to use an identical or virtually identical procedure in more than one test, you should consider inserting a call to an action from another test.
- If you want to make slight modifications to the action in only one test, you should use the Insert Call to Copy of Action option to create a copy of the action.
- If you want modifications to affect all tests containing the action, you should use the Insert Call to Existing Action option to insert a link to the action from the original test.
- If you want modifications to the action to affect all tests containing the action, but you want to edit data in a specific test's Data Table, use the Insert Call to Existing Action option and, in the External tab of the Action Properties dialog box, select Use a local, editable copy.
5. When you insert a call to an external action, the action is inserted in read-only format, so the Record button is disabled. If you want to continue recording, you first need to insert a call to a local action into your test, or select a step from a local action that already exists in your test.
6. Reusable actions help you to maintain your tests, but it is important to consider the effects of making an action reusable. Once you make an action reusable, be sure to consider how changes to that action could potentially affect other tests that call that action.
7. If you expect other users to open your tests and all actions in your tests are stored in the same drive, you should use relative paths for your reusable actions so that other users will be able to open your tests even if they have mapped their network drives differently.
8. If you expect certain elements of your application to change regularly, it is a good idea to divide the steps related to changeable elements into a separate action so that it will be easy to change the required steps, if necessary, after the application is modified.
9. If you decide to remove an action, consider how that might affect your test or another test that contains a call to that action. For example, will it prevent a later action in the same test from running correctly? Will it cause the test containing a call to that action to fail?
No comments
Post a Comment