After our series on VB Script and QTP Part1, Part2, Part3 I would like to post a series on integration of QTP with MS Excel. Basically this series is to make the readers aware of how to work on QTP using data table and external excel sheets.

How can we use the data table to provide input data to an application?

Use the DataTable.Value method to access data from the data table and input it into the application
For data in the Global datasheet:QTP and Excel
1. Open a new script.
2. In column A of the Global datasheet, enter the data in three rows.
3. Go to www.google.com.
4. Begin recording.
5. Type a value into the Google search field.
6. Stop recording.
7. Go to the Expert view. Modify the script so it look like this:

rc = DataTable.Value ("A", dtGlobalSheet)
msgbox rc
Browser("Google").Page("Google").WebEdit("q").Set rc

8. To run all rows in the global data table, go to Test ->; Test Settings -> Run tab, and select “Run on all rows.”
For data in the Local datasheet:
1. Start a new script.
2. In column A of the Action1 datasheet, enter the data in three rows:
3. Go to www.google.com.
4. Begin recording.
5. Type a value into the Google search field.
6. Stop recording.
7. Go to the Expert view. Modify the script so it look like this:

rc = DataTable.Value ("A", dtLocalSheet)
msgbox rc
Browser("Google").Page("Google").WebEdit("q").Set rc

8. To run all rows:

  1. Right-click on the Action name in the Tree View.
  2. Go to Action Properites -> Run tab, and select “Run all rows.”

Similarly, How can we use the data table to get output data from an application?

Create an Output Value. The text will be placed in the datatable and can be accessed as needed.
1. Once you see the text you want to retrieve, start recording.
2. From the Insert menu, select Output Value, then Text Output Value.
3. Click on the desired text. The “Text Output Value Properties” window will appear.
4. In the window you can verify or set the Before and After text settings.
5. By default the retrieved value will be added to the Global sheet. You can modify the settings by selecting Output Text in the combobox, then clicking Modify.
6. Once satisfied, click OK.
An Output statement will be entered into the script.
Example:

Browser("Browser").Page("Page").Output CheckPoint("Text")
msgbox DataTable.Value("PageOutput_Text_out", dtGlobalSheet)

In addition, a column (in the example, PageOutput_Text_out) will be inserted into the datatable(Remember in the runtime datatable), with the output text.
OR Another method to retrieve data during run time is to do just the opposite of what we did above in the first question above.
DataTable.Value(ParameterID [, SheetID])=NewValue
Note:
The value property is the default property for the DataTable object. As the default property you do not need to explicitly use .Value.
DataTable(ParameterID [, SheetID]) = NewValue
Example:

' Add data to the current row of the Global sheet
DataTable("VarName", dtGlobalSheet) = "new value" ' Using DataTable by itself
DataTable.Value("VarName2", dtGlobalSheet) = "new value2" ' Using .Value
' Add data to the current row of the Local sheet
DataTable("VarName", dtLocalSheet) = "new value" ' Using DataTable by itself
DataTable.Value("VarName2", dtLocalSheet) = "new value2" ' Using .Value

If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS Feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.

Please use the QTP forum for posting questions now!

Please use QTP forum for posting QTP questions.