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

ruby-on-rails – Capybara :: ElementNotFound:无法在没有webr

发布时间:2020-12-17 02:36:57 所属栏目:百科 来源:网络整理
导读:我不能让Capybara在我的许多集成测试中工作. 当我访问某些页面时,我得到以下html: !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd" 因此,当我尝试使用has_content()选择器时,它会引发以下错误
我不能让Capybara在我的许多集成测试中工作.

当我访问某些页面时,我得到以下html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

因此,当我尝试使用has_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@example.com'
      fill_in 'Password',:with => 'password'
      click_on 'Sign in'
    end
    puts page.html.length # ==> 108,No html
  end
end

我在this post中读到,这是在同时使用Capybara和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'

解决方法

尝试传递一个String来描述,而不是Controller类

describe "whatever" do
  ...
end

(编辑:李大同)

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

    推荐文章
      热点阅读