如何以较低的速度运行Selenium(通过Capybara使用)? [英] How can I run Selenium (used through Capybara) at a lower speed?

查看:176
本文介绍了如何以较低的速度运行Selenium(通过Capybara使用)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Selenium通过使用Cucumber定义的方案尽可能快地运行。
我想将其设置为以较低的速度运行,因此我可以捕获该进程的视频。

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.

我想出一个实例 Selenium :: Client :: Driver 有一个 set_speed 方法。其对应于 Java API

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

如何获取 Selenium :: Client ::驱动程序 class?我可以得到 page.driver ,但返回一个 Capybara :: Driver :: Selenium 的实例。

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.

推荐答案

感谢 http://groups.google.com/group/ruby-capybara/msg/6079b122979ffad2 提示。

只需注意,使用Ruby的睡眠,所以它有点不精确 - 但应该为你做的工作。此外,为所有的事情调用execute,这就是为什么它的秒级等待。

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.

在功能/支持目录中创建一个throttle.rb(如果使用的话) Cumbling]并填写:

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)

set_speed(:medium)

要重置,请调用:

set_speed(:fast)

这篇关于如何以较低的速度运行Selenium(通过Capybara使用)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆