Sunday, November 11, 2007

QTP Test parameters

1. Open a New Test.

2. Go to File->Settings, a 'Test Settings' window will open, go to 'Parameters' Tab.

3. Click on '+' sign which is on the top right.

4. Enter the Name of the parameter as 'vartest' and its Default Value as 'hello'. Click Apply and then Ok. The Type of this parameter is string.

5. Above we have created a Test Parameter.

6. Now in the Keyword View right click on Action1 and select 'Action Properties'. 'Action Properties' window opens.

7. Go to 'Parameters' Tab. Click on '+' sign which is on the top right.

8. Enter the Name of the parameter as 'varaction' and its Type as string and no default value. Click Ok to come out of that window.

9. Again in the Keyword View right click on Action1 and select 'Action Call Properties'. 'Action Call Properties' window opens.

10. Go to 'Parameter Values' Tab. There you will see the 'varaction' action parameter we created earlier. Make a single click under 'Value' heading, it will show a button like this <#>. Just click on this button to open 'Value Configuration Options' window.

11. Click on 'Parameter' radio button and select 'Test/action Parameter' from that dropdown.

12. 'Test Parameters' radio button will be selected by default and under 'Test Parameters' radio button select 'vartest' from Parameter dropdown.[ remember this vartest is a test parameter we created at the beginning]

13. When you click on ok to come out of 'Value Configuration Options' window, in the 'Action Call Properties' window, under 'Value' it will show <vartest>. Click Ok.

14. Go to Expert View and type:
msgbox(parameter("varaction"))

15. Now run the test. While running it will show 'hello' in the msgbox.

This example show how to declare test parameters and how to access those.

Remember (taken from QTP guide):

You can directly access test parameters only when parameterizing the value of a top-level action input parameter or when specifying the storage location for a top-level output parameter. To use values supplied for test parameters in steps within an action, you must pass the test parameter to the action containing the step.

Alternatively, you can enter the parameter name in the Expert View using the Parameter utility object, in the format: Parameter ("ParameterName").