Taking Screenshots In Selenium Using Ruby

I LOVE being able to take screenshots of my Selenium tests as they are running!

Here’s how I take screenshots of my selenium tests running, written in Ruby:

  • Find the variable referencing the selenium driver. Might look something like this:
    @selenium_driver = Selenium::Client::Driver.new(.....
  • Wait for condition to take screenshot. Example:
    page.wait_for_element("//h1", {:timeout_in_seconds => 10})
  • Take screenshot. Example:
    @selenium_driver.capture_entire_page_screenshot(File.expand_path(File.dirname(__FILE__)) + 'screenshot1.png', '')

    or something simpler like:

    @selenium_driver.capture_entire_page_screenshot('~/Desktop/screenshot1.png', '')

Selenium documentation for using the capture screenshot function.

Published by

MikeGrace

I am a Geek! I hope you enjoyed this recent post.