2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-19 11:50:42 -05:00
|
|
|
require "abstract_unit"
|
|
|
|
require "action_dispatch/system_testing/test_helpers/screenshot_helper"
|
2017-02-28 17:54:28 -05:00
|
|
|
require "capybara/dsl"
|
2019-01-30 02:40:01 -05:00
|
|
|
require "selenium/webdriver"
|
2016-11-06 18:55:15 -05:00
|
|
|
|
|
|
|
class ScreenshotHelperTest < ActiveSupport::TestCase
|
2017-01-22 14:05:51 -05:00
|
|
|
test "image path is saved in tmp directory" do
|
2017-03-06 12:33:34 -05:00
|
|
|
new_test = DrivenBySeleniumWithChrome.new("x")
|
2016-11-06 18:55:15 -05:00
|
|
|
|
2017-08-26 05:39:40 -04:00
|
|
|
Rails.stub :root, Pathname.getwd do
|
2018-02-27 08:49:38 -05:00
|
|
|
assert_equal Rails.root.join("tmp/screenshots/x.png").to_s, new_test.send(:image_path)
|
2017-08-26 05:39:40 -04:00
|
|
|
end
|
2017-02-19 12:12:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "image path includes failures text if test did not pass" do
|
2017-03-06 12:33:34 -05:00
|
|
|
new_test = DrivenBySeleniumWithChrome.new("x")
|
2017-02-19 12:12:06 -05:00
|
|
|
|
2017-08-26 05:39:40 -04:00
|
|
|
Rails.stub :root, Pathname.getwd do
|
|
|
|
new_test.stub :passed?, false do
|
2018-02-27 08:49:38 -05:00
|
|
|
assert_equal Rails.root.join("tmp/screenshots/failures_x.png").to_s, new_test.send(:image_path)
|
2017-08-26 05:39:40 -04:00
|
|
|
end
|
2017-02-19 12:12:06 -05:00
|
|
|
end
|
2016-11-06 18:55:15 -05:00
|
|
|
end
|
2017-02-23 08:30:01 -05:00
|
|
|
|
|
|
|
test "image path does not include failures text if test skipped" do
|
2017-03-06 12:33:34 -05:00
|
|
|
new_test = DrivenBySeleniumWithChrome.new("x")
|
2017-02-23 08:30:01 -05:00
|
|
|
|
2017-08-26 05:39:40 -04:00
|
|
|
Rails.stub :root, Pathname.getwd do
|
|
|
|
new_test.stub :passed?, false do
|
|
|
|
new_test.stub :skipped?, true do
|
2018-02-27 08:49:38 -05:00
|
|
|
assert_equal Rails.root.join("tmp/screenshots/x.png").to_s, new_test.send(:image_path)
|
2017-08-26 05:39:40 -04:00
|
|
|
end
|
2017-02-23 08:30:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-26 00:40:18 -04:00
|
|
|
|
2017-11-29 10:54:56 -05:00
|
|
|
test "defaults to simple output for the screenshot" do
|
|
|
|
new_test = DrivenBySeleniumWithChrome.new("x")
|
|
|
|
assert_equal "simple", new_test.send(:output_type)
|
|
|
|
end
|
|
|
|
|
2017-08-26 00:40:18 -04:00
|
|
|
test "display_image return artifact format when specify RAILS_SYSTEM_TESTING_SCREENSHOT environment" do
|
2018-12-20 12:44:01 -05:00
|
|
|
original_output_type = ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"]
|
|
|
|
ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"] = "artifact"
|
2017-08-26 00:40:18 -04:00
|
|
|
|
2018-12-20 12:44:01 -05:00
|
|
|
new_test = DrivenBySeleniumWithChrome.new("x")
|
2017-08-26 00:40:18 -04:00
|
|
|
|
2018-12-20 12:44:01 -05:00
|
|
|
assert_equal "artifact", new_test.send(:output_type)
|
2017-11-29 10:54:56 -05:00
|
|
|
|
2018-12-20 12:44:01 -05:00
|
|
|
Rails.stub :root, Pathname.getwd do
|
|
|
|
new_test.stub :passed?, false do
|
|
|
|
assert_match %r|url=artifact://.+?tmp/screenshots/failures_x\.png|, new_test.send(:display_image)
|
2017-08-26 00:40:18 -04:00
|
|
|
end
|
|
|
|
end
|
2018-12-20 12:44:01 -05:00
|
|
|
ensure
|
|
|
|
ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"] = original_output_type
|
2017-08-26 00:40:18 -04:00
|
|
|
end
|
2017-08-26 05:39:40 -04:00
|
|
|
|
2018-02-27 08:49:38 -05:00
|
|
|
test "image path returns the absolute path from root" do
|
2017-08-26 05:39:40 -04:00
|
|
|
new_test = DrivenBySeleniumWithChrome.new("x")
|
|
|
|
|
|
|
|
Rails.stub :root, Pathname.getwd.join("..") do
|
2018-02-27 08:49:38 -05:00
|
|
|
assert_equal Rails.root.join("tmp/screenshots/x.png").to_s, new_test.send(:image_path)
|
2017-08-26 05:39:40 -04:00
|
|
|
end
|
|
|
|
end
|
2017-03-06 12:33:34 -05:00
|
|
|
end
|
2017-02-28 17:54:28 -05:00
|
|
|
|
2017-03-06 12:33:34 -05:00
|
|
|
class RackTestScreenshotsTest < DrivenByRackTest
|
2017-02-28 17:54:28 -05:00
|
|
|
test "rack_test driver does not support screenshot" do
|
2017-03-06 12:33:34 -05:00
|
|
|
assert_not self.send(:supports_screenshot?)
|
2017-02-28 17:54:28 -05:00
|
|
|
end
|
2017-03-06 12:33:34 -05:00
|
|
|
end
|
2017-02-28 17:54:28 -05:00
|
|
|
|
2017-03-06 12:33:34 -05:00
|
|
|
class SeleniumScreenshotsTest < DrivenBySeleniumWithChrome
|
2017-02-28 17:54:28 -05:00
|
|
|
test "selenium driver supports screenshot" do
|
2017-03-06 12:33:34 -05:00
|
|
|
assert self.send(:supports_screenshot?)
|
2017-02-28 17:54:28 -05:00
|
|
|
end
|
2016-11-06 18:55:15 -05:00
|
|
|
end
|