加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 针对iframe内容的Rspec测试

发布时间:2020-12-16 23:21:20 所属栏目:百科 来源:网络整理
导读:我如何为iframe内容编写rspec测试?我的iframe看起来像 iframe src="/any url" name="Original" ... divtest /div/iframe 在iframe之间的任何内容,我想为该内容编写rspec测试用例.我能怎么做 ? 我如何使用rspec检查iframe中的“test”?我写下面但没有通过
我如何为iframe内容编写rspec测试?我的iframe看起来像
<iframe src="/any url" name="Original">
   ...
   <div>test </div>
</iframe>

在iframe之间的任何内容,我想为该内容编写rspec测试用例.我能怎么做 ?

我如何使用rspec检查iframe中的“test”?我写下面但没有通过

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读