Last active
July 11, 2018 10:51
-
-
Save antonyh/5338945b37b6b52a98f5 to your computer and use it in GitHub Desktop.
Various Selenium configurations for Capybara proxy
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
['capybara/poltergeist', 'capybara/webkit', 'selenium/webdriver'].each do |d| | |
begin | |
require d | |
rescue LoadError | |
end | |
end | |
if defined?(Capybara::Poltergeist) | |
Capybara.register_driver :poltergeist_proxy do |app| | |
options = { | |
phantomjs_options: [ | |
'--ignore-ssl-errors=yes', | |
"--proxy=#{CapybaraProxy.proxy.host}:#{CapybaraProxy.proxy.port}" | |
] | |
} | |
Capybara::Poltergeist::Driver.new(app, options) | |
end | |
end | |
if defined?(Capybara::Driver::Webkit) | |
Capybara.register_driver :webkit_proxy do |app| | |
driver = Capybara::Driver::Webkit.new(app) | |
driver.browser.set_proxy(:host => CapybaraProxy.proxy.host, | |
:port => CapybaraProxy.proxy.port) | |
driver.browser.ignore_ssl_errors | |
driver | |
end | |
end | |
if defined?(Selenium::WebDriver) | |
Capybara.register_driver :selenium_proxy do |app| | |
profile = Selenium::WebDriver::Firefox::Profile.new | |
profile.proxy = Selenium::WebDriver::Proxy.new( | |
:http => "#{CapybaraProxy.proxy.host}:#{CapybaraProxy.proxy.port}", | |
:ssl => "#{CapybaraProxy.proxy.host}:#{CapybaraProxy.proxy.port}") | |
Capybara::Selenium::Driver.new(app, :profile => profile) | |
end | |
if Selenium::WebDriver::Firefox::Profile.method_defined? :enable_firebug | |
Capybara.register_driver :selenium_proxy_with_firebug do |app| | |
profile = Selenium::WebDriver::Firefox::Profile.new | |
profile.proxy = Selenium::WebDriver::Proxy.new( | |
:http => "#{CapybaraProxy.proxy.host}:#{CapybaraProxy.proxy.port}", | |
:ssl => "#{CapybaraProxy.proxy.host}:#{CapybaraProxy.proxy.port}") | |
profile.enable_firebug | |
Capybara::Selenium::Driver.new(app, :profile => profile) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment