mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00
Can set cookies for given domain
This commit is contained in:
parent
6494884aca
commit
aae2bcb02b
3 changed files with 19 additions and 5 deletions
|
@ -337,6 +337,7 @@ Include as much information as possible. For example:
|
||||||
* Invalid selectors throw a useful error message
|
* Invalid selectors throw a useful error message
|
||||||
* Tie us to the 0.4 version of faye-websocket since the 0.5 version
|
* Tie us to the 0.4 version of faye-websocket since the 0.5 version
|
||||||
contains breaking changes.
|
contains breaking changes.
|
||||||
|
* Can set cookies for given domain
|
||||||
|
|
||||||
### 1.2.0 ###
|
### 1.2.0 ###
|
||||||
|
|
||||||
|
|
|
@ -177,11 +177,12 @@ module Capybara::Poltergeist
|
||||||
def set_cookie(name, value, options = {})
|
def set_cookie(name, value, options = {})
|
||||||
options[:name] ||= name
|
options[:name] ||= name
|
||||||
options[:value] ||= value
|
options[:value] ||= value
|
||||||
|
options[:domain] ||= begin
|
||||||
if @started
|
if @started
|
||||||
options[:domain] = URI.parse(browser.current_url).host
|
URI.parse(browser.current_url).host
|
||||||
else
|
else
|
||||||
options[:domain] = Capybara.app_host || "127.0.0.1"
|
Capybara.app_host || "127.0.0.1"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
browser.set_cookie(options)
|
browser.set_cookie(options)
|
||||||
|
|
|
@ -406,6 +406,18 @@ module Capybara::Poltergeist
|
||||||
@driver.cookies['foo'].expires.should == time
|
@driver.cookies['foo'].expires.should == time
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'can set cookies for given domain' do
|
||||||
|
port = @session.server.port
|
||||||
|
@driver.set_cookie 'capybara', '127.0.0.1'
|
||||||
|
@driver.set_cookie 'capybara', 'localhost', :domain => 'localhost'
|
||||||
|
|
||||||
|
@session.visit("http://localhost:#{port}/poltergeist/get_cookie")
|
||||||
|
@driver.body.should include('localhost')
|
||||||
|
|
||||||
|
@session.visit("http://127.0.0.1:#{port}/poltergeist/get_cookie")
|
||||||
|
@driver.body.should include('127.0.0.1')
|
||||||
|
end
|
||||||
|
|
||||||
it 'can enable and disable cookies' do
|
it 'can enable and disable cookies' do
|
||||||
@driver.cookies_enabled = false
|
@driver.cookies_enabled = false
|
||||||
@session.visit('/set_cookie')
|
@session.visit('/set_cookie')
|
||||||
|
|
Loading…
Add table
Reference in a new issue