Capybara-webkit:在测试期间禁用iframe加载

时间:2014-08-19 13:10:02

标签: ruby-on-rails ruby-on-rails-3 iframe capybara capybara-webkit

我正在测试一个包含各种嵌入式YouTube视频的网页。 Capybara-webkit加载和测试该页面的速度极慢,因此我需要禁用该页面的iframe加载。

iframe看起来像这样:

<iframe class="embedly-embed" src="//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2FKxu2A7-uBus%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKxu2A7-uBus&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FKxu2A7-uBus%2Fhqdefault.jpg&amp;key=7c4c130437b3403ab254d76c5015b5a5&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" scrolling="no" frameborder="0" allowfullscreen=""></iframe>

我尝试了两种方法:

将网址列入黑名单

Capybara.register_driver :webkit do |app|
  # Disabling useless resources loading from capybara
  driver = Capybara::Webkit::Driver.new(app)
  driver.browser.url_blacklist = [
    '//cdn.embedly.com/*',
    '//cdn.embedly.com/widgets/*',
    'http://cdn.embedly.com/widgets/*'
  ]
  driver
end

将所有iframe设置为display: none;

(在application.html.erb中)

<% if Rails.env.test? %>
  <style>iframe {display:none}</style>
<% end %>

他们都失败了......

有什么想法吗?

0 个答案:

没有答案