문제

We are just migrating from capybara-webkit to Poltergeist. Previously we did use capybara-webkit with puffing billy as you can see here:

def use_proxy_with_vcr cassettes_name = nil, cassettes_options = {}
  page.driver.browser.set_proxy(:host => Billy.proxy.host, :port => Billy.proxy.port)
  page.driver.browser.ignore_ssl_errors
  Billy.proxy.strategy.use_cassette cassettes_name, cassettes_options
  yield
  Billy.proxy.strategy.reset
  page.driver.browser.clear_proxy
end

This happens on runtime and I would like to do the same thing with Poltergeist. I realized one could set a proxy and ignore ssl errors by passing CLI options through capybara driver setup with phantomjs_options (https://github.com/jonleighton/poltergeist#customization).

Is it possible to enable/disable proxy and ssl errors during runtime? If yes how?

도움이 되었습니까?

해결책

It is not possible to disable/enable phantomjs options during runtime through poltergeist (though IIRC it is possible in general, so that feature could be added to poltergeist).

I think the easiest way to achieve this would be to register a new Capybara driver. E.g.

Capybara.register_driver :proxied_poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, phantomjs_options: [...])
end

You can then use the driver where applicable by setting Capybara.current_driver = :proxied_poltergeist. This will launch a separate phantomjs instance with the CLI options you specify.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top