Monday, March 10, 2008

QTP Action input output parameters Example 3

Action output value (value returned by a called action) can be stored in environment variable.

Open a new test. By default, it will have Action1.

Go to Insert (Menu) -> Call to New Action, to add a new action at the end of the test.

Now we have Action1 and Action2 in this test.

In the Keyword View, right click on Action1 and choose Action Properties.

Go to Parameters tab and create input variable in_a1_1 with Type as Number. Rest everything be default.
(To create an input variable, you have to click on ‘+’ sign which is on the right hand side of Input parameters section).

Create another input variable in_a1_2, same as above.

In the Parameters tab, also create one output variable out_a1_1 with Type as Number
(To create an output variable, you have to click on ‘+’ sign which is on the right hand side of Output parameters section).

In the Expert view of Action1 type:


Go to File-> Settings, Environment tab, in the 'Variable type' dropdown choose User-defined. Click on the + sign which is on the right side.

‘Add New Environment Parameter’ window opens. Enter the Name of the parameter as env_var and let the 'Value' field be empty and click on Ok.

In the Expert view of Action2 type:
(When you copy this below code in Expert view of Action2, it may give you a warning that it will make Action1 reusable, just click on Ok)

RunAction "Action1", oneIteration, 2, 2, Environment ("env_var")
msgbox Environment ("env_var")

To Run this test make sure Action2 is selected / highlighted if you are in the Keyword View or Action2 is selected from the dropdown above if you are in the Expert View and then choose Automation (Menu) -> Run Current action.