How to define proxy in Capybara

Asked

Viewed 232 times

0

I need to perform my tests, but my work network uses a proxy. What better way to set this up within my env.Rb

Below follows my file configuration code "env.Rb"

require "selenium-webdriver"
require "capybara"
require 'capybara/cucumber'
require "rspec"
require 'site_prism'



Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    desired_capabilities: { accept_insecure_certs: false }

  )


end

Capybara.configure do |config|

  config.run_server = false
  config.default_driver = :selenium_chrome
  config.app_host = "http://www.google.com"



end

Capybara.current_session.driver.browser.agent.set_proxy("172.16.0.1", 80)

Capybara.default_max_wait_time = 20

Capybara.page.driver.browser.manage.window.maximize

Capybara.javascript_driver = :webkit

1 answer

0


You can pass the proxy on capabilities, it would look something like this:

Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    desired_capabilities: { accept_insecure_certs: false, proxy: Selenium::WebDriver::Proxy.new(http: "myproxyaddress:8080")}
  )
end

I noticed that using Chrome, I believe that the proxy capacity only works for Firefox.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.