Micro Focus QTP (UFT) Forums
QTP and Excel - 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: QTP and Excel (/Thread-QTP-and-Excel--230)

Pages: 1 2


QTP and Excel - Sonia - 02-25-2008

Hello ,

I was using QTP 9.2 with QC 9.2. My script needs excel data and this data can be changed by the client at any time . I have created a script but if I use File -> import from excel data it attaches the current data to my test .

Is there a way to avoid this and allow the test script to pickup data from the excel file . This way if the client changes the excel file data , my script does not have to be modified .

Please note currently I am using record and playback scripting only so if anyone can tell how this can be done , I'd really appreciate it

Again my test and data have to be uploaded to Quality centre finally .

Thanks


RE: QTP and Excel - deepakmehta82 - 02-26-2008

Hi Sonia,
You can import the required excel file to your local data table.
Suppose you want to import an excel file called Name.xls for which the path is C:\New\Name.xls
For this,just go to the expert view and write:
Data Table.Import("C:\New\name.xls")
When you will run the script, the data would be imported and you can view it in the Run Time table formed.Run Time table can be viewed from the result summary of your script.


RE: QTP and Excel - Sonia - 02-27-2008

Thank you for explaining it so clearly . I will do just that .
Sonia


RE: QTP and Excel - Sonia - 02-28-2008

Hi,

I did the above and it imported the excel file at run time . However I have two records in the datatable and for some resaon the script runs twice but only takes the first record. Could it be possible that the script is reloading the excel file for both iterations and hence only takes the first row of data

Thank you
Sonia


RE: QTP and Excel - deepakmehta82 - 02-28-2008

Hi Sonia,

Ya you are rite,if the script is running twice then offcourse it will take 1st row only each time.However,if you want to execute 2nd row also then you don need to execute the script again but you can simply use Data Table.SetNextRow after 1st row has been used.


RE: QTP and Excel - newqtp - 02-28-2008

Hi Deepak ,
Can't we use runsettings..Run for all row iterations?


RE: QTP and Excel - Sonia - 02-29-2008

Hi,

Actually I am only running the script once but the excel data has two rows of data . So that is why the script iterates twice , but takes the first row each time .

Is there a way to have the script take data from each of the excel table rows,

Thank you again for your help,
Sonia


RE: QTP and Excel - Brian - 02-29-2008

Hi Sonia,

Im assuming that your test run settings are set to "run on all rows". You could try and set this to run on one iteration only and then have a do-while-loop inside your script which can set the data table row. Also important to only import the excel sheet once at the start so this shouldnt be included in the while loop.
code could look something like this....

Code:
DataTable.Import("C:\ExcelSheet.xls")
Do
Row = Row + 1
DataTable.SetCurrentRow(Row)
.......
some code here using a row of data from the datatable.....
.......
Row = Row + 1
Loop while (True)

Hope this helps,
Regards,
Brian


RE: QTP and Excel - deepakmehta82 - 02-29-2008

Hi Sonia,

Above said explanation hby Brian is quite rite.You try doing that.


RE: QTP and Excel - Sonia - 03-06-2008

Hi , I did as mentioned by Brian but now the code still sexecutes twice so I actually have four runs when the datatable contains only two rows of data . Attached is the code ,

I just want the script to run once for each row of the datatabel but for some reason it runs the script twice for each row ending up with four results .
----------------------------
Code:
Dim Row
DataTable.Import("E:\OFT\login.xls")
Row=1
'This loop iterates for each instance of the login name
Do while (Row < (Datatable.GetRowCount+1))
DataTable.SetCurrentRow(Row)

SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Documents and Settings\SSharma","open"
Browser("Home").Page("Home").Sync
Browser("Home").Navigate "https://www.ITS Inc.org/#"
Browser("Home").Dialog("Security Information").WinButton("Yes").Click
Browser("Home").Page("ITS Inc,.").WebEdit("txtusername").Set DataTable("username", dtGlobalSheet)
Browser("Home").Page("ITS Inc.").WebEdit("txtpassword").SetSecure "8e9d06e4654024dbf48"
Browser("Home").Page("ITS Inc").Image("header$loginButton").FireEvent "onmouseover"
Browser("Home").Page("ITS Inc").Image("header$loginButton").Click 11,11
Browser("Home").Page("ITS Inc").Link("LOGOUT").Click
Browser("Home").Page("ITS Inc").Sync
Browser("Home").Close

Row=Row+1
Loop

---------------------------------

Thanks ,

Sonia