lib/capy.rb in capy-1.4.2 vs lib/capy.rb in capy-1.4.3
- old
+ new
@@ -148,10 +148,15 @@
def capybara(script)
instance_eval script
end
+ def save_screenshot(png_path = nil)
+ png_path = gen_uniq_file_name('png') unless png_path
+ browser.save_screenshot(png_path)
+ end
+
def driver
page.driver
end
def browser
@@ -162,8 +167,24 @@
Capybara.app_host = app_host
end
def stop
Capy.start_shell(self)
+ end
+
+ private
+
+ def gen_uniq_file_name(extension)
+ file_name = Time.now.to_s
+ i = 2
+ while File.exists?("#{file_name}.#{extension}")
+ file_name = if file_name =~ /\(\d+\)$/
+ file_name.sub(/\(\d+\)$/, i.to_s)
+ else
+ file_name + " (#{i})"
+ end
+ i += 1
+ end
+ "#{file_name}.#{extension}"
end
end
end