Turn off screenshots in Rails system tests

Viewed 1300

I'm using system tests in Rails 5.1, and I'd like to turn off the automated screenshots for failure cases. Usually the failure message is plenty for me to figure out what's going on — and notably, the webdriver browser window always takes focus in order to take a screenshot, which is annoying when I'm working on the code (or trying to do anything else).

Is there a built in way in Capybara configuration to turn off screenshots? I looked through the docs and couldn't find anything stated explicitly, but since this is a new-ish addition to mainstream Rails, I figure that doesn't necessarily mean it doesn't exist.

3 Answers

I think it is more elegant to override supports_screenshot? method, In my case I wanted to disable screenshots on Heroku CI

 class ApplicationSystemTestCase < ActionDispatch::SystemTestCase


   private

   # disable only on CI, i.e: HEROKU CI
   def supports_screenshot?
    return false if ENV['CI'] 
    super
   end

   # to disable screenshots completely on every test invironment (local, CI)
   def supports_screenshot?
    false
   end

end
Related