require 'watir'
require 'watir/screen_capture'
include Watir::ScreenCapture
require 'win32ole'
def take_screenshot
randfname = Array.new(6) { (rand(122-97) + 97).chr }.join
begin
directory_name = File.dirname(__FILE__).gsub('/','\\') +
"\\screenshots\\#{$randdir}"
if FileTest::directory?(directory_name)
filename = "#{directory_name}\\#{randfname}.png"
screen_capture(filename,false, false)
else
Dir::mkdir(directory_name)
filename = "#{directory_name}\\#{randfname}.png"
screen_capture(filename,false, false)
end
end
end
Sunday, December 12, 2010
screen_capture Sample in Watir
This simple watir script will take a screenshot and save the to a random number filename.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment