Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Selenium headless driver #272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 24 additions & 6 deletions lib/billy/browsers/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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