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

后端 未结 5 767
天命终不由人
天命终不由人 2020-12-24 09:15

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

5条回答
  •  执笔经年
    2020-12-24 09:57

    The methods mentioned in this thread no longer work with Selenium Webdriver v3.

    You'll instead need to add a sleep to the execution command.

    module Selenium::WebDriver::Remote
      class Bridge
        def execute(command, opts = {}, command_hash = nil)
          verb, path = commands(command) || raise(ArgumentError, "unknown command: #{command.inspect}")
          path = path.dup
    
          path[':session_id'] = session_id if path.include?(':session_id')
    
          begin
            opts.each { |key, value| path[key.inspect] = escaper.escape(value.to_s) }
          rescue IndexError
            raise ArgumentError, "#{opts.inspect} invalid for #{command.inspect}"
          end
    
          Selenium::WebDriver.logger.info("-> #{verb.to_s.upcase} #{path}")
          res = http.call(verb, path, command_hash)
          sleep(0.1) # <--- Add your sleep here.
          res
        end
      end
    end
    

    Note this is a very brittle way to slow down the tests since you're monkey patching a private API.

提交回复
热议问题