ruby-on-rails - iframe 内容的 Rspec 测试

标签 ruby-on-rails rspec ruby-on-rails-3.2 capybara

如何为 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/

相关文章:

ruby-on-rails - 为 Ruby On Rails 环境创建 Docker 镜像时出错(来自 Dockerfile)

ruby-on-rails - 在 ActiveAdmin 的 'Custom Page' 中呈现自定义编辑部分

ruby-on-rails - 如何将登录表单放在 Devise 和 Rails 的标题中

facebook - 有时 "The specified feature has been temporarily disabled for this application"

ruby-on-rails - 将html表的值提交给 Controller ruby中的变量

ruby-on-rails - rails 3.1 生成 CSV 文件

ruby - Capybara + RSpec, spec/features 目录被 rspec 忽略。命令?

ruby-on-rails - rspec 失败 "Missing host to link to!..."

ruby-on-rails - 在 Rails 中自动测试流程

ruby-on-rails - Ruby on Rails : How to undo nested_scaffold in rails