Mike
To address a 2D array in Ruby, you need something like this:
dataArray[i][j]
when you write dataArray[i,j] you are accessing a slice.
Try this:
dataArray= Array.new
n = 0
File.new("data.csv").each_line do |line|
line.chomp!
dataArray[n] = line.split(',')
n += 1
end
i=0
while(i < dataArray.length)
# go to address query start
puts "First: #{dataArray[i][0]}"
puts "Second: #{dataArray[i][1]}"
puts "Third: #{dataArray[i][2]}"
sleep 2
i = i + 1
sleep 2
end
John
P.S. By convention, variable names that start with a capital are Constants.
On 10/18/05, Mike Tierney <[EMAIL PROTECTED]> 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
>
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general