Monday 6 January 2014

QTP Actions and Action Properties




Actions divide a test into logical units. This aids in highly readable tests and make sure that modularity is achieved.


Reusable – only these can be called multiple times within the same or different tests
Non-reusable – These cannot be called by any other actions
External actions – a reusable action when called from another action becomes an external action in the called action.
Steps to follow to perform different operation in Actions:

 Insert-->call to new action-->enter name of the action-->click OK.

Rename Actions:
Select desired action in action drop down box--> edit menu-->action-->rename action-->modify the name-->click OK.

Call an Action:
Insert-->call to existing action-->browse path of the test-->select desired action-->click OK.(Note: We cannot edit)

Copy an Action:
 Insert-->call to copy of action-->browse path of the test-->select desired action-->click OK.(Note: we can edit this action).

Select Non Reusable action -->edit -->action-->action properties-->check reusable action check box -->click OK.

Delete Actions:
Select desired action in action drop down box-->edit menu-->action-->delete action-->confirm deletion.
·         By default all new actions are reusable

·         Every action has its own “Action” datasheet or a local sheet

·         Call to an existing action in another test can be inserted by using the menu option: “Insert->Call to an existing action-> (Choose test/action)”
·         The statement or action call inserted in the current test will be as follows:

·         The action will be called as many times as the action called properties is specified for the parent action.

Example:
Action2 is a reusuable action in Test2. It is called on every iteration in the datatable of Test2.
Action1 is the action that calls Action2 in Test1.
Action1 runs only once.
Then, Action2 will run only once irrespective on how many times it was called in Test2.

·         A previously reusable action can be changed to become non-usable and vise versa.

·          When a previously reusable action is marked as non-reusable the test that calls the action fails and a warning message is displayed to the user.

a) Choose the action from the keyword view, right click and choose action properties.
b) While in the action in the expert view, select Edit->Action Properties from the menu.

·         The dialog box appears with General (name, description, reusable or not), Parameters(i/p or o/p), associated repositories (can associate another action’s OR) and Usedby tabs
The following are some of the ways in which you can utilize the output value of an action in your test depending on your requirement:

a) Action o/p value (value returned by a called action) can be stored in a variable.

RunAction “Action1”,OneIteration, i/pvalues, x, x being the variable
b) Action o/p value can be stored in an environment variable.
To create an environment variable choose “File->Settings->Environment tab” , in the ‘Variable Type’ drop down choose userdefined and click + and ‘Add new environment Parameter’ – enter the name (env_Var) and an empty value and click OK.

Though there are many built in functions available in the QTP for the tester, there might still be instances when you might want to perform a specific operation and make those steps reusable. by creating user defined functions, put them in a separate file, associate it with the test and have the function name work as a keyword for that particular test.

So by definition, a function is nothing but a piece of code that performs a certain task.
Use the menu option “File->New->Function Library” or “Shift+Alt+N” or click on the “New” drop down option in the menu and choose “Function library”
QTP will open up an editor, very similar to the keyword view of a test. Here you can write your code. I am going to include statements that will login a user into gmail.com page.

QTP Functions
Once you are done writing the code, “Save” the function library by choosing the required name and location on your computer.
Note – A function library does not get auto included in any of your tests. You are going to have to do it explicitly.
The following are the steps to associate a function library into your test:
·         Open your test or create a new test

·         Depending on the settings you have on your IDE you might have the resources pane already available to you. If not choose the menu option “View->Resources” and this displays the pane.

·         Right click on the “Associate Function libraries”, click the “Associate Function library” option and choose the library file you created earlier.

QTP Functions

·         There will be a message that asks for the tester’s confirmation before converting the path to a relative path. This is done to make sure that the test does not fail if the files are moved as long as the same hierarchy is followed. Click yes on this dialog box:


·          It will appear under this node from now and that is how you verify if your association has worked or not.

·         Once you have associated the library make sure you save your test.

From now on if there is a statement in my test that is as follows, it will invoke the function in the library and execute the steps in there.
You can have more than one function in your library files and you can have more than one library files associated to your test.

No comments:

Post a Comment