0

I am trying to test using poltergeist, but the browser is not shown when I run my tests.

This is my spec_helper.rb:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'rspec/page-regression'

require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
  #Capybara::Poltergeist::Driver.new(app, {debug: true, :timeout => 90})
  Capybara::Poltergeist::Driver.new(app, {debug: false, :default_wait_time => 30, :timeout => 90})
end
Capybara.javascript_driver = :poltergeist

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  # == Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  config.mock_with :rspec

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true
  # config.use_transactional_fixtures = false
  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  config.include Capybara::DSL
end

# from http://stackoverflow.com/questions/8524839/sending-rails-errors-to-rspec-output
# to output all errors to rspec output
ActionController::Base.class_eval do
  def rescue_action(exception)
    raise exception
  end
end

I don't know if I am correctly setting Capybara.javascript_driver.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
tardjo
  • 1,594
  • 5
  • 22
  • 38
  • 1
    Why do you want to use poltergeist if you want to see the browser? From the [webpage](https://github.com/jonleighton/poltergeist): "It allows you to run your Capybara tests on a headless WebKit browser". [Headless](http://en.wikipedia.org/wiki/Headless_computer) means "device that has been configured to operate without a monitor". – Shepmaster Nov 14 '13 at 01:01
  • sounds like 'working as intended'. – sevenseacat Nov 14 '13 at 01:08
  • It is beneficial sometimes to see the browser so that you can confirm what is gong wrong in a test. Yes you could inspect the DOM via console, and reassemble everything  — but that's tedious. Browser display is usually done via an ENV flag during the run – New Alexandria Nov 19 '16 at 17:47

1 Answers1

6

You won't see the browser. Poltergeist is for headless testing, this means it programmatically renders everything underneath, and programmatically processes interactions with the page.