Created
February 14, 2011 01:00
-
-
Save wrs/825357 to your computer and use it in GitHub Desktop.
Install Firebug for Capybara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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/ |
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
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