Capybara :: Poltergeist status error, could not get to the server

I try to run some tests with Rspec / Capybara / Poltergeist in my Rails 4 application, Phantomjs is installed (version 2.2.1), but I always get this error:

Error / Error: visit (perfect_landing_page_path)

Capybara :: Poltergeist :: StatusFailError:

The request http : //127.0.0.1-00-009623/path 'could not get to the server, check the DNS and / or server status

The test I'm working on:

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 

My gemfile looks like this:

  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 

My spec / support / capybara.rb file:

 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 

My spec_helper.rb file:

 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 

Has anyone encountered this problem before? Does anyone have a solution for this? I hit my head for several days looking on the Internet ... Thank you so much.

PS: it works fine on my other mac (Yosemite or El Capitan), just not on mine.

+6
source share
3 answers

I had the same problem and this was due to disabling a third-party script. You can prevent third-party scripts from loading using the blacklist. For instance:

 config.before(:each, js: true) do page.driver.browser.url_blacklist = ["http://use.typekit.net"] end 

will prevent any URL starting with http://use.typekit.net from being http://use.typekit.net for every test that uses the js driver. More information can be found at:

https://robots.thoughtbot.com/speed-up-javascript-capybara-specs-by-blacklisting-urls

Alternatively, you can use the whitelist:

 config.before(:each, js: true) do page.driver.browser.url_whitelist = ["127.0.0.1"] end 

which blocks all requests not up to 127.0.0.1

I placed the configuration in spec/feature_helper.rb to make sure that it was configured only for function specifications.

+1
source

I had this problem in CI (CodeShip).

Adding a call to bundle exec rake assets:precompile at the end of the configuration commands seemed to fix it:

CodeShip CI configuration commands:

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

There was also a whitelist on @agbodike, but in rails_helper.rb

 config.before(:each, js: true) do page.driver.browser.url_whitelist = ["127.0.0.1"] end 
+1
source

You can avoid this by preconfiguring the assets before testing. And the code:

 RSpec.configure do |config| config.before :all do ENV['PRECOMPILE_ASSETS'] ||= begin case self.class.metadata[:type] when :feature, :view STDOUT.write "Precompiling assets..." require 'rake' Rails.application.load_tasks Rake::Task['assets:precompile'].invoke STDOUT.puts " done." Time.now.to_s end end end end 

more details

0
source

All Articles