mirror of https://github.com/rails/rails
Save failure screenshot path in test metadata
This commit is contained in:
parent
35a614c227
commit
a962fc3c9c
|
@ -313,7 +313,7 @@ GEM
|
|||
mini_magick (4.12.0)
|
||||
mini_mime (1.1.2)
|
||||
mini_portile2 (2.8.2)
|
||||
minitest (5.17.0)
|
||||
minitest (5.19.0)
|
||||
minitest-bisect (1.6.0)
|
||||
minitest-server (~> 1.0)
|
||||
path_expander (~> 1.1)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
* `ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper` saves the screenshot path in test metadata on failure.
|
||||
|
||||
*Matija Čupić*
|
||||
|
||||
* `ActionDispatch::Assertions#html_document` uses Nokogiri's HTML5 parser if it is available.
|
||||
|
||||
The HTML5 parser better represents what the DOM would be in a browser. Previously this test
|
||||
|
|
|
@ -42,7 +42,10 @@ module ActionDispatch
|
|||
#
|
||||
# +take_failed_screenshot+ is called during system test teardown.
|
||||
def take_failed_screenshot
|
||||
take_screenshot if failed? && supports_screenshot? && Capybara::Session.instance_created?
|
||||
return unless failed? && supports_screenshot? && Capybara::Session.instance_created?
|
||||
|
||||
take_screenshot
|
||||
metadata[:failure_screenshot_path] = absolute_image_path if Minitest::Runnable.method_defined?(:metadata)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -152,6 +152,24 @@ class ScreenshotHelperTest < ActiveSupport::TestCase
|
|||
assert_match %r|url=artifact://.+?tmp/screenshots/1_x\.png|, display_image_actual
|
||||
end
|
||||
|
||||
test "take_failed_screenshot persists the image path in the test metadata" do
|
||||
skip "Older versions of Minitest don't support test metadata." unless Minitest::Runnable.method_defined?(:metadata)
|
||||
|
||||
Rails.stub :root, Pathname.getwd do
|
||||
@new_test.stub :passed?, false do
|
||||
Capybara::Session.stub :instance_created?, true do
|
||||
@new_test.stub :save_image, nil do
|
||||
@new_test.stub :show, -> (_) { } do
|
||||
@new_test.take_failed_screenshot
|
||||
|
||||
assert_equal @new_test.send(:absolute_image_path), @new_test.metadata[:failure_screenshot_path]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "image path returns the absolute path from root" do
|
||||
Rails.stub :root, Pathname.getwd.join("..") do
|
||||
assert_equal Rails.root.join("tmp/screenshots/0_x.png").to_s, @new_test.send(:image_path)
|
||||
|
|
Loading…
Reference in New Issue