Parameterization is a process in which parameters, or variables are substituted for hard-coded values which help perform the same operations on the AUT with multiple sets of data. In other words, in QTP, parameterization helps automation developers test an application with different data from a single action (or multiple actions) through multiple iterations. Because the data changes each iteration, it must be stored in a data-pool, or in multiple variables. This data-pool can be QTP’s (Local or Global) DataTables, an Excel Spreadsheet (external to QTP), Access DB, SQL Server, or any database of your choice. It can also come from several Environment variables. This topic will describe parameterization with QTP’s DataTable.
The trick to successful parameterization is cycling around a process. For example, consider a flight booking/checkout process. You would first login to the application, find and select the flight of your choice, make the purchase, and in the end view the confirmation.
If you were to parameterize the above process, instead of ending your script at the confirmation page, you would end it at the Find Flight page. This is because, when the next iteration executes, it is already at the correct page which can enable the script to start all over again at the expected point. In other words, our process should look like below:
Parameterization with DataTable
Before we start with the actual parameterization, we must first understand how data will be retrieved from the DataTable and the settings that we need to make in order to cover all the rows. In our example, we will test a few UserName and Passwords in the HP/Mercury’s Demo AUT.
Below, I have created 2 columns in the Local (Action1) DataTable- UserName & Password. You can create columns by simply double-clicking the Column heading:
Next, I will create 4 rows with different sets of data:
Below is the syntax to retrieve data from the DataTable’s local sheet:
'If retrieving data from Local DataTable (Action1, Action2,.. ActionN) DataTable("ColumnName", dtLocalSheet) 'If retrieving data from Global DataTable (dtGlobalSheet) DataTable("ColumnName", dtGlobalSheet)
Therefore, we can now create 2 statements using the syntax above to retrieve our user name and password:
DataTable("UserName", dtLocalSheet) DataTable("Password", dtLocalSheet)
Before we create our script, we must first tell QTP to run the test from all rows in the Local DataTable. In Keyword view, right-click Action1 then click Action Call Properties:
In the Run Tab of Action Call Properties window, select “Run on all rows”. A Dialog will popup mentioning what we discussed in the beginning of this post, about ending our iteration where the first step in our process begins.
Close the dialog, then click OK to save the settings we made under Action Call Properties. We are now ready to create our script which will take data from each row and test each UserName/Password combination. Below will be the steps in our process:
1. Launch application 2. Enter UserName/Password from DataTable and click Login 3. Verify if the Find Flights page appears 4. If Find Flights page appears, iteration passed. 5. Return to Home Page and start Step #2
'Step 1 If DataTable.LocalSheet.GetCurrentRow = 1 Then SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com" End If
After executing the above code, or manually launching the application, execute the below steps:
'Parameterization Block: With Browser("title:=Welcome: Mercury Tours", "index:=0") 'Step 2 'Parameter 1: UserName .WebEdit("name:=userName").Set Datatable("UserName", dtLocalSheet) 'Parameter 2: Password .WebEdit("name:=password").Set Datatable("Password", dtLocalSheet) .Image("name:=login").Click End With 'Step 3 'If Find a Flight page appears, go back to Home If Browser("title:=Find a Flight: Mercury Tours:", "index:=0").Exist(10) Then 'Step 4 Reporter.ReportEvent micPass, "Iteration " & DataTable.LocalSheet.GetCurrentRow, _ "UserName: " & Datatable("UserName", dtLocalSheet) & " is valid" Browser("title:=Find a Flight: Mercury Tours:", "index:=0").Link("text:=Home").Click Else 'Step 5 'Else, fail the iteration and return to the Home page Reporter.ReportEvent micFail, "Iteration " & DataTable.LocalSheet.GetCurrentRow, _ "UserName: " & Datatable("UserName", dtLocalSheet) & " is invalid" Browser("title:=Sign-on: Mercury Tours", "index:=0").Link("text:=Home").Click End If
Once the above script ends its execution, your test results should look like this:
This topic covered a very high-level process of parameterization, but I hope it gives you a good idea how this process can be enhanced and adapted to your application. The next topic in Parameterization will cover Excel Spreadsheets and a few tricks that we can use for successfully driving different sets of data to our AUT.