mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow setting a custom path to store the System Test screenshots
Now ScreenshotHelper.take_screenshot uses the Capybara.save_path value as directory to store the screenshots if defined
This commit is contained in:
parent
84643885cf
commit
6b5ef23d22
2 changed files with 20 additions and 2 deletions
|
@ -15,8 +15,11 @@ module ActionDispatch
|
|||
#
|
||||
# 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 screenhoted so you can investigate the
|
||||
# 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
|
||||
|
@ -76,7 +79,11 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def absolute_path
|
||||
Rails.root.join("tmp/screenshots/#{image_name}")
|
||||
Rails.root.join(screenshots_dir, image_name)
|
||||
end
|
||||
|
||||
def screenshots_dir
|
||||
Capybara.save_path.presence || "tmp/screenshots"
|
||||
end
|
||||
|
||||
def absolute_image_path
|
||||
|
|
|
@ -36,6 +36,17 @@ class ScreenshotHelperTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "image path uses the Capybara.save_path to set a custom directory" do
|
||||
original_save_path = Capybara.save_path
|
||||
Capybara.save_path = "custom_dir"
|
||||
|
||||
Rails.stub :root, Pathname.getwd do
|
||||
assert_equal Rails.root.join("custom_dir/0_x.png").to_s, @new_test.send(:image_path)
|
||||
end
|
||||
ensure
|
||||
Capybara.save_path = original_save_path
|
||||
end
|
||||
|
||||
test "image path includes failures text if test did not pass" do
|
||||
Rails.stub :root, Pathname.getwd do
|
||||
@new_test.stub :passed?, false do
|
||||
|
|
Loading…
Reference in a new issue