Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scmx/c577d20ac6ac39c8e36d63b6591749a8 to your computer and use it in GitHub Desktop.
Save scmx/c577d20ac6ac39c8e36d63b6591749a8 to your computer and use it in GitHub Desktop.
Capybara Selenium WebDriver running at a lower speed using sleep command #capybara #selenium #rails #

Capybara Selenium WebDriver running at a lower speed using sleep command

Ever wanted to run your integration/end-to-end test suite at a lower speed so that you better could observe what's happening and perhaps make a recording of it?

Here's a a technique I've been using when writing tests with Capybara Selenium WebDriver.

Put this in test/test_helper.rb or maybe something like spec/support/capybara.rb.

# For running Selenium at a lower speed
# Very useful when recording test runs
# https://stackoverflow.com/a/46840590/2037928
if ENV["SLOW"].present?
  require "selenium-webdriver"
  module ::Selenium::WebDriver::Remote
    class Bridge
      alias old_execute execute

      def execute(*args)
        sleep(0.1)
        old_execute(*args)
      end
    end
  end
end

Then set the SLOW=1 environment variable whenever you want to run your tests in slow motion. For example:

  • SLOW=1 rails test test/system
  • SLOW=1 rspec spec/features

Then if you want to make a recording to GIF I'd recommend LICEcap https://www.cockos.com/licecap/ which I've been using for years now.


Thanks to Ken Mayer for this solution on StackOverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment