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

Ability to specify a proxy for each driver #46

Closed
Cruikshanks opened this issue Nov 28, 2016 · 3 comments
Closed

Ability to specify a proxy for each driver #46

Cruikshanks opened this issue Nov 28, 2016 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Cruikshanks
Copy link
Member

We have found that in some build environments access to the internet is provided by a proxy. Therefore for Quke to work we need to be able to tell PhantomJS and Selenium what the address and port for the proxy server is.

@Cruikshanks Cruikshanks added the enhancement New feature or request label Nov 28, 2016
@Cruikshanks Cruikshanks self-assigned this Nov 28, 2016
@Cruikshanks
Copy link
Member Author

Have found some examples of how to do this

http://stackoverflow.com/a/6595850/6117745

Capybara.register_driver :selenium do |app|
    profile = Selenium::WebDriver::Firefox::Profile.new

    profile["network.proxy.type"] = 1 # manual proxy config
    profile["network.proxy.http"] = "http://example.com"
    profile["network.proxy.http_port"] = 80

    Capybara::Selenium::Driver.new(app, :profile => profile)
end

https://gist.github.com/antonyh/5338945b37b6b52a98f5

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

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

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 

http://www.rubydoc.info/gems/selenium-webdriver/0.0.28/Selenium%2FWebDriver%2FFirefox%2FProfile%3Ainitialize

profile = Selenium::WebDriver::Firefox::Profile.new
profile['network.proxy.http'] = 'localhost'
profile['network.proxy.http_port'] = 9090

driver = Selenium::WebDriver.for :firefox, :profile => profile

Cruikshanks added a commit that referenced this issue Nov 28, 2016
This change adds support to **Quke** to specify a proxy server when using the **PhantomJS** and **Selenium** based drivers (in **Quke's case *chrome* and *firefox*).

The reasoning is that connection to the internet may be been setup to go via a proxy server for security purposes in some build environments. With no way currently to tell **Quke** this is means it cannot be used if this is the case.

This new feature relates to issue #46.
@Cruikshanks
Copy link
Member Author

For future reference when it comes to figuring out what options you can pass to chrome it essentially appears to be this list http://peter.sh/experiments/chromium-command-line-switches

You can pass them in as an array with the switches tag for example

Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    switches: ["--proxy-server=localhost:8080"]
)

Got this inspiration when I found this https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#chrome

@Cruikshanks
Copy link
Member Author

This was resolved #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant