Search code examples
phantomjscapybaratravis-cipoltergeist

Poltergeist Error on first Capybara Test - Travis


My test suite is using Capybara for feature testing with PhantomJS as the driver for headless testing. We have gotten both up and working on Travis for our CI suite, but we're still getting failures as the suite runs (it works perfectly locally). Upon further examination I have realized that it is always the first feature test to run that is failing, every time, regardless of the order (our tests are executed in a randomized order). After it fails it gives this error:

Capybara::Poltergeist::StatusFailError:
   Request to 'http://127.0.0.1:52455/#/login' failed to reach server, check DNS and/or server status
   # /home/travis/.rvm/gems/ruby-2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:351:in `command'
   # /home/travis/.rvm/gems/ruby-2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:34:in `visit'
   # /home/travis/.rvm/gems/ruby-2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/driver.rb:95:in `visit'
   # /home/travis/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.0/lib/capybara/session.rb:233:in `visit'
   # /home/travis/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.0/lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'

We are using version 1.9.0 for Poltergeist and 2.1.1 for PhantomJS. Every test that runs after this one work, even if they depend on this strategy to work (i.e. when testing authentication).

Has anybody encountered this issue / have any wisdom to share on it?


Solution

  • I ended up solving the issue by adding the following bit of code to spec/spec_helper.rb:

    config.before(:suite) do
      Capybara.current_driver = Capybara.javascript_driver
    end
    

    Which is my understanding will set all Capybara tests to default to the javascript driver from initialization of the test suite - which fixed the problem perfectly.