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:![]()
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:
- Right-click on the Action name in the Tree View.
- 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 Testing Tools forum for posting questions now!

32 comments:
Hi ankur i am a fresher to the domain
of software testing i have lots of challanges to full fill, i want to play with QTP please show a path
cause i am not finding anyone as such
cheers
my contact e mail is rocketspeed_rocketspeed@yahoo.co.in
HI Ankur,
In our testing, we are using Mercury Quality Center to run QTP Scripts. I want to get a consolidated report of all the scripts passed/failed and if failed where they are failed. How to generate this report. Please let me know,
Thanks,
Arpitha
argarapati@deloitte.com
Hi Anukar,
I added an excelsheet With the Datatable.addsheet method. I tried to put a value into the added sheet with Datable.value("a","MySheet") method. But Itz not working/allowing. I am using qtp 8.2. Watz the solution for dis?
I have one excel sheet and column is more than 256.So is there any solution to convert this excel sheet in another format and how???
@ Neeraj, Are you sure you need 256 columns? thats too much...How much time will it take to enter data inside those? If your app really requires 256 columns to be filled. Is it really worth automating?
Hi How can we retrieve the data present in an excelsheet using VBScript with QTP.
Kindly help me out
Hey Ankur
How can we retrieve data from a notepad file?
Hi Ankur...
Thanks for ur guidance....
just want to add one thing..in QTP 8.2 if u want to run all row....
To run all rows:
Right-click on the Action name in the Tree View.
Go to Action Call Properites (Not Action Properites)-> Run tab, and select "Run all rows."...
Thanks
Bharat
hi ankur this is raju . pls help me about this Quality center . if possiable can i have any help regarding qc. pls tell me how to play with qtp.. any links ,pls helpme iam in job search
waiting fr your positive response
cheers
raju
Hi Ankur,
I used your example to add data to the Global sheet using
DataTable.Value("XXX", dtGlobalSheet) = "textValue"
where XXX was the column name in the Global Sheet and textValue is my value to be inserted. What could be the problem. Nothing is getting written into XXX column.
thanks
@ Sai: As I have written in the post above, the value could be seen in run time data table(ie the one which you get in the results window after your script is executed) not the design time data table.
Examples in the site are Great and simple to understand.
Great ! Keep it UP
Thanks Ankur, that helped. I was not looking at Run Time table before. I have another question. Can I pass a variable in the sql query when creating a DB Checkpoint.
This is what I want to do:
textvalue=Browser("Browser").Page("Page1").WebEdit("WebEdit").GetROProperty("innertext")
In the DB Checkpoint query:
select * from tablename where col=textvalue
Instead of :
select * from tablename where col=1234
Thanks,
Sai
Hi All,
I wanted to know if we can use two different dataSheet in the same script. If Yes then some one can u please help me knowing how to do the same... Thanks in advance...
Raghu
Hi,
I wanted to know if there is a way to take data from multiple rows in one iteration. Alo if more than one datasheet can be used...
Hi,
While outputting values, is there a way to import the values to the local data sheet from the run time data sheet? Also, in the data sheet, how can we output values in to different rows?
hey ankur i m not able to record the dialog boxes getting opened after right clicks of mouse how 2 fix this bug
Hi,
we have newly started recording scripts for regression in our test application. My question is , I have 10 text boxes in one screen , I need to create a record for each text box with each different data. how can I do this.
like
1st record --text box1- xxx(save)
2nd record----text box2 -yyy(save)
3 rd record--text box3--zzz(save)
This is also great initiative, it helps me a lot.
I have a que: If I want to fetch value from datasheet based on particular column-row intersection (like where clause in database).
Like I have value in two column as follows:
Gujarat-Gandhinagar
Maharastra-Mumbai
Karnatka-Bangaore
If I want to fetch Capital based on State like in data base:
Select Capital from tble where state="Karnatka"
Is it possible from datasheet, if yes how?
Hi Ankur,
Does QTP 9 support audio/video streaming?
Thank You,
Luky
hi when ever i do the example of global sheet using google.com i get this error : The "q" object was not found in the Object Repository.
Check the Object Repository to confirm that the object exists or to find the correct name for the object.
so please give me the solution for this.
Hi Ankur,
we r trying to get the sum of price of orders(in flight application of QTP)using data table.
i=Window("text:=Flight Reservation).WinEdit("attached text:=Total:").GetVisibleText
msgbox i
and further we r unable write the script, can u help us? and send me the answer 2 rajendra_js@yahoo.co.in
Hi Ankur,
Does QTP support SAP BW 7.0
If yes any link or document for the same
Thank You,
Milan
Milan_Kothari@satyam.com
Hi i am supriya can anyone tell me which is the best institute to learn QTP automation tool in Bangalore(India).. Please reply to my email id supriysahen@gmail.com..
Send me QTP Faq & Objective questions related to it.. I request anyone to reply to my email id--> supriysahen@gmail.com
Hi ankur i am a fresher to the domain
of software testing i have lots of challanges to full fill, i want to play with QTP please show a path
cause i am not finding anyone as such
cheers
tejmail@yahoo.com
hi, can anyone help to install qtp, as i want to learn it, and send me some links from where i can download it .
vikram_mukhyan@yahoo.co.in
How are we save external data in datatable sheet.
i tried following statement with loop
datatable.values("A",dtlocalsheet)=rs.fields(1)
but values doesn't save into column
please advice.
is there another way i need to implement.
-Achyut
Hi Ankur,
What does it mean to "click" on the text that you want to be saved in the run time DataTable? Suppose I search for 12+12= in Google; I end up getting the result. Now, I would like to save the result in my dataTable. But the problem is how do I specify the text for the text output checkpoint? I mean clicking on the result does not do anything; My message box pops up a blank value. Please help.
Thanks in anticipation,
Sakura
Hi
i have functions say fun1(),fun2(),fun3()
i want to call these functilns from excel sheet.and results also in excel sheet please help me its urgent
Thanks & Regards
vanu
@supriya : you can go for Qspider , Bangalore . I think this is the best institute for learning QTP.
Hi All,
Can we use excel as database in QTp?
HI ankur
could you tell me how to save my data in excel sheet...
i am using datatable.value("A","action1")="pass"
but after running script see me in run time in data table but when i try to see that my data save on not in excel then i got no value save in excel.
plz tell how to save my data in excel sheet..
plz do me solution on prashantkit@gmail.com
Post a Comment