How, for each row, in global data sheet, QTP iterates all rows of any action data sheet.
1. Open a new Test.
2. Click on Record.
3.Go to Start->All Programs->QuickTest Professional->Sample Applications->Flight.
4. Enter the Agent Name as 'mary' and Password as 'mercury'. Click Ok (make sure we click ok with mouse and not hit the return (enter) Key.)
5. When the Flight Reservation window is open, go to File->Exit.
6. Click Stop in order to stop recording the test.
7. In the Keyword View under 'Value' column, make a single click on 'mary' (Agent Name), a button like <#> will appear, click on this button to open 'Value Configuration Options' window.
8. Click on Parameter radio button and select Data Table from the dropdown and let rest everything be default. click ok to come out of that window.
9. In the Global Data sheet it will add a new columns with 'mary' as its first value.
10. Go to Insert (menu) -> Call to New Action to insert action2.
11. For this action2, repeat steps from 2 to 7. (This time I have used the Agent Name as 'bill')
12. After repeating step 7, when you click on 'Parameter' radio button and select Data Table from the dropdown, make sure you select Current action sheet (local) in the Location in Data Table area. Click Ok to close that window.
13. It will add a new column in action2 Data Sheet with 'bill ' (because I used bill as an Agent Name ) as its first row.
14. Now you have two actions (action1 and action2), both of them do the same job but their data is in different sheets.
15. Go to Global Data Sheet and Add one more row in it below 'mary'. I added 'rama'.
16. In the Local Data Sheet (action2) add two more rows to make them a total of 3. I added 'amar' and 'Sumit'.
17. Right click on action1 and select action call properties, go to Run Tab and select "Run on all rows" radio button. Do the same for action2.
18. Go to Expert View of action one and type : msgbox("acton1"). Now my action1 looks like this:
- SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest
- Dialog("Login").WinEdit("Agent Name:").Set DataTable("p_Text", dtGlobalSheet)
- Dialog("Login").WinEdit("Agent Name:").Type micTab
- Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
19. Do the same for action2 and type msgbox("acton2") in its Expert view, as we did for action1.
20. Now Run the test.
I have added the msgbox step in both the action just to make you understand how the QTP is picking up the rows from Data Sheets, otherwise it will be fast and some people may not able to understand.
This examples shows that each action can access data not only from Global Data Sheet or its own Local Data Sheet but also from other action's Data Sheet in the same test.
Open a new test.
Insert two actions.
In the Global Data table, in cell(A,1) type 'Global Data'.
In the Action1 Data table, in cell(A,1) type 'Action1 Data'.
In the Action2 Data table, in cell(A,1) type 'Action2 Data'.
msgbox("I am in action 1")
rc = DataTable.Value("A", dtGlobalSheet) 'accessing data from Global data sheet from action1
rc = DataTable.Value("A", 2) 'accessing data from action1 data sheet from action1
In expert view of action2 type:
msgbox("I am in action 2")
rc = DataTable.Value("A", dtGlobalSheet) 'accessing data from Global data sheet
rc = DataTable.Value("A", 2) 'accessing data from action1 data sheet from action2