Retrieving test data from Excel sheet - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP) +--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners) +--- Thread: Retrieving test data from Excel sheet (/Thread-Retrieving-test-data-from-Excel-sheet) Pages:
1
2
|
Retrieving test data from Excel sheet - janriis - 01-26-2011 Hi all I need to retrieve test data from an Excel sheet instead of using the build in Data table. For each iteration passed, i also need to return an "OK" to the Excel sheet. Could anyone tell me how that is done ? RE: Retrieving test data from Excel sheet - sreekanth chilam - 01-27-2011 Hi, Search for "Excel COM" in this forum. You can do it easily. RE: Retrieving test data from Excel sheet - janriis - 01-27-2011 Searched all over this forum and found lots of bits of code which required that you knew the rest of the code. I want to be more specific about my question I have an Excel file called: testdata.xlsx in the folder "C:\temp" In this file I have a sheet called "release 1". In the sheet I have 3 columns which looks as follows: Column A: UserID Column B: FirstName Column C: LastName In my web application, I have 3 WebEdit fields also called UserID, FirstName and LastName So how should the code look like if I want to retrieve the data from the 3 columns in Excel and populate the WebEdit's in my web application ? RE: Retrieving test data from Excel sheet - tarun - 01-27-2011 first you need to change the excel to 2003 format as QTP does not support 2007 format. then you can use Datatable.importsheet or datatable.import statements to import the sheet to your test. The second way is to change the "Resource" settings for the test (right click on test in test flow tab and select settings), under the data table options give the path of your excel file. Hope this helps RE: Retrieving test data from Excel sheet - sreekanth chilam - 01-27-2011 Hi, As tarun suggested, use .xls format file instead .xlsx format excel files as they are not supported by QTP. Code: Dim xl RE: Retrieving test data from Excel sheet - janriis - 01-28-2011 Thx for your reply, but wont it just take the first row of data ? The next run should fetch data from the second row and so on. RE: Retrieving test data from Excel sheet - tarun - 01-28-2011 Use the statement DataTable.ImportSheet SheetPath, SheetSource, Sheetdestination statement in your QTP code to import the excel sheet to your test case e.g. DataTable.ImportSheet "c:\test.xls","TestData","Login" This statement will import data from TestData worksheet of test.xls excel sheet to data table of Login action. if you want to import to global sheet then use DataTable.Import "c:\test.xls" RE: Retrieving test data from Excel sheet - sreekanth chilam - 01-28-2011 Hi Janris, In your question given above you have just asked for 3 columns A,B,C. So I took that example code You can use the below statements to the above code. Row_Count=xl.ActiveSheet.UsedRange.Rows.Count Code: For i=1 to Row_Count RE: Retrieving test data from Excel sheet - Zelfiris - 01-31-2011 Don't mean to hijack your thread, but I also have an excel question. I'm trying to get QTP to read "0002" from my spreadsheet but I'm not sure how to do it. When I used .csv with a different application it saves the zeros but with .xls it does not seem to be able to. Thanks! RE: Retrieving test data from Excel sheet - tarun - 02-01-2011 When you are saving data to excel sheet try to "'" before the data |