diff options
author | Azul <azul@leap.se> | 2014-02-07 11:27:47 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2014-02-07 11:27:47 +0100 |
commit | f13cfd635f9d0d089da10c1a2c9f4af5ff87cda8 (patch) | |
tree | a79a186a9f302482a0fb7eb626649de99de5adb5 | |
parent | d8aa92f9d4911e28c95e9abb70e87ac282ef0601 (diff) |
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.
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | test/test_helper.rb | 35 |
2 files changed, 37 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml index 232467c..3bd8ba1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,5 @@ before_script: - "bundle exec rake couchrest:migrate_with_proxies" - "bundle exec rake couchrest:migrate_with_proxies" # looks like this needs to run twice - "mv test/config/couchdb.yml.user config/couchdb.yml" +after_script: + - "cat tmp/*.test*.log" # printing logs from the failed integration tests 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 |