Tuesday, 18 November 2014

QTP Action input output parameters

QTP Action input output parameters

Those who are still confused about input parameters to actions and output values from actions, just have a look at these examples, these act as a foundation for action input and output values (this is ONE of the many ways, of course there can be other ways of doing the things I have done below).

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

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, var1msgbox 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.

2) Action output value (value returned by a called action) can be stored in data table column.

QTP Action input output parameters Example 2
Action output value (value returned by a called action) can be stored in data table column.
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, DataTable("Action1_out",dtGlobalSheet)
In the Global Data Sheet, where you have column names as A, B and so on, double click on A,
It will open Change Parameter Name box,
Enter the parameter name as Action1_out and click Ok.
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.

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

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:
s1=parameter("in_a1_1")s2=parameter("in_a1_2")parameter("out_a1_1")=s1+s2
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.

4) Action output value (value returned by a called action) can be stored in Any variable and RunAction Statement is not used.

QTP Action input output parameters Example 4
Action output value (value returned by a called action) can be stored in Any variable and RunAction Statement is not used.
Open a new test. By default it will have Action1.
Go to Insert-> 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 output variable out_a1_1 with Type as Any.
In the Keyword View, right click on Action2 and choose Action Properties.
Go to Parameters tab and create input variable in_a2_1 with Type as Any.
In the Keyword View, right click on Action1 and choose Action Call Properties.
Go to Parameters tab and in the ‘Store In’ column enter var1.
In the Keyword View, right click on Action2 and choose Action Call Properties.
Go to Parameters tab and in the Value column enter var1.

In the expert view of Action1 type:
Parameter("out_a1_1") = 23
In the expert view of Action2 type:
msgbox Parameter(" in_a2_1")
5) Working with Four Actions
QTP Action input output parameters Example 5
To Run this test, always go to Action4 and then, Automation (Menu) ->Run Current Action
What these Actions will do:
Action4 will call Action1 with two input values 2, 2.
Action1 sums those values (2+2=4) and assigns the sum to out_a1_1 (Action1’s output parameter).
Then Action1 passes the sum (i.e. 4) along with another number (3) to Action2 by calling Action2 in its last line.
Action2 multiplies those two values (4, 3) it got from Action1 and passes on the result of multiplication (12) and another number (5) to Action3, where these passed on values are added and the result is shown in a message box.
1. Open a new test. Obviously Action1 will be there by default.
2. Go to Insert-> Call to New Action, when ‘Insert Call to New Action’ window opens, just click on Ok. This adds Action2.
3. Similarly add Action3 and Action4.
4. In the Keyword View right click on Action1 and choose Action properties. Action Properties window opens and go to Parameters tab.
5. In the Parameters tab, click on the +, which is on the right hand side of input parameters. Add 1st input variable as in_a1_1 (in means input, a1 is for action1 and 1 is 1st variable) and keep its Type as Number, let all other things be default.Similarly add 2nd input variable in_a1_2 and one output variable out_a1_1 also a Number Type.
6. Similarly add input and output parameters for Action2 (input variables in_a2_1 & in_a2_2, output variable out_a2_1) and Action3
(input variables in_a3_1 & in_a3_2, output variable out_a3_1).
In the Expert view of Action1 type:
s1=parameter("in_a1_1")
s2=parameter("in_a1_2")
parameter("out_a1_1")=s1+s2
RunAction "Action2", oneIteration, parameter("out_a1_1"), 3
In the Expert view of Action2 type:
parameter("out_a2_1")= parameter("in_a2_1") * parameter("in_a2_2")
RunAction "Action3", oneIteration, parameter("out_a2_1"),5
In the Expert view of Action3 type:
parameter("out_a3_1")= parameter("in_a3_1") + parameter("in_a3_2")
msgbox parameter("out_a3_1")
In the Expert view of Action4 type:
RunAction "Action1", oneIteration, 2,2

1 comment:

QTP/UFT Tutorials © 2014. All Rights Reserved | Powered by-Blogger | Designed by-Dapinder