我允许用户与其他人分享照片。当用户查看照片及其描述时,他们可以单击“共享”并加载新页面。在此页面上填写电子邮件地址(和可选的评论 - 未在此处测试)并单击“共享照片”。系统向收件人发送一封包含链接的电子邮件,主题行包含照片的名称。带有共享表单的页面还显示照片已与之共享的个人列表。
整页加载是用户投诉的一个来源。他们想要一个模态窗口来快速加载和最小化导航。我同意。
我使用 shadowbox.js将共享页面加载到模式窗口中的 iframe 中。它运行良好,并允许在需要时很好地回退到旧页面。
但是 - 我就是无法通过测试。特别是,Capybara:Webkit 无法找到 iframe。
环境是: 铁路 3.0.9 capybara 0.4.1.2 capybara -webkit 0.5.0 cucumber 1.0.2
cucumber 的故事:
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"
我的步骤:
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
失败信息:
(::) 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
我已经尝试了元素 ID 的所有组合。我就是无法让 Capybara:Webkit 识别 iframe。
有什么想法或解决方案吗?我无法通过失败的测试交付产品,并且正在考虑推销整个 iframe 方法 - 但我想找到一个解决方案。
谢谢
最佳答案
需要添加时间以允许 iframe 打开/填充。 Sleep 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
关于javascript - capybara :Webkit 无法找到 iframe 或其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6890364/