The Data Driver enables you to quickly parameterize several (or all) property values for test objects, checkpoints, and/or method arguments containing the same constant value within a given action.
Let’s see with an easy to understand example the use of Data Driver option.
(Tools (Menu) -> Data Driver)
1
Open a new test in QTP and make sure that Flight Reservation Application window is open.
2
Click Record in order to start recording. Enter all the fields (in Flight Reservation Window) - Date of Flight, Fly From, Fly To etc and at last click ‘Insert Order’ button in order to insert a new record.
3
Stop recording and go to Tools (Menu) -> Data Driver.
4
Data Driver Window opens as shown below.
It shows 5 constants are there which can be parameterized.
5
Let us try to parameterize only one Constant value.
Select Denver as shown above and click Parameterize.
6.
Data Driver Wizard opens. Click Next.
7
On this screen (below) you can also click on Parameterize Options button (A paper and pencil icon on the right side of Parameter radio button) to select other options like Global sheet or Action Sheet etc. But for this example click Next.
8
Click Finish.
9
You will return to Data Driver window. You can now see that now for Denver it shows 0 under Constants and 1 under Parameterized i.e. value Denver is now parameterized once.
10.
Click Ok.
Now my code shows like this: (see 3rd line) and a new Data Table parameter is added (by default in Global Sheet) as you can see in the below screenshot.
1. Window("Flight Reservation").Activate
2. Window("Flight Reservation").WinObject("Date of Flight:").Type "12122009"
3. Window("Flight Reservation").WinComboBox("Fly From:").Select DataTable("DataTableDenver_param_dtGlobalSheet", dtGlobalSheet)
4. Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
5. Window("Flight Reservation").WinButton("FLIGHT").Click
6. Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
7. Window("Flight Reservation").WinEdit("Name:").Set "Sachin"
8. Window("Flight Reservation").WinEdit("Tickets:").SetSelection 0,1
9. Window("Flight Reservation").WinEdit("Tickets:").Set "2"
10. Window("Flight Reservation").WinButton("Insert Order").Click
11. Window("Flight Reservation").WinButton("Button").Click
11.
Enter one more value e.g. London and now run the test. It will run your script twice for each row.