There are quite a few other steps that I'm skipping because they're
pretty easy to google (checking if a log file exists already, appending
the log name with the date to preven overwrites, etc), but here's a real
simple intro:

                textlog = File.open("text.log",
File::CREAT|File::APPEND|File::WRONLY)

This creates a file named text.log in the root directory.  The flags at
the end tell it to create the file it if doesn't exist, append the file
if it already exists, and allow write access.

Now, when you want to write something to the log, you use:

                textlog.puts "Here's some stuff"

I store my logging function in a separate library and call it at the
beginning of each test, and then call a separate function that enters
some formatting for the end of the log at the end of each test.  I just
use simple formatting like "##  " at the beginning of every heading line
to make the important information easier to read.

Hope that helps,
Adam

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of B Smith
Sent: Wednesday, June 13, 2007 1:36 PM
To: wtr-general@rubyforge.org
Subject: [Wtr-general] Save results to file

Pls be patient. I just d/l'd Watir and am just starting...

I used this .rb from the tutorial of Watir ---------snippet
start------------------
require 'watir'   # the watir controller

   # set a variable
   test_site = 'http://www.google.com'
  
   # open the IE browser
   ie = Watir::IE.new

   # print some comments
   puts "## Beginning of test: Google search"
   puts "  "
  
   puts "Step 1: go to the test site: " + test_site
   ie.goto(test_site)
   puts "  Action: entered " + test_site + " in the address bar."

   puts "Step 2: enter 'pickaxe' in the search text field"
   ie.text_field(:name, "q").set("Beer + Bottle + Label")       # q is
the name of the search field
   puts "  Action: entered pickaxe in the search field"

   puts "Step 3: click the 'Google Search' button"
   ie.button(:name, "btnG").click   
# "btnG" is the name of the Search button
   puts "  Action: clicked the Google Search button."

   puts "Expected Result: "
   puts " - a Google page with results should be shown. 'Programming
Ruby' should be high on the list."
  
   puts "Actual Result: Check that the 'Programming Ruby' link appears
on the results page "
   if ie.contains_text("Programming Ruby")  
      puts "Test Passed. Found the test string: 'Programming Ruby'.
Actual Results match Expected Results."
   else
      puts "Test Failed! Could not find: 'Programming Ruby'" 
   end
   
   puts "  "
   puts "## End of test: Google search"
  ----------end snippet--------------

It opens the window and performs the search.

NOW...How do I save the text of the results to a file? I will eventually
want to save the results to a MySQL tble, but I'm trying baby steps to
learn the syntax.

Thanks,
B
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to