Data table in QTP

By | July 15, 2009

Data table in QTP

What is Data table in QTP?

Data table is simple excel kind of sheet with columns and rows which display data applicable to your test. Data table will help you in parameterize your test.
To view data table Go to view->Data Table.

There are basically two kinds of data sheet one is Global sheet and other is local sheet (current action sheet)

Practical example of Data table in QTP

I am going to give you step by step procedure from scratch to end for how to use data table in your application, so you will be more clearer about data table in QTP.
Please go through following procedure.

1. Press “Record” button.
2. Go to start->run write http://google.com and click OK.
3. close the internet explorer window, you will have code like following.

————————————
SystemUtil.Run “http://google.com”,””,””,””

Browser(“Google”).Page(“Google”).sync

Browser(“Google”).Close
————————————

4. Now put cursor on second sentence and do right click on that sentence.

5. Select “Insert output value”, you will have window like following select all three properties and click ok. By default all the values will go to global sheet. You can modify this setting by pressing “modify” button and selecting local sheet.(Note: You can also redirect these values to environment table and you can access it. know more about environment variable in qtp and how to load and export environment variable in qtp ) Refer following figure for more clarity.

6. So you will have code like following.

————————————
SystemUtil.Run “http://google.com”,””,””,””

Browser(“Google”).Page(“Google”).Output CheckPoint(“Google”)

Browser(“Google”).Page(“Google”).sync

Browser(“Google”).Close
————————————
7. So when you run the above script you can view three parameter and its value in global data sheet. If you are not able to view, please go to view->Data Table.

8. You can view values during test run, you can’t view that value after test is over.

9. You can export these values in external file with help of datatable.export command.
Put following sentence at last in your script

Datatable.export(“c:\qtp.xls”)

10. You can also use datatable.import command to import external excel file to your test in the start of test.

How to use values in data table during run time in QTP?
You can do so using datatable.value command. For e.g.

intLink = datatable.value (“Google_number_of_links_out”)

Values from “Google_number_of_links_out” parameter will be stored in intLink variable.

In addition to this you can also use datatable.getrowcount command to get row count in datatable. You can also use addsheet, deleteSheet, getSheet, getSheetCount, setCurrentRow, setNextRow, setPrevRow data table methods etc. You can use QTP help for more understanding on this kind of data table commands.

Let us know if you have any doubts on data table in QTP, You are always welcome to share your valuable thoughts and feedback.

If you like this article, You can subscribe through mail.

2 thoughts on “Data table in QTP

  1. Alex

    Hi there,

    For the test I am doing, I am creating an adjustment within my application. The adjustment is always 1000, so I will always know what the output will be, ie 1000, 2000, 3000, in other words each time the adjustment is made, it increments by 1000. My test is to ensure the application successfully adds the 1000 each time it is run. If the result was 500, 1200, 1450 e.t.c.., then it’s a fail. So I have a column in the data table starting from 1000 thru to 10,000 paramatising the only acceptable output values, divisable by 1000. Now when I run the test, it only reads from the first cell. Is there anyway QTP can read a value in any cell in the column, and not just the first cell everytime the test is run??

    Thanks in advance for your help

    Alex

    Reply
  2. Nrusingha Acharya

    keep the input values in local sheet of Default.xls of the script,
    then in your script
    Add code like:

    FYI: The first row will be the column name, so data will be started from 2nd row:

    For i = 2 to 10
    propName = DataTable.GetSheet(“Local”).GetParameter(1).ValueByRow(i)
    propValue = DataTable.GetSheet(“Local”).GetParameter(2).ValueByRow(i)
    sourceValue = DataTable.GetSheet(“Local”).GetParameter(3).ValueByRow(i)

    here , GetParameter(3) : means 3rd column
    ValueByRow(i): i’ th row

    now u can values in ur script

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *