Using Poltergeist with a Proxy

VCRProxy: Record PhantomJS ajax calls with VCR inside Capybara

So I did some research and now I have a very basic example of a working VCR proxy server, that handles HTTPS calls as a MITM proxyserver (if you deactivate the security check in your client). I would be very happy if someone could contribute and help me to bring this thing to life.

Here is the github repo: https://github.com/23tux/vcr_proxy

PhantomJS, Capybara, Poltergeist failed to reach server

Sounds like your production environment needs to make outbound connections through a socks5 proxy, and your other environments don't. You'll need to make the configuration dependent on environment

Capybara.register_driver :polt do |app|
phantomjs_options = ['--ignore-ssl-errors=yes', '--ssl-protocol=any', '--load-images=no']
phantomjs_options.push('--proxy=localhost:9050', '--proxy-type=socks5') if Rails.env.production?
Capybara::Poltergeist::Driver.new(
app,
js_errors: false, # break on js error
timeout: 180, # maximum time in second for the server to produce a response
debug: false, # more verbose log
window_size: [1280, 800], # not responsive, used to simulate scroll when needed
inspector: false, # use debug breakpoint and chrome inspector,
phantomjs_options: phantomjs_options
)
end

Capybara Poltergeist getting forced over https when using path helpers

Your app is redirecting the request to https, but Capybara doesn't run the app with https support. If it's a rails app you've probably got the config.force_ssl option enabled in your app - set it to false in the test environment. If that doesn't fix it then you'll have to look through your app to see why it's redirecting and turn off that behavior in test mode.

How to perform non-fresh logins using Devise/Rspec/Capybara/Poltergeist?

Assuming login_as is from Warden::Test::Helpers, it works by setting up a hook for the next request which logs the user in. That means the actual 'logging in' doesn't actually occur until the visit "/" call which will overwrite the value you've saved. I haven't tried this, but it should be possible to set devise.skip_trackable in the request environment by registering your own request hook rather than calling login_as and thereby stop the login dates from being updated

Warden.on_next_request do |proxy|
opts[:event] ||= :authentication
proxy.env['devise.skip_trackable'] = true
proxy.set_user(user, opts)
end


Related Topics



Leave a reply



Submit