Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Looping and DataTable

This is a discussion on Looping and DataTable within the QTP forums, part of the Software Testing category; Hey, I am trying to loop through a set of steps X number of times and each iteration the test is supposed to extract(output) data into the datatable. The problem ...

Go Back   Geeks Talk > Software Testing > QTP
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 07-01-2009
Junior Member
 
Join Date: Jun 2009
Location: Michigan, USA
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Davis2sa is on a distinguished road
Question Looping and DataTable

Hey,

I am trying to loop through a set of steps X number of times and each iteration the test is supposed to extract(output) data into the datatable. The problem is that if I set the loop to run 10 times it runs ten times but it records over the last run's data.

I'm using:

For i=1 to 3
Step1
Step2...
Next

To run the loop 3 times. But I only end up with one row of data in the DataTable because each loop records over the last loop's data.
I tried using DataTable.SetNextRow, but it didn't work.

Any ideas? Thanks.

Last edited by Davis2sa; 07-01-2009 at 10:45 AM.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-01-2009
Expert Member
 
Join Date: Apr 2008
Location: Tamilnadu
Posts: 1,465
Thanks: 15
Thanked 150 Times in 141 Posts
deepasree has a spectacular aura aboutdeepasree has a spectacular aura about
Re: Looping and DataTable

Hai friend,

File-> settings->Run->Run one iteration only->Apply-> ok.

Dim i
For i=1 to Datatable.GetRowCount

//steps here

Datatable.SetNextRow
Next

Now run your scripts and let me know.

Thanks
Deepa
Reply With Quote
  #3 (permalink)  
Old 07-28-2009
Junior Member
 
Join Date: Jun 2009
Location: Michigan, USA
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Davis2sa is on a distinguished road
Re: Looping and DataTable

This would work if I had existing data in the data table that I was running the test with. But I am starting with a blank datatable. I want the steps in the test to repeat 10 times and each time it should pull a number into the datatable. So, after the test is completed I should have 10 rows, 1 number in each row. But I only end up with 1 number in 1 row because the numbers just get written over the previous run's number.
Reply With Quote
  #4 (permalink)  
Old 07-29-2009
Expert Member
 
Join Date: Apr 2008
Location: Tamilnadu
Posts: 1,465
Thanks: 15
Thanked 150 Times in 141 Posts
deepasree has a spectacular aura aboutdeepasree has a spectacular aura about
Re: Looping and DataTable

Hai friend,

Ok initially you have blank datatable and you need to insert value in runtime into the datatable to perform iteration.

Datatable.ImportSheet "C:\Documents and Settings\Deepa\Desktop\Abc.xls",1,1

Note: This excel Abc.xls should contain the value to iterate.

The statement given above will insert the value into the datatable in run time and then use the below code and settings

File-> settings->Run->Run one iteration only->Apply-> ok.

Dim i
For i=1 to Datatable.GetRowCount

//steps here

Datatable.SetNextRow
Next

I hope this helps thanks, if not then tell me clearly what you are expecting.

Thanks
Deepa

Last edited by deepasree; 07-29-2009 at 05:58 AM.
Reply With Quote
  #5 (permalink)  
Old 07-29-2009
Junior Member
 
Join Date: Aug 2008
Location: Australia
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shruthihp is on a distinguished road
Re: Looping and DataTable

Hey,
Why don't you try this
Firstly declare the no of rows in the datasheet and Every time you retrieve the data from wherever you want it , set that to that particular row in which iteration the test is running currently.
Reply With Quote
  #6 (permalink)  
Old 07-29-2009
Junior Member
 
Join Date: Jun 2009
Location: Michigan, USA
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Davis2sa is on a distinguished road
Re: Looping and DataTable

How would I declare the number of rows that should be in the datatable?

Deepasree:
I am starting with a blank datatable. I don't want to import an excel file. One step in my test is to output a certain value to the datatable.

I want to run this test and end up with 10 different rows of data.

So, datatable after test should look like this:

Output Value
100000456
100000789
100000433
100000453
100000457
100000367
100000119
100000444
100000458
100000459

Right now it looks like this:
Output Value
100000459

Notice it's the last value output because it writes over the first row each time the steps loop.

Hope this is more clear.

Thanks for your help.
Reply With Quote
  #7 (permalink)  
Old 07-30-2009
Expert Member
 
Join Date: Jun 2008
Posts: 212
Thanks: 6
Thanked 12 Times in 11 Posts
learqtptesting is on a distinguished road
Re: Looping and DataTable

There are many ways of solving problem. It's nice to have code/logic from other to plug in your test but you will not learn unless you attempt to solve your problem or take code/logic from other to evaluate or experiment.

1) prepare you dataTable
2)
for i = 1 to 10
dataTable.value(your value)
Datatable.SetNextRow
Next


OR

row = 1
do while row < 10
dataTable.setCurrentrow(row)
dataTable.value(your value)
row = row + 1
loop



3) after the loop, you can save the datatable

Last edited by learqtptesting; 07-30-2009 at 09:14 PM.
Reply With Quote
Reply

  Geeks Talk > Software Testing > QTP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
DataTable Question Davis2sa QTP 5 06-15-2009 09:24 AM
Auto looping of the Script Hobqtplearner QTP 2 05-23-2008 02:11 PM
How to do looping for consecutive rows? coolkrish QTP 1 05-09-2008 06:49 PM
How to achieve looping in C++ Lokesh M C and C++ 0 09-05-2007 05:43 AM
Can we implement a cursor looping logic JayaSravani Data Warehousing 0 07-25-2007 12:36 AM


All times are GMT -4. The time now is 02:08 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved