Create a gist now

Instantly share code, notes, and snippets.

Install Firebug for Capybara
# UPDATE: You are probably better off using jfirebaugh's gem.
# See https://github.com/jfirebaugh/capybara-firebug
# Set up Capybara to install Firebug in the default session.
#
# Download firebug.xpi from http://getfirebug.com/downloads and check it in.
# Set FirebugFix::ORIGINAL_XPI_PATH to its location.
require 'selenium/webdriver'
class FirebugFix
ORIGINAL_XPI_PATH = File.join(Rails.root, "features/support/firebug.xpi")
# Rejigger Firebug so the welcome page doesn't come up on launch
#
def self.generate_patched_xpi
tmp_name = "firebugfix-#{Time.now.utc.to_f}"
tmp_dir = "/tmp/#{tmp_name}"
xpi_path = "/tmp/#{tmp_name}.xpi"
script = <<-END
mkdir #{tmp_dir}
cd #{tmp_dir}
unzip '#{ORIGINAL_XPI_PATH}'
sed -i '' -e 's/currentVersion", ""/currentVersion", "99"/' defaults/preferences/firebug.js
zip -r #{xpi_path} *
END
`#{script}`
raise "Failed to generate firebug.xpi" if $? != 0
xpi_path
end
end
Capybara.register_driver :selenium do |app|
patched_xpi = FirebugFix.generate_patched_xpi
profile = Selenium::WebDriver::Firefox::Profile.new
profile.add_extension patched_xpi
Capybara::Driver::Selenium.new app, :profile => profile
end
# This code is dedicated to the public domain using a CC0 license.
# http://creativecommons.org/publicdomain/zero/1.0/
@jfirebaugh

Thanks for this. I figured out how to set up the profile in a way that doesn't require repackaging firebug, and released it as a gem: https://github.com/jfirebaugh/capybara-firebug

@wrs
Owner
wrs commented Mar 10, 2011

Thanks John! I've switched to your gem and it's working fine.

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