Skip to content

Commit

Permalink
Add ability to set proxy at runtime (needs test coverage)
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Mar 11, 2016
1 parent ea8bb98 commit 386faae
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### Next release ###

#### Features ####
* Added ability to set proxy at runtime (Dmitry Vorotilin)

### 1.9.0 ###

#### Features ####
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/capybara/poltergeist/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/poltergeist/client/browser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
5 changes: 5 additions & 0 deletions lib/capybara/poltergeist/client/compiled/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/poltergeist/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 386faae

Please sign in to comment.