How can I run Selenium (used through Capybara) at a lower speed? How can I run Selenium (used through Capybara) at a lower speed? selenium selenium

How can I run Selenium (used through Capybara) at a lower speed?


Thanks to http://groups.google.com/group/ruby-capybara/msg/6079b122979ffad2 for a hint.

Just a note that this uses Ruby's sleep, so it's somewhat imprecise - but should do the job for you. Also, execute is called for everything so that's why it's sub-second waiting. The intermediate steps - wait until ready, check field, focus, enter text - each pause.

Create a "throttle.rb" in your features/support directory (if using Cucumber) and fill it with:

require 'selenium-webdriver'module ::Selenium::WebDriver::Firefox  class Bridge    attr_accessor :speed    def execute(*args)      result = raw_execute(*args)['value']      case speed        when :slow          sleep 0.3        when :medium          sleep 0.1      end      result    end  endenddef set_speed(speed)  begin    page.driver.browser.send(:bridge).speed=speed  rescue  endend

Then, in a step definition, call:

set_speed(:slow)

or:

set_speed(:medium)

To reset, call:

set_speed(:fast)


This will work, and is less brittle (for some small value of "less")

require 'selenium-webdriver'module ::Selenium::WebDriver::Remote  class Bridge    alias_method :old_execute, :execute    def execute(*args)      sleep(0.1)      old_execute(*args)    end  endend


As an update, the execute method in that class is no longer available. It is now here only:

module ::Selenium::WebDriver::Remote

I needed to throttle some tests in IE and this worked.