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?

3
  • Welcome to Stack Overflow. Have you tried anything yet? Commented Oct 23, 2013 at 10:55
  • The only thing i see you are putting to the console is the title of the web page and the url. Read this : stackoverflow.com/questions/2777802/… Commented Oct 23, 2013 at 11:16
  • Do you need the puts to go to both the console and file? Or is just going to the file sufficient? Commented Oct 23, 2013 at 11:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.