The Data Driver in UFT provides you an option to quickly parameterize required property (or all) values of test objects, checkpoints, and/or method arguments containing the same constant value within a given action. You can record a Test and quickly parameterize constant/hard-coded values with either DataTale, Environment Variable, or a Random number.
- How UFT Data Driver works
- Replace a constant value using a parameter
- Replace all occurrences of constant value with a parameter
How Data Driver works in UFT
Let’s suppose we have recorded a Test on Mercury Tour Demo application and the following is the recorded code. You can see the constant / hard-coded values in the script highlighted with yellow color.
1 2 3 4 5 6 7 8 9 10 11 |
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "abcd1234" Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").Set "abcd1234" Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Sync Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("passCount").Select "2" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select "2" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("passCount").Select "2" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebRadioGroup("tripType").Select "oneway" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebRadioGroup("servClass").Select "Business" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("airline").Select "Unified Airlines" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("findFlights").Click |
In real-life automation projects, there is no room for hard-coded values and everything should be parameterized to test the same test script with different sets of data.
In order to replace constant values with parameters, go to “Tools > Data Driver”.UFT takes some time to scan the entire test for constant values before opening the Data Driver utility. When the Data Driver opens, it displays the list of default constant values in the current action. The constant column indicates how many times the constant value has been used in the action. The parameterized column indicates the number of occurrences the constant value has been parameterized.
The Data Driver does not show the Test Object name of the script as constant values. If you want to parameterize a Test Object as well or any other value that is not being displayed in the list, click on the Add Value button. The “Add Value” dialog box will open. Enter a constant value in the dialog box and click on the OK button. The constant will be added to the list.
Replace a Constant value Using a Parameter
The Data Driver window will be displayed. You will notice that the constant column will now be showing 0 and the Parameterized column will be showing 1 value against the selected constant value indicating it has been parameterized. Click on the OK button.
The constant value will be replaced with the parameterization statement in the code and the parameter name along with the value will be added in the DataTable.
1 |
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("airline").Select DataTable("Airlines", dtGlobalSheet) |
Replace all occurrences of constant value with a parameter
The Data Driver utility gives you an option to replace all occurrences of constant values with a parameter. In the following code value “2” has been used in three different web list-objects.
1 2 3 |
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("passCount").Select "2" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select "2" Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromDay").Select "2" |
If you open the Data Driver it will look like the following snapshot. There are three occurrences of constant value 2 and the number of Parameterized constant value will be 0.
Click on the Parameterized button. Data Driver Wizard will be displayed. Select the “Parameterize all” option to parameterize all occurrences of constant value “2”.Data Driver automatically assigns the name of the parameter.
The name might not be very meaningful. So I would recommend it to give a meaningful name. To edit the parameter name, click on the pencil icon. The parameter Options window will be displayed. Provide a meaningful name and click on the “OK” button.
Data Driver Wizard will be displayed again. Click on the “Finish” button.
The Data Driver window will be displayed and the “Parameterized” column will show that 3 occurrences of constant value “2” have been parameterized and the number of constant will become 0.
Click on the OK button. All the constant values will be replaced with the same DataTable parameter.
Recommended Posts
- How to Use RegisterUserFunc in UFT with Examples
- An Insight on UFT Test Settings
- File Content Checkpoint | PDF File Validation in UFT
- Reading and Updating MS Access Database Using ADODB in UFT
- How to Use Insight Object in UFT
- Amazing Facts about Object Repository Manager in UFT
- Action Input And Output Parameters In UFT
- Micro Focus UFT Tutorial – An Overview of UFT