From e96d21ed7d2fce1d07fc381200d31919a2d93299 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 6 Feb 2014 12:08:15 +0100 Subject: integration test with en-EN language Tests fail on machines that default to other available languages. Also move setting capybara driver to be javascript driver into the BrowserIntegrationTest. --- test/test_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 3e301e7..1dff80a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,6 +43,11 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest include Capybara::DSL include IntegrationTestHelper + setup do + Capybara.current_driver = Capybara.javascript_driver + page.driver.add_headers 'ACCEPT-LANGUAGE' => 'en-EN' + end + teardown do Capybara.reset_sessions! # Forget the (simulated) browser state Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver -- cgit v1.2.3 From f13cfd635f9d0d089da10c1a2c9f4af5ff87cda8 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Feb 2014 11:27:47 +0100 Subject: log failing integration tests with screenshot * store the last screenshot in tmp * store the html and the end of the server log in tmp Filenames are build from the test class name and the tests name. --- test/test_helper.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 1dff80a..3fb2716 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -52,4 +52,39 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest Capybara.reset_sessions! # Forget the (simulated) browser state Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver end + + add_teardown_hook do |testcase| + unless testcase.passed? + testcase.save_state + end + end + + def save_state + page.save_screenshot screenshot_path + File.open(logfile_path, 'w') do |test_log| + test_log.puts self.class.name + test_log.puts "=========================" + test_log.puts __name__ + test_log.puts Time.now + test_log.puts current_path + test_log.puts page.status_code + test_log.puts page.response_headers + test_log.puts "page.html" + test_log.puts "------------------------" + test_log.puts page.html + test_log.puts "server log" + test_log.puts "------------------------" + test_log.puts `tail log/test.log -n 200` + end + end + + protected + + def logfile_path + Rails.root + 'tmp' + "#{self.class.name.underscore}.#{__name__}.log" + end + + def screenshot_path + Rails.root + 'tmp' + "#{self.class.name.underscore}.#{__name__}.png" + end end -- cgit v1.2.3