Skip to content

Instantly share code, notes, and snippets.

@brianjbayer
Last active January 9, 2022 19:50
Show Gist options
  • Save brianjbayer/ffa9b4fa9047e72653c775bd2a532884 to your computer and use it in GitHub Desktop.
Save brianjbayer/ffa9b4fa9047e72653c775bd2a532884 to your computer and use it in GitHub Desktop.
Using PhantomJS in Capybara RSpec (Historical)

Using PhantomJS in Capybara RSpec

Wood Fungus - Brian Bayer


Before there was headless Chrome and Firefox, there was the PhantomJS headless browser.

With the rise of headless Chrome and Firefox and lack of active contributors, PhantomJS development has been suspended since March 2018.

It is highly recommended to use headless Chrome and Firefox, particularly the SeleniumHQ-maintained Docker images instead of the legacy PhantomJS browser.

The PhantomJS browser requires the Poltergeist driver.

This gist documents using PhantomJS/Poltergeist in Capybara (RSpec) for historical reference.


PhantomJS in Capybara

To avoid having to download and manage the PhantomJS browser manually, use the phantomjs-helper gem.

Gemfile

The following is a minimal Capybara-RSpec Gemfile for using PhantomJS...

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'capybara'
gem 'phantomjs-helper'
gem 'poltergeist'
gem 'rspec'

spec-helper

The following is a minimal Capybara-RSpec spec-helper.rb for using PhantomJS...

# frozen_string_literal: true

require 'capybara'
require 'capybara/poltergeist'
require 'capybara/rspec'

Capybara.default_driver = :poltergeist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment