Monday, March 10, 2008

QTP Action input output parameters Example 1

Action output value (value returned by a called action) can be stored in a 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:

s1=parameter("in_a1_1")
s2=parameter("in_a1_2")
parameter("out_a1_1")=s1+s2

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, var1
msgbox var1

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.