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

Driver can enable or disable PhantomJS cookies #300

Merged
merged 1 commit into from
Apr 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ Include as much information as possible. For example:

### Next release ###

#### Features ####
* Add support for PhantomJS 1.7's `cookiesEnabled` API
(Micah Frost)

#### Bug fixes ####

* Fix logging of mouse event co-ordinates
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/poltergeist/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def remove_cookie(name)
command 'remove_cookie', name
end

def cookies_enabled=(flag)
command 'cookies_enabled', !!flag
end

def js_errors=(val)
command 'set_js_errors', !!val
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 @@ -285,6 +285,10 @@ class Poltergeist.Browser
@page.deleteCookie(name)
this.sendResponse(true)

cookies_enabled: (flag) ->
phantom.cookiesEnabled = flag
this.sendResponse(true)

set_js_errors: (value) ->
@js_errors = value
this.sendResponse(true)
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 @@ -393,6 +393,11 @@ Poltergeist.Browser = (function() {
return this.sendResponse(true);
};

Browser.prototype.cookies_enabled = function(flag) {
phantom.cookiesEnabled = flag;
return this.sendResponse(true);
};

Browser.prototype.set_js_errors = function(value) {
this.js_errors = value;
return this.sendResponse(true);
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 @@ -191,6 +191,10 @@ def remove_cookie(name)
browser.remove_cookie(name)
end

def cookies_enabled=(flag)
browser.cookies_enabled = flag
end

def debug
if @options[:inspector]
inspector.open
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ def session_url(path)
@driver.set_cookie 'foo', 'bar', :expires => time
@driver.cookies['foo'].expires.should == time
end

it 'can enable and disable cookies' do
@driver.cookies_enabled = false
@session.visit('/set_cookie')
@driver.cookies.should be_empty

@driver.cookies_enabled = true
@session.visit('/set_cookie')
@driver.cookies.should_not be_empty
end
end

it "allows the driver to have a fixed port" do
Expand Down