Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Add clear_network_traffic command
Browse files Browse the repository at this point in the history
  • Loading branch information
vickvu committed Oct 21, 2013
1 parent 24e154a commit ff0a744
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
### Next release ###

#### Features ####
* Added ability to clear network traffic (Vick Vu)
* Added ability to set paper_size via a driver setter (Philippe Lehoux)
* Can support Basic HTTP authentication

Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -198,6 +198,9 @@ You can inspect the network traffic (i.e. what resources have been
loaded) on the current page by calling `page.driver.network_traffic`.
This returns an array of request objects. A request object has a
`response_parts` method containing data about the response chunks.
Please note that network traffic is not cleared when you visit new page.
You can manually clear the network traffic by calling `page.driver.clear_network_traffic`
or `page.driver.reset`

### Manipulating cookies ###

Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/poltergeist/browser.rb
Expand Up @@ -188,6 +188,10 @@ def network_traffic
end
end

def clear_network_traffic
command('clear_network_traffic')
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
Expand Up @@ -288,6 +288,10 @@ class Poltergeist.Browser
network_traffic: ->
this.sendResponse(@page.networkTraffic())

clear_network_traffic: ->
@page.clearNetworkTraffic()
this.sendResponse(true)

get_headers: ->
this.sendResponse(@page.getCustomHeaders())

Expand Down
5 changes: 5 additions & 0 deletions lib/capybara/poltergeist/client/compiled/browser.js
Expand Up @@ -388,6 +388,11 @@ Poltergeist.Browser = (function() {
return this.sendResponse(this.page.networkTraffic());
};

Browser.prototype.clear_network_traffic = function() {
this.page.clearNetworkTraffic();
return this.sendResponse(true);
};

Browser.prototype.get_headers = function() {
return this.sendResponse(this.page.getCustomHeaders());
};
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/poltergeist/client/compiled/web_page.js
Expand Up @@ -154,6 +154,10 @@ Poltergeist.WebPage = (function() {
return this._networkTraffic;
};

WebPage.prototype.clearNetworkTraffic = function() {
return this._networkTraffic = {};
};

WebPage.prototype.content = function() {
return this["native"].frameContent;
};
Expand Down
3 changes: 3 additions & 0 deletions lib/capybara/poltergeist/client/web_page.coffee
Expand Up @@ -100,6 +100,9 @@ class Poltergeist.WebPage
networkTraffic: ->
@_networkTraffic

clearNetworkTraffic: ->
@_networkTraffic = {}

content: ->
@native.frameContent

Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/poltergeist/driver.rb
Expand Up @@ -178,6 +178,10 @@ def network_traffic
browser.network_traffic
end

def clear_network_traffic
browser.clear_network_traffic
end

def headers
browser.get_headers
end
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/driver_spec.rb
Expand Up @@ -490,6 +490,15 @@ def create_screenshot(file, *args)
@session.visit('/poltergeist/with_js')
expect(@driver.network_traffic.length).to eq(4)
end

it "gets cleared when being cleared" do
@session.visit('/poltergeist/with_js')
expect(@driver.network_traffic.length).to eq(4)

@driver.clear_network_traffic

expect(@driver.network_traffic.length).to eq(0)
end
end

context 'status code support' do
Expand Down

0 comments on commit ff0a744

Please sign in to comment.