Capybara:Webkit无法找到iframe或其内容

gli*_*ana 8 javascript tdd ruby-on-rails cucumber capybara

我允许用户与其他人分享照片.当用户正在查看照片及其描述时,他们可以单击"共享"并加载新页面.在此页面上填写电子邮件地址(和可选注释 - 此处未测试),然后单击"共享照片".系统向收件人发送包含链接的电子邮件,主题行包括照片的名称.具有"共享"表单的页面还会显示已与其共享照片的个人列表.

整页加载是用户投诉的来源.他们想要一个模态窗口来快速加载和最小化导航.我同意.

我使用shadowbox.js将Share页面加载到模态窗口中的iframe中.它运行良好,如果需要,可以很好地回退到旧页面.

但是 - 我无法让我的测试通过.特别是,Capybara:Webkit就是找不到iframe.

环境是:Rail 3.0.9 capybara 0.4.1.2 capybara-webkit 0.5.0黄瓜1.0.2

黄瓜的故事:

Feature: Share photo

@javascript
Scenario: User shares photo
  When I follow "Share"
  Then I should see "Share Old Man Photo" inside "#sb-player"
  And I should see information about who I've shared this photo with
  When I fill in "Share with" with "joe@example.com"
  And I press "Share Photo"
  Then "joe@example.com" should receive an email with subject "Old Man photo has been shared with you"
Run Code Online (Sandbox Code Playgroud)

我的步骤:

Then %r{^I should see "([^"]*)" inside ([^"].*)$} do |expected_text, named_element|
  selector = element_for(named_element)
  within_frame selector do
    page.should have_content(expected_text)
  end
end
Run Code Online (Sandbox Code Playgroud)

失败消息:

(::) failed steps (::)

Unable to locate frame.  (Capybara::Driver::Webkit::WebkitError)
./features/step_definitions/sharing_steps.rb:94:in `/^I should see "([^"]*)" inside "([^"]*)"$/'
features/user_shares_photo.feature:21:in `Then I should see "Share Old Man Photo" inside "#sb-player"'

Failing Scenarios:
cucumber features/user_shares_photo.feature:19 
Run Code Online (Sandbox Code Playgroud)

我已经尝试了元素ID的每个组合.我只是不能让Capybara:Webkit识别iframe.

任何想法或解决方案?我不能提供失败的测试,我正在考虑推销整个iframe方法 - 但我想找到一个解决方案.

谢谢

gli*_*ana 6

需要添加时间以允许iframe打开/填充.睡5做了.

Then %r{^I should see "([^"]*)" inside ([^"].*)$} do |expected_text, named_element|
  sleep 5
  selector = element_for(named_element)
  within_frame selector do
    page.should have_content(expected_text)
  end
end
Run Code Online (Sandbox Code Playgroud)