capybara_poltergeist_screenshot.rb 366B

12345678910111213
  1. require 'launchy'
  2. module Capybara
  3. module PoltergeistScreenshot
  4. def screenshot_and_open_image(full: false)
  5. timestamp = Time.now.strftime('%Y-%m-%d-%H-%M-%S')
  6. screenshot_path = "tmp/capybara/screenshot_#{timestamp}_#{SecureRandom.hex}.png"
  7. page.save_screenshot(screenshot_path, full: full)
  8. Launchy.open screenshot_path
  9. end
  10. end
  11. end