gpt4 book ai didi

ruby-on-rails-4 - Capybara::Poltergeist 状态错误,无法访问服务器

转载 作者:行者123 更新时间:2023-12-04 12:29:49 25 4
gpt4 key购买 nike

我正在尝试在我的 Rails 4 应用程序上使用 Rspec/Capybara/Poltergeist 进行一些测试,安装了 Phantomjs(版本 2.2.1),但我总是收到此错误:

Failure/Error: visit(perfect_landing_page_path)

Capybara::Poltergeist::StatusFailError:

Request to 'http://127.0.0.1:49623/path' failed to reach server, check DNS and/or server status



我正在做的测试:
require 'rails_helper'

RSpec.feature 'Subscription', :type => :feature do

let!(:plan) { create(:plan) }
let!(:landing_page) { create(:landing_page) }

before(:each) { landing_page.default_plan = plan }

describe 'landing_page#perfect_show' do
scenario 'form display', js: true do
plan_2 = create(:plan)
plan_3 = create(:plan)
landing_page.plans << plan_2
landing_page.plans << plan_3
visit(perfect_landing_page_path)
expect(page).to have_css(".start-now", count: 3)
first(".start-now").click
expect(page).to have_css("#new_user")
end

end

end

我的 Gemfile 看起来像这样:
  gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
gem 'guard-rspec'

group :test do
gem 'database_cleaner'
gem 'capybara'
gem 'capybara-screenshot'
gem 'poltergeist'
gem 'selenium-webdriver'
gem 'shoulda-matchers', require: false
gem 'show_me_the_cookies'
end

我的 spec/support/capybara.rb 文件:
require 'capybara/rails'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'

require "capybara/poltergeist" # Add this line to require poltergeist
require 'selenium-webdriver'

Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {:js_errors => false, :default_max_wait_time => 30, :timeout => 30, phantomjs_options: [
'--load-images=no',
'--ignore-ssl-errors=true',
'--ssl-protocol=any']})
end

Capybara.register_driver :poltergeist_debug do |app|
Capybara::Poltergeist::Driver.new(app, :inspector => true)
end

Capybara.configure do |config|
config.javascript_driver = :poltergeist
config.ignore_hidden_elements = true
config.default_max_wait_time = 30
end

我的 spec_helper.rb 文件:
require 'capybara/rspec'

RSpec.configure do |config|

config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end

config.filter_run :focus
config.run_all_when_everything_filtered = true

以前有人遇到过这个问题吗?有没有人对此有解决方案?几天来,我一直在寻找网络上的头...
非常感谢。

PS:它在我 friend 的 mac(Yosemite 或 El Capitan)上运行良好,只是在我的不运行。

最佳答案

我在 CI (CodeShip) 中遇到了这个问题。

添加调用 bundle exec rake assets:precompile在设置命令的末尾似乎修复了它:

CodeShip CI 设置命令:

rvm use 2.3.4 --install
bundle install
export RAILS_ENV=test
bundle exec rake db:schema:load
bundle exec rake assets:precompile

每个@agbodike 也有一个白名单,但在 rails_helper.rb
config.before(:each, js: true) do
page.driver.browser.url_whitelist = ["127.0.0.1"]
end

关于ruby-on-rails-4 - Capybara::Poltergeist 状态错误,无法访问服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35743167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com