diff --git a/CHANGELOG.md b/CHANGELOG.md index 19c522f9..7f190c2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ### Next release ### +#### Features #### +* Added ability to set proxy at runtime (Dmitry Vorotilin) + ### 1.9.0 ### #### Features #### diff --git a/README.md b/README.md index 6ca1623d..7122e125 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ and the following optional features: * `page.driver.scroll_to(left, top)` * `page.driver.basic_authorize(user, password)` * `element.native.send_keys(*keys)` +* `page.driver.set_proxy(ip, port, type, user, password)` * window API * cookie handling * drag-and-drop diff --git a/lib/capybara/poltergeist/browser.rb b/lib/capybara/poltergeist/browser.rb index b5bdc024..a6c3eda8 100644 --- a/lib/capybara/poltergeist/browser.rb +++ b/lib/capybara/poltergeist/browser.rb @@ -260,6 +260,13 @@ def clear_network_traffic command('clear_network_traffic') end + def set_proxy(ip, port, type, user, password) + args = [ip, port, type] + args << user if user + args << password if password + command('set_proxy', *args) + end + def equals(page_id, id, other_id) command('equals', page_id, id, other_id) end diff --git a/lib/capybara/poltergeist/client/browser.coffee b/lib/capybara/poltergeist/client/browser.coffee index 8cb34dcd..a53e0268 100644 --- a/lib/capybara/poltergeist/client/browser.coffee +++ b/lib/capybara/poltergeist/client/browser.coffee @@ -400,6 +400,10 @@ class Poltergeist.Browser @currentPage.clearNetworkTraffic() @current_command.sendResponse(true) + set_proxy: (ip, port, type, user, password) -> + phantom.setProxy(ip, port, type, user, password) + @current_command.sendResponse(true) + get_headers: -> @current_command.sendResponse(@currentPage.getCustomHeaders()) diff --git a/lib/capybara/poltergeist/client/compiled/browser.js b/lib/capybara/poltergeist/client/compiled/browser.js index 994625f4..6222f67c 100644 --- a/lib/capybara/poltergeist/client/compiled/browser.js +++ b/lib/capybara/poltergeist/client/compiled/browser.js @@ -549,6 +549,11 @@ Poltergeist.Browser = (function() { return this.current_command.sendResponse(true); }; + Browser.prototype.set_proxy = function(ip, port, type, user, password) { + phantom.setProxy(ip, port, type, user, password); + return this.current_command.sendResponse(true); + }; + Browser.prototype.get_headers = function() { return this.current_command.sendResponse(this.currentPage.getCustomHeaders()); }; diff --git a/lib/capybara/poltergeist/driver.rb b/lib/capybara/poltergeist/driver.rb index 7677fe4f..83a65f06 100644 --- a/lib/capybara/poltergeist/driver.rb +++ b/lib/capybara/poltergeist/driver.rb @@ -224,6 +224,10 @@ def clear_network_traffic browser.clear_network_traffic end + def set_proxy(ip, port, type = "http", user = nil, password = nil) + browser.set_proxy(ip, port, type, user, password) + end + def headers browser.get_headers end