0

I have a little test script to run in Watir that searches "books" on google images and then takes a screenshot of the result.

require "watir-webdriver"
browser = Watir::Browser.new :ie
browser.goto "http://www.google.com/"
puts browser.url
browser.a(:text => "Images").click
puts browser.title
browser.text_field(:name => "q").set "book"
browser.button(:value => "Search by image").click
browser.screenshot.save 'screenshots\search-results.png'
browser.close

However I would also like to include a log in a .txt file of the information I am "putting" into the console.

How would I go about doing this?

CustomNet
  • 732
  • 3
  • 12
  • 31

1 Answers1

4

To do this I used:

require "watir-webdriver"
require 'logger'
$log = Logger.new('logs\search-books.log')
$log.info("** TEST 1 - Search books on google images and screenshot results **")
browser = Watir::Browser.new :chrome
browser.goto "http://www.google.com/"
$log.info("** PAGE URL **")
$log.info browser.url
browser.a(:text => "Images").click
$log.info("** PAGE TITLE **")
$log.info browser.title
browser.text_field(:name => "q").set "book"
browser.button(:value => "Search by image").click
browser.screenshot.save 'screenshots\search-results.png'
browser.close

By using Logger it allows you to create a log file (.log) and insert into it as you go along the script.

CustomNet
  • 732
  • 3
  • 12
  • 31