Last active
December 1, 2016 14:57
-
-
Save tokland/173ea9c2e4f14e4e1a85237b47e0194c to your computer and use it in GitHub Desktop.
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
require 'capybara' | |
# $ xvfb-run rspec -f documentation chrome-extension_spec.rb | |
# | |
# ./myext -- Directory containing the unpacked extension | |
class ChromeBrowser | |
include Capybara::DSL | |
def initialize(chrome_flags = {}) | |
Capybara.register_driver :selenium_chrome do |app| | |
chrome_opts = chrome_flags.map do |arg, value| | |
case value | |
when true | |
"--#{arg}" | |
when false | |
nil | |
else | |
"--#{arg}=#{value}" | |
end | |
end.compact | |
Capybara::Selenium::Driver.new(app, browser: :chrome, switches: chrome_opts) | |
end | |
Capybara.current_driver = :selenium_chrome | |
end | |
end | |
describe "Chrome with extension <myext> installed" do | |
let(:browser) do | |
ChromeBrowser.new("user-data-dir" => ".myext-profile", "load-extension" => "myext") | |
end | |
describe "visiting page" do | |
before(:all) { browser.visit("http://someurl") } | |
it "adds a link (example)" do | |
expect(browser.find("a#link_added_my_content_script")).to be_truthy | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment