Tuesday, July 15, 2008

How do I take screenshots and append to a Word file?



require 'watir'
   require 'win32ole'
   @@word=WIN32OLE.new('Word.Application')
   @@word.Documents.Add()
   def take_a_screenshot(url)
    @autoit = WIN32OLE.new("AutoItX3.Control")
    browser = Watir::IE.new
    browser.bring_to_front
    browser.goto(url)
    browser.maximize
    @autoit.Send("{PRINTSCREEN}")
    browser.close
    @@word.Selection.Paste
    @autoit.Send("{ENTER}")
  end
  
 def save_file
  @@word.ActiveDocument.SaveAs('C:\screenshots.doc')
  @@word.ActiveDocument.close
  @@word.Quit
 end

 take_a_screenshot('http://www.agiletester.co.uk')
 take_a_screenshot('http://www.fsf.org/')
 save_file


No comments: