save_and_open_page无法与capybara 2.0一起使用吗? [英] save_and_open_page not working with capybara 2.0?

查看:81
本文介绍了save_and_open_page无法与capybara 2.0一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将水豚更新为2.0,并且我所有的save_and_open_page调用都返回一个没有样式的html页面。它的样式表链接正确位于页面顶部。当我恢复到水豚1.3时,样式再次起作用。任何人都知道如何解决此问题和/或问题是什么?


谢谢,
戴夫




更新1。 b Capybara Webkit问题
指向: capybara-screenshot


它涉及使用capybara截屏的gem来获取页面外观的屏幕截图。将其与生成html的save_and_open_page结合使用时,您可以看到它的外观并查看HTML。

  save_and_open_page 
Capybara :: Screenshot.screenshot_and_open_image

如果我能得到 Capybara :: Screenshot.screenshot_and_save_page 起作用,那么我认为我可能有解决方案(如果名称表示我认为确实可以采取的措施)。但是,当我尝试时,我得到无法加载此类文件-capybara / util / save_and_open_page




更新2。


!请稍等,screenshot_and_open_image现在不起作用(未创建或显示png图像)。 !!




更新3。


测试应用程序:


我创建了一个测试应用程序,并将其发布在Github上的 test_capybara_screenshot 上。

>

当我在开发中运行此测试应用程序时,该页面显示了耀眼的红色背景样式。当我运行测试时,唯一对我有用的是save_and_open_page,除了没有样式。


注意,当我运行任何测试时,都会收到以下警告:


警告:Nokogiri是针对2.7.8的LibXML构建的,但已动态加载2.7.3


rspec测试的详细信息:



  • save_and_open_page带有无聊的白色背景(没有

  • screenshot_and_open_image返回以下错误:



机架::测试水豚驱动程序无法输出屏幕截图。跳过。


打开失败/~/Documents/experiments/test_capybara_screenshot/tmp/capybara/screenshot-2012-11-26-07-48-29.png带有选项{}:否找到的应用程序可以处理'/~/Documents/experiments/test_capybara_screenshot/tmp/capybara/screenshot-2012-11-26-07-48-29.png'




  • screenshot_and_save_page返回:



后钩异常发生


LoadError:无法加载此类文件-capybara / util / save_and_open_page
发生在~/.rvm/gems/ruby-1.9.3-p125@global/gems/activesupport-3.2。 6 / lib / active_support / dependencies.rb:251:in`require'





解决方案

经过一些博客浏览和挖掘,我能够解决save_and_open_page的问题。我从项目中删除了capybara_screenshot宝石。您可以在 github test_capybara_screenshot存储库上看到我的工作代码。我发现的解决方案使用了一些我在 capybara github网站上找到的指针。 / p>

假设:




  • 您正在使用rspec进行测试。

  • 您的应用已配置为使用资产管道。



我要做的第一件事就是设置它以便将资产预编译到测试目录中。为此,我将以下代码添加到 RSpec.configure 循环内的 spec / spec_helper.rb 文件中: / p>

  config.before(scope =:suite)do 
%x [捆绑执行耙资产:预编译]
end

我在配置中指定资产的预编译位置/environments/test.rb 文件:

  config.assets.prefix = assets_test#个位置测试public / assets_test目录中的资产
config.action_controller.asset_host = file://#{:: Rails.root} / public

这使得测试资产独立于开发资产,并且仅在测试套件运行期间生成。



如果执行此操作,则可能需要让git忽略 / public / assets * 目录。


I just had my capybara updated to 2.0, and all of my save_and_open_page calls return an html page without styling. It has the style sheets links properly at the top of the page. When I revert back to capybara 1.3, the styles work again. Anyone know how to fix this, and/or what the problem is?

thanks, Dave


Update 1.

hack:

I have found a reasonable way to get around the problem following the links recommended by simonmorley: Capybara Webkit problem which points to: capybara-screenshot

It involves using the capybara-screenshot gem to get a screenshot of what the page looks like. When you combine it with the save_and_open_page, which generates the html, you can see what it looks like, and see the HTML.

    save_and_open_page
    Capybara::Screenshot.screenshot_and_open_image

If I could get Capybara::Screenshot.screenshot_and_save_page to work, then I think that I might have a solution (if the name implies the action I think it does). However, when I try it, I get cannot load such file -- capybara/util/save_and_open_page


Update 2.

!! wait, the screenshot_and_open_image is not working now (no png image created or displayed). !!


Update 3.

Test App:

I created a test app, and posted it at test_capybara_screenshot on Github.

When I run this test app in development, the page come up with the blaring red background style displayed. When I run the tests, the only thing that works for me is the save_and_open_page, except there is no styling.

Note, when I run any tests, I get the following warning:

WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3

Details of the rspec test:

  • The save_and_open_page comes up with a boring white background (no styling).
  • the screenshot_and_open_image returns with the error:

Rack::Test capybara driver has no ability to output screen shots. Skipping.

Failure in opening /~/Documents/experiments/test_capybara_screenshot/tmp/capybara/screenshot-2012-11-26-07-48-29.png with options {}: No application found to handle '/~/Documents/experiments/test_capybara_screenshot/tmp/capybara/screenshot-2012-11-26-07-48-29.png'

  • The screenshot_and_save_page returns:

An error occurred in an after hook

LoadError: cannot load such file -- capybara/util/save_and_open_page occurred at ~/.rvm/gems/ruby-1.9.3-p125@global/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'


解决方案

I was able to fix the problem with save_and_open_page after some blog browsing and digging. I have dropped the capybara_screenshot gem from my project. You can see my working code on my github test_capybara_screenshot repository. The solution that I figured out uses some pointers that I found on the capybara github site.

Assumptions:

  • You are using rspec for testing.
  • Your app is already configured for using the asset pipeline.

The first thing that I do is set it up so that assets are precompiled into a test directory. I do this by adding the following code into the spec/spec_helper.rb file within the RSpec.configure loop:

config.before (scope = :suite) do
  %x[bundle exec rake assets:precompile]
end

I specify where the assets are pre-compiled to in the config/environments/test.rb file:

config.assets.prefix = "assets_test"    # place test assets in public/assets_test directory
config.action_controller.asset_host = "file://#{::Rails.root}/public"

This makes it so that the test assets are independent of the development assets, and are only generated during a test suite run.

If you do this, you will probably want to have git ignore the /public/assets* directories.

这篇关于save_and_open_page无法与capybara 2.0一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆