lib/rutl/camera.rb in rutl-0.6.0 vs lib/rutl/camera.rb in rutl-0.8.0
- old
+ new
@@ -25,17 +25,33 @@
FileUtils.mkdir_p @dir
end
def shoot(path = nil)
return if guard
+ file = prepare_shot(path)
+ cheese_already(file)
+ end
+ alias screenshot shoot
+
+ def prepare_shot(path = nil)
+ FileUtils.mkdir_p @dir
# Magic path is used for all auto-screenshots.
name = path || magic_path
+ File.join(@dir, pathify(name))
+ end
- FileUtils.mkdir_p @dir
- file = File.join(@dir, pathify(name))
- @driver.save_screenshot(file)
+ def cheese_already(file)
+ if @driver.respond_to?(:save_screenshot)
+ @driver.save_screenshot(file)
+ elsif @driver.respond_to?(:screenshot)
+ @driver.screenshot(file)
+ else
+ raise 'unknown screenshot method!'
+ end
+ rescue Selenium::WebDriver::Error::NoSuchWindowError
+ puts 'app closed; no photos, please'
+ # leave a zero length file as a sign that we came down this path
end
- alias screenshot shoot
def clean_dir(dir)
FileUtils.rm_rf dir
FileUtils.mkdir_p dir
end