如何为 Iframe 内容编写 rspec 测试?我的 iframe 看起来像
<iframe src="/any url" name="Original">
...
<div>test </div>
</iframe>
在 iframe 之间的任何内容中,我想为该内容编写 rspec 测试用例。我能怎么做 ?
如何使用 rspec 检查 iframe 中的“测试”?我写在下面但没有通过
page.should have_content("test")
错误如
Failure/Error: page.should have_content("test")
expected there to be content "test" in "Customize ....
我使用 capybara - 1.1.2 和 rspec - 2.11.0 和 rails 3.2.8
最佳答案
以下一个适用于 selenium 驱动程序,也可能适用于其他驱动程序,但不适用于 rack_test。
/index.html:
<!DOCTYPE html>
<html>
<body>
<h1>Header</h1>
<iframe src="/iframer" id='ident' name='pretty_name'></iframe>
</body>
</html>
/iframer.html:
<!DOCTYPE html>
<html>
<body>
<h3>Inner Header</h3>
</body>
</html>
规范:
visit "/"
page.should have_selector 'h1'
page.should have_selector 'iframe'
page.within_frame 'ident' do
page.should have_selector 'h3'
page.should have_no_selector 'h1'
end
page.within_frame 'pretty_name' do
page.should have_selector 'h3'
page.should have_no_selector 'h1'
end
关于ruby-on-rails - iframe 内容的 Rspec 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13249483/