Dip*_*hal 6 rspec ruby-on-rails capybara ruby-on-rails-3.2
我如何为iframe内容编写rspec测试?我的iframe看起来像
<iframe src="/any url" name="Original">
...
<div>test </div>
</iframe>
Run Code Online (Sandbox Code Playgroud)
在iframe之间的任何内容,我想为该内容编写rspec测试用例.我能怎么做 ?
我如何使用rspec检查iframe中的"test"?我写下面但没有通过
page.should have_content("test")
Run Code Online (Sandbox Code Playgroud)
错误就像
Failure/Error: page.should have_content("test")
expected there to be content "test" in "Customize ....
Run Code Online (Sandbox Code Playgroud)
我使用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>
Run Code Online (Sandbox Code Playgroud)
/iframer.html:
<!DOCTYPE html>
<html>
<body>
<h3>Inner Header</h3>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
规格:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3508 次 |
| 最近记录: |