teamcapybara--capybara/lib/capybara/spec/driver.rb

132 lines
3.9 KiB
Ruby
Raw Normal View History

require 'capybara/spec/test_app'
Dir[File.dirname(__FILE__)+'/driver/*'].each { |group|
require group
}
2009-11-04 22:00:05 +00:00
shared_examples_for 'driver' do
2009-11-04 23:34:11 +00:00
2009-11-04 22:32:35 +00:00
describe '#visit' do
it "should move to another page" do
2009-11-04 22:05:11 +00:00
@driver.visit('/')
@driver.body.should include('Hello world!')
2009-11-04 22:05:11 +00:00
@driver.visit('/foo')
@driver.body.should include('Another World')
2009-11-04 22:00:05 +00:00
end
2009-12-17 11:22:47 +00:00
it "should show the correct URL" do
2009-12-25 18:09:10 +00:00
@driver.visit('/foo')
@driver.current_url.should include('/foo')
2009-12-17 11:22:47 +00:00
end
2009-11-04 22:00:05 +00:00
end
2009-11-04 23:34:11 +00:00
2009-11-04 22:32:35 +00:00
describe '#body' do
it "should return text reponses" do
@driver.visit('/')
@driver.body.should include('Hello world!')
2009-11-04 22:32:35 +00:00
end
2009-11-04 23:34:11 +00:00
2009-11-04 22:32:35 +00:00
it "should return the full response html" do
@driver.visit('/with_simple_html')
@driver.body.should include('Bar')
2009-11-04 22:32:35 +00:00
end
end
2009-11-04 23:34:11 +00:00
describe '#find' do
context "with xpath selector" do
before do
@driver.visit('/with_html')
end
it "should extract node texts" do
@driver.find('//a')[0].text.should == 'labore'
@driver.find('//a')[1].text.should == 'ullamco'
end
2009-11-04 23:34:11 +00:00
it "should extract node attributes" do
2009-11-07 23:28:32 +00:00
@driver.find('//a')[0][:href].should == '/with_simple_html'
@driver.find('//a')[0][:class].should == 'simple'
@driver.find('//a')[1][:href].should == '/foo'
@driver.find('//a')[1][:id].should == 'foo'
@driver.find('//a')[1][:rel].should be_nil
end
2010-01-30 19:43:56 +00:00
it "should extract boolean node attributes" do
@driver.find('//input[@id="checked_field"]')[0][:checked].should be_true
end
2009-11-07 23:28:32 +00:00
it "should allow assignment of field value" do
@driver.find('//input').first.value.should == 'monkey'
2009-11-10 21:48:31 +00:00
@driver.find('//input').first.set('gorilla')
@driver.find('//input').first.value.should == 'gorilla'
2009-11-04 23:34:11 +00:00
end
2009-11-05 14:10:18 +00:00
it "should extract node tag name" do
@driver.find('//a')[0].tag_name.should == 'a'
@driver.find('//a')[1].tag_name.should == 'a'
@driver.find('//p')[1].tag_name.should == 'p'
end
2009-12-22 20:13:55 +00:00
it "should extract node visibility" do
@driver.find('//a')[0].should be_visible
2009-12-25 17:50:01 +00:00
@driver.find('//div[@id="hidden"]')[0].should_not be_visible
@driver.find('//div[@id="hidden_via_ancestor"]')[0].should_not be_visible
2009-12-22 20:13:55 +00:00
end
2009-11-04 23:34:11 +00:00
end
end
describe "node relative searching" do
before do
@driver.visit('/tables')
@node = @driver.find('//body').first
end
it "should be able to navigate/search child node" do
@node.all('//table').size.should == 5
@node.find('//form').all('.//table').size.should == 1
@node.find('//form').find('.//table//caption').text.should == 'Agent'
if @driver.class == Capybara::Driver::Selenium
pending("Selenium gets this wrong, see http://code.google.com/p/selenium/issues/detail?id=403") do
@node.find('//form').all('//table').size.should == 5
end
else
@node.find('//form').all('//table').size.should == 5
end
end
end
2009-11-04 23:34:11 +00:00
end
2009-11-05 16:35:45 +00:00
shared_examples_for "driver with javascript support" do
before { @driver.visit('/with_js') }
2009-11-05 16:35:45 +00:00
describe '#find' do
it "should find dynamically changed nodes" do
@driver.find('//p').first.text.should == 'I changed it'
end
end
describe '#drag_to' do
it "should drag and drop an object" do
draggable = @driver.find('//div[@id="drag"]').first
droppable = @driver.find('//div[@id="drop"]').first
draggable.drag_to(droppable)
@driver.find('//div[contains(., "Dropped!")]').should_not be_nil
end
end
describe "#evaluate_script" do
it "should return the value of the executed script" do
@driver.evaluate_script('1+1').should == 2
end
end
2009-11-05 16:35:45 +00:00
end
shared_examples_for "driver with header support" do
it "should make headers available through response_headers" do
@driver.visit('/with_simple_html')
@driver.response_headers['Content-Type'].should == 'text/html'
end
end