The process of replacing fixed value with parameter is called as parametrization where a parameter is a value that is assigned by external data source or generator. QTP enables you to expand the scope of a basic test by replacing fixed values with parameters. This process is known as parametrization, which greatly increases the power and flexibility of your test.
Types of Parameters
This enables you to create a data driven test that runs several times using the data you supply. In each repetition or iteration, QTP uses different values from the Data Sheets of the Data Table. The Data Table has two types of data sheets- Global and Action.
Global sheet contains the data that is available to all actions. Action sheet contains the data that is available to specific action. Below is the script to search a specified keyword from Google Search :
Types of Parameters
Depending on the source of data, parametrization is divided into 4 categories.
- Data Table parametrization
- Test/Action parametrization
- Environment variable parametrization
- Random number parametrization
- To do this from keyword view, select the cell which contains QTP and click on symbol.
- Value Configuration Option Dialog as shown below will be displayed. select the parameter as Data Table, Sheet as Global Sheet and Name of the column to store data as SearchKeyword.
- A new column SearchKeyword will be created in the Global Sheet. Add keywords to search in this column. After entering the data, the global sheet looks as below:
- Click Run button. You can see that the test runs 4 iterations and each iteration uses one search keyword from the list above.
- The number of iterations the test runs can be controlled from File>Settings>Run dialog.
Run one Iteration only: Runs Test Script one iteration only irrespective of the number of rows in the Global Sheet.
Run on all rows: Test Script iterations depend on the number of rows in Global Sheet. For example 4 rows in the Global Sheet means the test iterations for 4 times.
Run from row X to row Y: The test iterates to the difference between X and Y. If Y is 10 rows and X is 5 rows the test iterates 5 times.
Steps to do data table parametrization:- Select sheet as Local Sheet.
- A new column SearchKeyword will be created in the Local Sheet-Action1. Add keywords to search in this column. After entering the data the action1 sheet looks like this:
- Click Run button and observe that the script searches for only the first keyword in the column. This is because iteration settings of action points to Run One Iteration Only by default.
- To change the action iteration settings, select View>Test Flow. This opens the test flow pane, Right click on Action node in test flow pane and select Action Call Properties from the menu.
It will open Action call properties dialog as shown below: - Now Run the script and observe the script searches for all keywords.
Test/Action Parameters
Test/Action parameters enables you to use values passed from calling action to called action. say if we create a login action and made it reusable, this login action can be called from any other action. Limitation is that calling action has to use the username and password which is a part of login action. This limitation can be eliminated by Parameterizing the action in such a way that it takes input parameters as username and password.
- Create a login action for Gmail, Login code looks like as shown below, username is syedarmani :
- Right click on the action node and select action properties. The Action properties dialog box will appear. Select parameters>Input Parameters and click + symbol and add uname and passwd as their parameters and their type as string and password respectively. Action properties dialog looks as below and click OK.
- Now your action is ready with two input parameters uname and passwd. you must use these input parameters in the script. From the script shown above, text syedarmani in line1 must be parametrized with uname and line2 must be parametrized with passwd.
- To do this from keyword view, select the cell which contains syedarmani and Click on symbol.
- Value Configuration Option Dialog as shown below will be displayed. Select parameter as Test/Action parameter and parameter name as uname.
- Repeat steps 4-5 for password also.
- Now the action with parameters is ready to use by any calling action. Save this in a script as S1.
- Now let us call the Login Action of script S1 from script S2 and pass the parameter values. Steps for this are as shown below:
- Create new script S2 and select Insert>Call To Existing Action
- From Select Action dialog select the From test as S1 and Action as Login.
- Click OK. This adds a statement to call login action of script S1 from S2. The statement will be as shown below:
RunAction "Login[S1]" oneIteration - Right Click on node Login and select Action Call Properties. This displays Action Call Properties Dialog. Select the Property Values tab and enter uname as DemoUser and password Demo123. The dialog appears as below
- Now script S2 calls Action Login from script S1 and passes username and password as Demo User and Demo123.
Using Parametrization you can- Parametrize values in steps.
- Parametrize values of action parameters.
- Parametrize values in steps and checkpoints while working with your test.
- Also parametrize identification property values of test objects in the object repository using repository parameters.