Poltergeist

Poltergeist es un driver para Capybara.

Nos permite ejecutar pruebas Capybara con un navegador WebKit 18.1headless, basado en PhantomJS.

Es posible ejectuar las pruebas del ejemplo anterior usando PhantomJS via Poltergeist cambiando el fichero features/support/env.rb:

[~/sinatra/sinatra-capybara/youtube(poltergeist)]$ cat features/support/env.rb 
require 'capybara/cucumber'
require 'capybara/poltergeist'

#Capybara.default_driver = :selenium
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, :js_errors => false)
end
Capybara.default_driver = :poltergeist
#Capybara.javascript_driver = :webkit

Es necesario poner el atributo :js_errors => false para evitar que los errores que se producen en JavaScript se propagen al código Ruby y causen que las pruebas se detengan.

Sigue una ejecución:

[~/sinatra/sinatra-capybara/youtube(poltergeist)]$ rake
cucumber
Feature: Search for Videos on YouTube

  Scenario: Search for Videos of Large Rodents # features/youtube_search.feature:3
Refused to display document because display forbidden by X-Frame-Options.

    Given I am on the YouTube home page        # features/step_defs/steps.rb:1
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/casiano/.rvm/gems/ruby-2.1.2/gems/poltergeist-1.5.1/lib/capybara/poltergeist/client/compiled/main.js. Domains, protocols and ports must match.

    When I search for "capybara"               # features/step_defs/steps.rb:5
    Then videos of large rodents are returned  # features/step_defs/steps.rb:10
      #<Capybara::Session>

1 scenario (1 passed)
3 steps (3 passed)
0m6.230s

Casiano Rodriguez León 2015-01-07