mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Add cleanup method to clear cookies for Celerity/Culerity and RackTest, with tests for Selenium included
This commit is contained in:
parent
a94f9949d5
commit
5ad348d776
10 changed files with 59 additions and 27 deletions
|
@ -72,7 +72,7 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
||||||
def path
|
def path
|
||||||
node.xpath
|
node.xpath
|
||||||
end
|
end
|
||||||
|
|
||||||
def trigger(event)
|
def trigger(event)
|
||||||
node.fire_event(event.to_s)
|
node.fire_event(event.to_s)
|
||||||
end
|
end
|
||||||
|
@ -102,7 +102,7 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
||||||
def current_url
|
def current_url
|
||||||
browser.url
|
browser.url
|
||||||
end
|
end
|
||||||
|
|
||||||
def source
|
def source
|
||||||
browser.html
|
browser.html
|
||||||
end
|
end
|
||||||
|
@ -114,7 +114,7 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
||||||
def response_headers
|
def response_headers
|
||||||
browser.response_headers
|
browser.response_headers
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_code
|
def status_code
|
||||||
browser.status_code
|
browser.status_code
|
||||||
end
|
end
|
||||||
|
@ -138,6 +138,10 @@ class Capybara::Driver::Celerity < Capybara::Driver::Base
|
||||||
@_browser
|
@_browser
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cleanup!
|
||||||
|
browser.clear_cookies
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def url(path)
|
def url(path)
|
||||||
|
|
|
@ -204,7 +204,7 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
||||||
def response_headers
|
def response_headers
|
||||||
response.headers
|
response.headers
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_code
|
def status_code
|
||||||
response.status
|
response.status
|
||||||
end
|
end
|
||||||
|
@ -218,21 +218,25 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
||||||
def find(selector)
|
def find(selector)
|
||||||
html.xpath(selector).map { |node| Node.new(self, node) }
|
html.xpath(selector).map { |node| Node.new(self, node) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def body
|
def body
|
||||||
@body ||= response.body
|
@body ||= response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def html
|
def html
|
||||||
@html ||= Nokogiri::HTML(body)
|
@html ||= Nokogiri::HTML(body)
|
||||||
end
|
end
|
||||||
alias_method :source, :body
|
alias_method :source, :body
|
||||||
|
|
||||||
|
def cleanup!
|
||||||
|
clear_cookies
|
||||||
|
end
|
||||||
|
|
||||||
def get(*args, &block); reset_cache; super; end
|
def get(*args, &block); reset_cache; super; end
|
||||||
def post(*args, &block); reset_cache; super; end
|
def post(*args, &block); reset_cache; super; end
|
||||||
def put(*args, &block); reset_cache; super; end
|
def put(*args, &block); reset_cache; super; end
|
||||||
def delete(*args, &block); reset_cache; super; end
|
def delete(*args, &block); reset_cache; super; end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def reset_cache
|
def reset_cache
|
||||||
|
@ -268,9 +272,4 @@ private
|
||||||
env
|
env
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_cache
|
|
||||||
@body = nil
|
|
||||||
@html = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'capybara/spec/test_app'
|
require 'capybara/spec/test_app'
|
||||||
|
|
||||||
Dir[File.dirname(__FILE__)+'/driver/*'].each { |group|
|
Dir[File.dirname(__FILE__)+'/driver/*'].each { |group|
|
||||||
require group
|
require group
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ shared_examples_for 'driver' do
|
||||||
@driver.visit('/foo')
|
@driver.visit('/foo')
|
||||||
@driver.body.should include('Another World')
|
@driver.body.should include('Another World')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should show the correct URL" do
|
it "should show the correct URL" do
|
||||||
@driver.visit('/foo')
|
@driver.visit('/foo')
|
||||||
@driver.current_url.should include('/foo')
|
@driver.current_url.should include('/foo')
|
||||||
|
@ -66,10 +66,10 @@ shared_examples_for 'driver' do
|
||||||
@driver.find('//a')[1].tag_name.should == 'a'
|
@driver.find('//a')[1].tag_name.should == 'a'
|
||||||
@driver.find('//p')[1].tag_name.should == 'p'
|
@driver.find('//p')[1].tag_name.should == 'p'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should extract node visibility" do
|
it "should extract node visibility" do
|
||||||
@driver.find('//a')[0].should be_visible
|
@driver.find('//a')[0].should be_visible
|
||||||
|
|
||||||
@driver.find('//div[@id="hidden"]')[0].should_not be_visible
|
@driver.find('//div[@id="hidden"]')[0].should_not be_visible
|
||||||
@driver.find('//div[@id="hidden_via_ancestor"]')[0].should_not be_visible
|
@driver.find('//div[@id="hidden_via_ancestor"]')[0].should_not be_visible
|
||||||
end
|
end
|
||||||
|
@ -81,7 +81,7 @@ shared_examples_for 'driver' do
|
||||||
@driver.visit('/tables')
|
@driver.visit('/tables')
|
||||||
@node = @driver.find('//body').first
|
@node = @driver.find('//body').first
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to navigate/search child node" do
|
it "should be able to navigate/search child node" do
|
||||||
@node.all('//table').size.should == 5
|
@node.all('//table').size.should == 5
|
||||||
@node.find('//form').all('.//table').size.should == 1
|
@node.find('//form').all('.//table').size.should == 1
|
||||||
|
@ -95,7 +95,6 @@ shared_examples_for 'driver' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for "driver with javascript support" do
|
shared_examples_for "driver with javascript support" do
|
||||||
|
@ -176,3 +175,22 @@ shared_examples_for "driver with frame support" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples_for "driver with cookies support" do
|
||||||
|
describe "#cleanup" do
|
||||||
|
it "should set and clean cookies" do
|
||||||
|
@driver.visit('/get_cookie')
|
||||||
|
@driver.body.should_not include('test_cookie')
|
||||||
|
|
||||||
|
@driver.visit('/set_cookie')
|
||||||
|
@driver.body.should include('Cookie set to test_cookie')
|
||||||
|
|
||||||
|
@driver.visit('/get_cookie')
|
||||||
|
@driver.body.should include('test_cookie')
|
||||||
|
|
||||||
|
@driver.cleanup!
|
||||||
|
@driver.visit('/get_cookie')
|
||||||
|
@driver.body.should_not include('test_cookie')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -13,7 +13,7 @@ class TestApp < Sinatra::Base
|
||||||
get '/foo' do
|
get '/foo' do
|
||||||
'Another World'
|
'Another World'
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/redirect' do
|
get '/redirect' do
|
||||||
redirect '/redirect_again'
|
redirect '/redirect_again'
|
||||||
end
|
end
|
||||||
|
@ -33,7 +33,7 @@ class TestApp < Sinatra::Base
|
||||||
get '/form/get' do
|
get '/form/get' do
|
||||||
'<pre id="results">' + params[:form].to_yaml + '</pre>'
|
'<pre id="results">' + params[:form].to_yaml + '</pre>'
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/favicon.ico' do
|
get '/favicon.ico' do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
@ -50,6 +50,16 @@ class TestApp < Sinatra::Base
|
||||||
redirect back
|
redirect back
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/set_cookie' do
|
||||||
|
cookie_value = 'test_cookie'
|
||||||
|
response.set_cookie('capybara', cookie_value)
|
||||||
|
"Cookie set to #{cookie_value}"
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/get_cookie' do
|
||||||
|
request.cookies['capybara']
|
||||||
|
end
|
||||||
|
|
||||||
get '/:view' do |view|
|
get '/:view' do |view|
|
||||||
erb view.to_sym
|
erb view.to_sym
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ if RUBY_PLATFORM =~ /java/
|
||||||
it_should_behave_like "driver with javascript support"
|
it_should_behave_like "driver with javascript support"
|
||||||
it_should_behave_like "driver with header support"
|
it_should_behave_like "driver with header support"
|
||||||
it_should_behave_like "driver with status code support"
|
it_should_behave_like "driver with status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
|
puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
|
||||||
|
|
|
@ -4,10 +4,10 @@ describe Capybara::Driver::Culerity do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@driver = Capybara::Driver::Culerity.new(TestApp)
|
@driver = Capybara::Driver::Culerity.new(TestApp)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_behave_like "driver"
|
it_should_behave_like "driver"
|
||||||
it_should_behave_like "driver with javascript support"
|
it_should_behave_like "driver with javascript support"
|
||||||
it_should_behave_like "driver with header support"
|
it_should_behave_like "driver with header support"
|
||||||
it_should_behave_like "driver with status code support"
|
it_should_behave_like "driver with status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,9 +10,9 @@ describe Capybara::Driver::RackTest do
|
||||||
Capybara::Driver::RackTest.new(nil)
|
Capybara::Driver::RackTest.new(nil)
|
||||||
end.should raise_error(ArgumentError)
|
end.should raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_behave_like "driver"
|
it_should_behave_like "driver"
|
||||||
it_should_behave_like "driver with header support"
|
it_should_behave_like "driver with header support"
|
||||||
it_should_behave_like "driver with status code support"
|
it_should_behave_like "driver with status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,4 +9,5 @@ describe Capybara::Driver::Selenium do
|
||||||
it_should_behave_like "driver with javascript support"
|
it_should_behave_like "driver with javascript support"
|
||||||
it_should_behave_like "driver with frame support"
|
it_should_behave_like "driver with frame support"
|
||||||
it_should_behave_like "driver without status code support"
|
it_should_behave_like "driver without status code support"
|
||||||
|
it_should_behave_like "driver with cookies support"
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ if RUBY_PLATFORM =~ /java/
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#driver' do
|
describe '#driver' do
|
||||||
it "should be a rack test driver" do
|
it "should be a celerity driver" do
|
||||||
@session.driver.should be_an_instance_of(Capybara::Driver::Celerity)
|
@session.driver.should be_an_instance_of(Capybara::Driver::Celerity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe Capybara::Session do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#driver' do
|
describe '#driver' do
|
||||||
it "should be a rack test driver" do
|
it "should be a culerity driver" do
|
||||||
@session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
|
@session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue