diff --git a/README.md b/README.md index 8abd790..cabd7fc 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ require 'billy/capybara/rspec' # select a driver for your chosen browser environment Capybara.javascript_driver = :selenium_billy # Uses Firefox +# Capybara.javascript_driver = :selenium_headless_billy # Uses Firefox in headless mode # Capybara.javascript_driver = :selenium_chrome_billy # Capybara.javascript_driver = :selenium_chrome_headless_billy # Capybara.javascript_driver = :apparition_billy diff --git a/lib/billy/browsers/capybara.rb b/lib/billy/browsers/capybara.rb index 66f16ea..dcdaa2d 100644 --- a/lib/billy/browsers/capybara.rb +++ b/lib/billy/browsers/capybara.rb @@ -47,12 +47,19 @@ def self.register_webkit_driver def self.register_selenium_driver ::Capybara.register_driver :selenium_billy do |app| - profile = Selenium::WebDriver::Firefox::Profile.new - profile.assume_untrusted_certificate_issuer = false - profile.proxy = Selenium::WebDriver::Proxy.new( - http: "#{Billy.proxy.host}:#{Billy.proxy.port}", - ssl: "#{Billy.proxy.host}:#{Billy.proxy.port}") - ::Capybara::Selenium::Driver.new(app, profile: profile) + options = build_selenium_options_for_firefox + capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true) + + ::Capybara::Selenium::Driver.new(app, options: options, desired_capabilities: capabilities) + end + + ::Capybara.register_driver :selenium_headless_billy do |app| + options = build_selenium_options_for_firefox.tap do |opts| + opts.add_argument '-headless' + end + capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true) + + ::Capybara::Selenium::Driver.new(app, options: options, desired_capabilities: capabilities) end ::Capybara.register_driver :selenium_chrome_billy do |app| @@ -84,6 +91,17 @@ def self.register_apparition_driver end end end + + def self.build_selenium_options_for_firefox + profile = Selenium::WebDriver::Firefox::Profile.new.tap do |prof| + prof.assume_untrusted_certificate_issuer = false + prof.proxy = Selenium::WebDriver::Proxy.new( + http: "#{Billy.proxy.host}:#{Billy.proxy.port}", + ssl: "#{Billy.proxy.host}:#{Billy.proxy.port}") + end + + Selenium::WebDriver::Firefox::Options.new(profile: profile) + end end end end