What Does Parameterization in QTP Mean?
There are instances wherein an application does not allow repeated data entries. If the same test script is run with the same input data, the application may throw an error due to data duplication. To address this, QTP comes with a provision for accepting various test inputs for the script.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
This method of providing different input data via external parameters is termed as parameterization.
=> Access the QTP Training Tutorials Series Here
Different Types of Parameterization in QTP
The variable values could be from any of the following parameter types:
- Data Table parameters
- Test/Action parameters
- Environment variable parameters
- Random number parameters
In today’s QTP guide, our primary emphasis will be on parameterization using the Datatable, while we will further discuss other types of parameterization techniques in the next guide.
Parameterization Within QTP
Suppose you are scripting a program to validate the login credentials for multiple users at gmail.com. Given below is the code for one user:
Code for Single User Gmail Login:
SystemUtil.Run "iexplore.exe", "http://www.gmail.com" Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "swatiseela" Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure "sfgs686898" Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click
You can create different values each time by parameterizing the email ID and password. This can be accomplished in the Keyword view by clicking on the value column for both the email ID and password set statements.
The screenshot below displays the various parameterization options:
With the parameterization options, you have the choice to use a fixed value or parameterize the fields. By choosing the parameterization option, you gain the ability to use values from the data table, environment variables, or random numbers.
In the given code snippet, the email ID and password values dynamically come from the data table.
Upon running the code on all of the rows of the data table, the script will run for each email ID and password pairing. The number of iterations can also be managed programmatically using a loop.
How to Use Parameterization in QTP via Datatable (Example)
Parameterization in QTP Using Excel
While parameterizing, you can select if the data originates from the global sheet or the current action sheet.
Name: This pertains to the column name in the data table where the data is housed. Although QTP proposes a default name, you can alter it as needed.
Global Sheet: This sheet carries data that is accessible for all actions during a test.
Current Action Sheet or Local Sheet: This sheet holds data that is only accessible for a specific action.
You can supplement multiple data rows to the global data sheet. For added security, you can encrypt the values using a password encoder tool.
Here’s an instance of a data sheet:
Following the parameterization, the code will appear like so:
SystemUtil.Run "iexplore.exe", "http://www.gmail.com" Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set DataTable("SignInName", dtGlobalSheet) Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure DataTable("GPassword", dtGlobalSheet) Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync Browser("Gmail: Email from Google").Close
The values for the email ID and password are drawn from the data table in the preceding code.
If the “Run on all rows” option is chosen, the code will execute for all rows present in the global sheet.
If you’d rather control iterations programmatically, you can pick the “Run one iteration only” option and tweak the code accordingly:
for i=1 to datatable.GetRowCount SystemUtil.Run "iexplore.exe", "http://www.gmail.com" Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync datatable.SetCurrentRow(i) varName=datatable.value("SignInName") varPwd=datatable.Value("GPassword") Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Email").Set varName Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Passwd").SetSecure varPwd Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebButton("Sign in").Click Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync Browser("Gmail: Email from Google").Close next
Running the test with two iterations will generate test results for each iteration.
It’s crucial to comprehend each line of code and the sequence in which it’s placed for successful test execution:
- The browser is launched within the ‘for’ loop to make sure each iteration initiates with the same state.
- Sync statements are integrated to pause for page synchronization prior to performing operations.
- Explicitly closing the browser guarantees only a single instance of the browser is open.
- The close statement is placed inside the ‘for’ loop to terminate the browser following each iteration.
Maintaining a consistent application state throughout iterations allows you to provide consistent parameters for interaction.
Below is an illustration of using a local sheet:
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Email").Set DataTable("Name", dtLocalSheet) Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Passwd").SetSecure DataTable("Pwd", dtLocalSheet) Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebButton("Sign in").Click
QTP offers parameterization options for checkpoints, object properties, operation arguments, and local object repository properties.
The example mentioned above demonstrates the data driving of a test. Other parameter types can be explored in the following article.