如何以较低的速度运行 Selenium(通过 Capybara 使用)?
默认情况下,Selenium 在我使用 Cucumber 定义的场景中尽可能快地运行。 我想将其设置为以较低的速度运行,以便我能够捕获该过程的视频。
我发现 Selenium::Client::Driver
的实例有一个 set_speed
方法。对应于 Java API。
如何获取 Selenium::Client::Driver
类的实例?我最多可以到达 page.driver
,但它会返回 Capybara::Driver::Selenium
的实例。
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
感谢 http://groups.google.com/group/ruby-capybara/msg/6079b122979ffad2 寻求提示。
请注意,这使用了 Ruby 的睡眠,因此有点不精确 - 但应该可以为您完成这项工作。此外,所有事情都会调用执行,因此这就是亚秒级等待的原因。中间步骤 - 等待准备就绪、检查字段、聚焦、输入文本 - 每次暂停。
在 features/support 目录中创建一个“throttle.rb”(如果使用 Cucumber)并填充:
然后,在步骤定义中,调用:
或:
要重置,调用:
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:
Then, in a step definition, call:
or:
To reset, call:
这将起作用,并且不那么脆弱(对于“less”的一些小值)
This will work, and is less brittle (for some small value of "less")
作为更新,该类中的执行方法不再可用。它现在只在这里:
module ::Selenium::WebDriver::Remote
我需要限制 IE 中的一些测试,这有效。
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.
此线程中提到的方法不再适用于 Selenium Webdriver v3。
相反,您需要向执行命令添加睡眠。
请注意,这是一种非常脆弱的减慢测试速度的方法,因为您正在对私有 API 进行猴子修补。
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.
Note this is a very brittle way to slow down the tests since you're monkey patching a private API.
我想减慢水豚测试套件中的页面加载速度,看看是否可以触发一些间歇性失败的测试。我通过创建一个 nginx 反向代理容器并将其放置在我的测试容器和我用作无头浏览器的 phantomjs 容器之间来实现这一点。使用 limit_rate 指令限制速度。它最终没有帮助我实现我的目标,但它确实有效,并且可能对其他人来说是一个有用的策略!
I wanted to slow down the page load speeds in my Capybara test suite to see if I could trigger some intermittently failing tests. I achieved this by creating an nginx reverse proxy container and sitting it between my test container and the phantomjs container I was using as a headless browser. The speed was limited by using the limit_rate directive. It didn't help me to achieve my goal in the end, but it did work and it may be a useful strategy for others to use!