1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/spec/drivers_spec.rb

73 lines
2.1 KiB
Ruby
Raw Normal View History

2009-11-04 17:00:05 -05:00
require File.expand_path('spec_helper', File.dirname(__FILE__))
shared_examples_for 'driver' do
2009-11-04 18:34:11 -05:00
2009-11-04 17:32:35 -05:00
describe '#visit' do
it "should move to another page" do
2009-11-04 17:05:11 -05:00
@driver.visit('/')
@driver.body.should include('Hello world!')
2009-11-04 17:05:11 -05:00
@driver.visit('/foo')
@driver.body.should include('Another World')
2009-11-04 17:00:05 -05:00
end
end
2009-11-04 18:34:11 -05:00
2009-11-04 17:32:35 -05:00
describe '#body' do
it "should return text reponses" do
@driver.visit('/')
@driver.body.should include('Hello world!')
2009-11-04 17:32:35 -05:00
end
2009-11-04 18:34:11 -05:00
2009-11-04 17:32:35 -05:00
it "should return the full response html" do
@driver.visit('/with_simple_html')
@driver.body.should include('<h1>Bar</h1>')
2009-11-04 17:32:35 -05:00
end
end
2009-11-04 18:34:11 -05:00
describe '#find' do
context "with xpath selector" do
before do
@driver.visit('/with_html')
end
it "should find the correct number of elements" do
@driver.find('//a').size.should == 2
end
it "should extract node texts" do
@driver.find('//a')[0].text.should == 'labore'
@driver.find('//a')[1].text.should == 'ullamco'
end
it "should extract node attributes" do
2009-11-07 18:28:32 -05: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
it "should allow assignment of field value" do
2009-11-10 16:48:31 -05:00
@driver.find('//input').first[:value].should == 'monkey'
@driver.find('//input').first.set('gorilla')
@driver.find('//input').first[:value].should == 'gorilla'
2009-11-04 18:34:11 -05:00
end
2009-11-05 09:10:18 -05: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-11-04 18:34:11 -05:00
end
end
end
2009-11-05 11:35:45 -05:00
shared_examples_for "driver with javascript support" do
describe '#find' do
it "should find dynamically changed nodes" do
@driver.visit('/with_js')
@driver.find('//p').first.text.should == 'I changed it'
end
end
end