lib/gnawrnip/screenshot.rb in gnawrnip-0.3.0 vs lib/gnawrnip/screenshot.rb in gnawrnip-0.3.1
- old
+ new
@@ -1,9 +1,8 @@
require 'time'
require 'capybara'
-require 'securerandom'
-require 'fileutils'
+require 'tempfile'
module Gnawrnip
class Screenshot
class << self
#
@@ -17,13 +16,12 @@
# So, to retry during +wait_second+ seconds.
#
# @example
# image = Gnawrnip::Screenshot.take
#
- #
# @param [Fixnum] wait_second Second to repeat the retry
- # @return [String] Image filename of screenshot
+ # @return [Tempfile] Image file of screenshot
#
def take(wait_second = Capybara.default_wait_time)
start_time = Time.now
begin
@@ -46,22 +44,16 @@
def session
Capybara.current_session
end
#
- # @return [Gnawrnip::Image]
+ # @return [Tempfile]
#
def shot
- path = filepath
-
- FileUtils.touch(path)
- session.save_screenshot(path)
-
- path
- end
-
- def filepath
- SCREENSHOT_OUTPUT_DIR + '/gnawrnip-' + SecureRandom.uuid + '.png'
+ Tempfile.open(['gnawrnip', '.png']) do |fp|
+ session.save_screenshot(fp.path)
+ fp
+ end
end
end
end
end