4
我不能讓水豚在許多集成測試中工作。水豚:: ElementNotFound:無法找到沒有webrat的xpath「/ html」
當我訪問某些網頁時,我得到了以下的html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
因此,當我嘗試使用have_content()
選擇,它提出了以下錯誤:
Failure/Error: page.should have_content("HELLO")
Capybara::ElementNotFound:
Unable to find xpath "/html"
一些我的應用程序的頁面我可以訪問很好,但其他一些我不能。甚至有一些網頁,在一些地方工作,而不是在別人:
require 'spec_helper'
describe HomeController do
it "shows the website description" do
visit root_path
puts page.html.length # ==> 108 (no html)
...
end
end
require 'spec_helper'
describe FlowsController do
it "should do stuff" do
visit root_path
puts page.html.length # ==> 4459, works even if the exact same one didn't work in home_controller_spec!
visit flows_path
puts page.html.length # ==> 3402, works
visit new_user_session_path
puts page.html.length # ==> 3330, works
within("form#new_user") do
fill_in 'Email', :with => '[email protected]'
fill_in 'Password', :with => 'password'
click_on 'Sign in'
end
puts page.html.length # ==> 108, No html
end
end
我this post看,這是在同一時間使用水豚和webrat時可能會出現錯誤。但是我沒有使用webrat可言,而我仍然得到錯誤...
這裏是我的Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'pg'
gem 'thin'
gem 'devise'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
# Add rspec for testing
group :test, :development do
gem "rspec-rails", "~> 2.0"
gem "capybara"
gem "factory_girl_rails"
end
gem 'jquery-rails'