Ruby has a built-in CSV library that comes with the standard distribution.

You could do something like:

require 'csv'
myData = []
CSV.open("C:\\mAddressData.csv", "r") do |row|
    myData.push row
end

You could then look at your data using

myData[row#][column#]

Note that both row numbers and column numbers start at 0.

I hope this is helpful.  You can find more on the CSV library on pg 663 
of the Pickaxe 2nd Ed.

Regards,
Alf

Mike Tierney wrote:

>long email- I have been burning too many cycles on this & just about to go 
>back to manual testing for now<g> ... or use Win32:GuiTest for the current 
>problem :>( .. too bad because I love using Watir for web app testing, and 
>this is a web app I've got
>Does anyone know how to load test variable inputs from a file into a 2-D array 
>and use them in a WATIR script ?
>I used to do this in Win32:GuiTest using Perl and it seemed straightforward,
>(Thanks for even reading Perl <g>) eg.
>open (FIL, "C:\\mAddressData.csv");
># reading from file
> while ( <FIL> ) {
>     chomp;
>     push @mDatArray, [ split /,/ ];
> }
> 
> for ($k=0; $k< 20; $k++) {
> 
>  # get to address query home page
> address1 = "$mDatArray[$k][0]";
> # note the address1 field in the input file has no commas
> # so I can safely use csv files as input
> city = "$mDatArray[$k][1]";
> state = "$mDatArray[$k][8]";
> 
> 
>    # now do some stuff on the app with the address query screen
>    # using the inputs from row 'k' of my input
> 
>{
># here is a similar attempt in Ruby/ Watir
>##################################################################
># load data array
>############
>DatArray= Array.new
>File.open("Data99.csv","r") do |file|
> while line= file.gets
>    DatArray<<line.split(',')
> end
>end
>i=0
>while(i < 100)
># go to address query start
>
> ie.text_field(:name, "address1").set(DatArray[i,0].to_s)
> sleep 2
> ie.text_field(:name, "City").set(DatArray[i,1].to_s)
> sleep 2
> ie.text_field(:name, "State").set(DatArray[i,2].to_s)
> 
> sleep 2
> ie.send_keys("{tab}")
> ie.send_keys("{ENTER}") #submits address query
>
> i = i + 1
> sleep 2
> 
># end while loop
>end
># number 1 problem is that line.split does not seem to really split up the line
># number 2 problem.. if I leave off 'to_s ' Ruby complains that I can't use an 
>array cell
>#  with the set argument. problem 2.1 .... If I put to_s on, Ruby concatenates 
>each successive string I use it with
># anyone SUCCESSFULLY  done anything similar to this with Ruby/ watir ?
>Thanks
>Mike Tierney ..
> 
>
>_______________________________________________
>Wtr-general mailing list
>[email protected]
>http://rubyforge.org/mailman/listinfo/wtr-general
>
>  
>

-- 
Alf Whitehead [EMAIL PROTECTED] 416-214-4977 x260
Quality Assurance Specialist
Klick Communications, http://klick.com/

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to