W3cubDocs

/Ruby on Rails 7.0

module ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper

Screenshot helper for system testing.

Public Instance Methods

take_failed_screenshot() Show source
# File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 44
def take_failed_screenshot
  take_screenshot if failed? && supports_screenshot? && Capybara::Session.instance_created?
end

Takes a screenshot of the current page in the browser if the test failed.

take_failed_screenshot is called during system test teardown.

take_screenshot() Show source
# File actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb, line 33
def take_screenshot
  increment_unique
  save_html if save_html?
  save_image
  puts display_image
end

Takes a screenshot of the current page in the browser.

take_screenshot can be used at any point in your system tests to take a screenshot of the current state. This can be useful for debugging or automating visual testing. You can take multiple screenshots per test to investigate changes at different points during your test. These will be named with a sequential prefix (or 'failed' for failing tests)

The screenshot will be displayed in your console, if supported.

The default screenshots directory is tmp/screenshots but you can set a different one with Capybara.save_path

You can set the RAILS_SYSTEM_TESTING_SCREENSHOT_HTML environment variable to save the HTML from the page that is being screenshotted so you can investigate the elements on the page at the time of the screenshot

You can set the RAILS_SYSTEM_TESTING_SCREENSHOT environment variable to control the output. Possible values are:

© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.