Last active
July 11, 2020 17:23
-
-
Save tychobrailleur/5712504 to your computer and use it in GitHub Desktop.
Capybara/Selenium/Firefox/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
require 'capybara/firebug' | |
# Disable Webmock if needed. | |
WebMock.disable_net_connect!(allow_localhost: true) | |
# Same thing for VCR if it has been imported somewhere. | |
VCR.configure do |c| | |
c.ignore_localhost = true | |
end | |
ENV['NO_PROXY'] = ENV['no_proxy'] = '127.0.0.1' | |
Capybara.app_host = 'http://127.0.0.1:3000' | |
Capybara.server_port = 3000 | |
Capybara.default_driver = :selenium | |
Capybara.default_selector = :css | |
Capybara.default_wait_time = 10 | |
Capybara.register_driver :selenium do |app| | |
# Use an existing profile | |
profile = Selenium::WebDriver::Firefox::Profile.new('/path/to/Firefox/Profiles/blahblah.test') | |
profile.enable_firebug | |
# Configure proxy manually. | |
profile["network.proxy.type"] = 1 | |
# Auto-detect proxy = 4 | |
# No proxy = 3 | |
# Use system proxy settings = 5 | |
profile["network.proxy.http"] = 'localhost' | |
profile["network.proxy.http_port"] = 3128 | |
Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile) | |
end | |
# Uncomment to run against standalone server. | |
#Capybara.run_server = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my code that works in July 2020:
Unfortunately, I realize I need to get proxy working with username and password (like @tchret), which has been a headache.
Does anyone know how to do this on either Chrome/Chromedriver or on Firefox/geckodriver? On Firefox, I believe it involves downloading an extension, and setting username/password through that. I was unable to fill out the popup username/password prompt through Capybara