Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QTP and Excel
#1
Solved: 11 Years, 5 Months ago
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
Reply
#2
Solved: 11 Years, 5 Months ago
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.
Reply
#3
Solved: 11 Years, 5 Months ago
Thank you for explaining it so clearly . I will do just that .
Sonia
Reply
#4
Solved: 11 Years, 5 Months ago
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
Reply
#5
Solved: 11 Years, 5 Months ago
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.
Reply
#6
Solved: 11 Years, 5 Months ago
Hi Deepak ,
Can't we use runsettings..Run for all row iterations?
Reply
#7
Solved: 11 Years, 5 Months ago
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
Reply
#8
Solved: 11 Years, 5 Months ago
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
Reply
#9
Solved: 11 Years, 5 Months ago
Hi Sonia,

Above said explanation hby Brian is quite rite.You try doing that.
Reply
#10
Solved: 11 Years, 5 Months ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  excel macro to open QTP from excel karthik1979_us 1 11,157 11-07-2009, 02:57 AM
Last Post: geethwind

Forum Jump:


Users browsing this thread: 1 Guest(s)