I'm using PhantomJS and poltergeist to emulate a browser, however I'm not sure how to specify a proxy to use in the code:
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
task :experiment => :environment do
Capybara.run_server = false
Capybara.current_driver = :poltergeist
Capybara.app_host = "http://something.com"
include Capybara::DSL
# set_proxy('12.13.14.15', '4521')
visit('posts')
page.include?('foo')
end
Also, for some reason, i get undefined method page
when using poltergeist, can anyone advise?
Try to run it in controller action, so when it will control through controller level it will update the new proxy ip. Like this way
You need to pass the
--proxy
option to PhantomJS, see the API docsWith Poltergeist, you can use the
:phantomjs_options
configuration option to specify command line options for PhantomJS.Putting it together: