Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

By default Selenium runs as fast as possible through the scenarios I defined using Cucumber. I would like to set it to run at a lower speed, so I am able to capture a video of the process.

I figured out that an instance of Selenium::Client::Driver has a set_speed method. Which corresponds with the Java API.

How can I obtain an instance of the Selenium::Client::Driver class? I can get as far as page.driver, but that returns an instance of Capybara::Driver::Selenium.

like image 277
mlangenberg Avatar asked Jan 27 '11 11:01

mlangenberg


People also ask

How do I slow down selenium Webdriver execution in Python?

If you are looking to slow down or pause your execution, press F8 (if you are using chrome).

What is Rspec capybara?

Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language. Capybara.


1 Answers

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
  end
end

def set_speed(speed)
  begin
    page.driver.browser.send(:bridge).speed=speed
  rescue
  end
end

Then, in a step definition, call:

set_speed(:slow)

or:

set_speed(:medium)

To reset, call:

set_speed(:fast)
like image 86
delitescere Avatar answered Oct 12 '22 08:10

delitescere