It's actually pretty simple if you're just using a CSV file. I don't
have my code in front of me at the moment, but I use a CSV file to
store information for a login test.

Basically, since all CSV is is "comma separated", you just open the
file like normal in ruby, read each line, and use .split to get an
array with each value.

fin = File.open("C:\File\Path\Filename.csv","r")
fin.each_line do |line|
     values = line.split(",")
     #Do stuff with values here
end

for every line in the file, you will end up with an array of each
value on that line.
To write to a CSV file, just do the opposite. Every time you want to
write a line, add commas between your values
(Say that line[] is an array with one line of values you want to add
in a CSV file):

fout = File.open("C:\File\Path\OutputFilename.csv","w")
line.each do |value|
     fout.print "#{value},"
end
print "\n"

You could create a 2 dimensional array with all the data you want to
put into the CSV file and run the loop I just showed you within
another loop for each line:

fout = File.open("C:\File\Path\OutputFilename.csv","w")
allvalues.each do |line|
     line.each do |value|
          fout.print "#{value},"
      end
     print "\n"
end


If you want to add the results to the end of the file rather than
rewriting whatever was there already, change the "w" to "a" in the
File.open line, that will start writing at the end of the file rather
than the beginning.

Hope that helps, don't hesitate to ask more questions if you have
them.

-Dylan

On Jul 25, 8:03 am, RAM <rahulbhai...@gmail.com> wrote:
> Hi all........I am very new to Watir....anybody here knows how to
> import value from  .CSV files and Export Results into an .CSV file in
> Watir????.
> Please reply and provide links if similar subject is already posted.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to