Вы находитесь на странице: 1из 6

Parameterization

Def: A parameter is a variable that is assigned a value from the external data source or generator By replacing fixed values with parameters QTP increases the power and flexibility of the test. Values in steps and checkpoints and also the values of action parameters can be parameterize. Parameters let us know how the application performs the same operations with multiple sets of data.

Types
1) Data Tables
It allows us to create a data-driven test (or action) that runs several times using the data that we supply. In each repetition, or iteration, Quick Test uses a different value from the Data Table. It will run only for one value inputted during recording. Example: 1. 2. 3. 4. 5. 6. Open a new Test. Click on Record (F3). The mouse pointer will become hand and QTP will be minimized. Open Flight Reservation application and enter username rajeev, password as mercury and click ok button. Stop recording. Now go to Keyboard View and click on AgentName and then value rajeev and click symbol <=>.

7. It will open view configuration option. From here select Parameter and in Name type c_name and click OK.

8. Now in the data table enter names under c_name heading.

9. Now Run (F5) the test will execute application with all the users in the list one by one. 10. Result window will show test result with all users separately. 2) Environment Variables Environment variable parameters allow us to use variable values from other sources during the run session. These may be values that we supply, or values that Quick Test generates for us based on conditions and options we choose. Types: I. Built-in Variables: Built-in variables as the name suggests are predefined by QTP. Examples of such variables are OS, OSVersion, ActionName which are for Operating System, Operating System Version and name of the action which is currently running, respectively. Example: 1. Open a new Test. 2. Go to File (Menu) > Settings, a Test Settings window opens. 3. Go to Environment Tab. By default Built-in variable type is selected and you will be able to see Name and Description of Built-in variables below Variable type dropdown box.

4. 5. 6. 7.

You can click on any of those variables to see their current value. I just did the above four steps in order to show you from where you can access Built-in variables. Now close this Test Settings window and go to test. In the Expert View type:
a = environment("ActionName") & " is running on " & environment("OS") msgbox (a)

8. And Run the test. It is just a simple way to show how a Built-in environment variable works. II. User defined (Internal) Variables: User Defined Internal variables are the variables defined by you (the user) within the test and which are saved within the test and also accessible from within the test.

Example: 1. Open a new Test. 2. Go to File (Menu) > Settings, a Test Settings window opens. 3. Go to Environment Tab. From Variable type dropdown select User-defined. 4. Click on the '+' which is on the right of Variable type dropdown. 5. 'Add New Environment Parameter' window opens up, type the name and value of the variable e.g. in Name type 'n' and in Value type 'rajeev' and click on OK. It will add the variable with its type as 'internal'.

6. 7. 8. 9.

Click Apply and OK to come out of Test Settings window. Click on Record (F3). The mouse pointer will become hand and QTP will be minimized. Open Flight Reservation application and enter username rajeev, password as mercury and click ok button. 10. Stop recording. 11. Now go to Keyboard View and click on AgentName and then value rajeev and click symbol <=>.

12. It will open view configuration options. From here select Parameter and then Environment from drop down list. Now select n from the Name drop down list and then click OK button.

13. 14. Go to expert view and type:


msgbox(environment("n"))

15. Now Run the test. It will show you the value of variable 'a' in the message box. III. User defined (External) Variables: User-Defined external variables are the variables which are defined in the file outside of test. These act as read only for the test. You can create as many files for environment variables as you want and choose them for your test. Example: 1. Open a new text file and type the following lines in it and save it with .xml extension.

2. 3. 4. 5.

Open a new Test. Go to File (Menu) > Settings, a Test Settings Window opens. Go to Environment Tab. From Variable type dropdown select User-defined. Click on "Load variables and values from external file" check box and import that external xml file that we created above. As soon as it is imported the complete path of that file will be shown in the File text box and the variable in it will show under Name, Value and Type heading (in our case it will show Address under Name, 25 yellow Road under Value and External under Type). 6. Click on Apply and Ok to come out of it. 7. Go to expert view and type:
msgbox(environment("Address"))

8. Now run the test. It will show you the value of variable 'Address' in the message box. 1. Random Numbers Random number parameters enable us to insert random numbers as values in your test. Values in steps and checkpoints can be parameterized while recording or editing the test. The values of object properties can be parameterized for a selected step.

The values of the operation (method or function arguments) defined for the step can also be parameterized. When the value of an object property for a local object is parameterized, we are amending the test object description in the local object repository. Therefore, all occurrences of the specified object within the action are parameterized. Parametersing the value of a checkpoint property enables us to check how an application or Web site performs the same operation based on different data. Example: 1.

2. Action Parameters
Test/action parameters: Test parameters make possible for us to use values passed from the test. Action parameters enable us to pass values from other actions in your test. To use a value within a specific action, the value must be passed down through the action hierarchy of the test to the required action. We can then use that parameter value to parameterize a step in the test. Example: 2. Start a new test. 3. In the Keyword View right click on Action1 and select 'Action Properties'. It will open 'Action Properties' window.

4. Go to 'Parameters' Tab. Under Input Parameters click on '+' sign which is on the top right. 5. Enter the Name of the parameter as 'a', its type as Number and Default Value as 10. In the same way create another Number parameter 'b' and Default Value 5. 6. Now create an Output Parameter as c and its type as Number and Click Ok.

7. QTP will show a message box that This is a reusable action. Modifying Click Yes button.

8. Now, In the Expert View of Action1 type: X=parameter(a) Y=parameter(b) Parameter(c)=X+Y Msgbox parameter(c) 9. Run the test will show you a message box with result as 15.

Вам также может понравиться