capybara
DESCRIPTION
Presentation about Integration Tests using Capybara, Selenium and Rails.TRANSCRIPT
![Page 2: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/2.jpg)
Unit testsUnit testsFunctional test Functional test
![Page 3: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/3.jpg)
User + BrowserUser + Browser
![Page 4: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/4.jpg)
Integration testsIntegration tests
![Page 5: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/5.jpg)
![Page 6: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/6.jpg)
Capybara simulates how a real Capybara simulates how a real user would interact with a user would interact with a
web applicationweb application
http://www.flickr.com/photos/kalebdf/3172638676/
Ué... não Ué... não aconteceu nada!aconteceu nada!
![Page 7: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/7.jpg)
Sinatra
![Page 8: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/8.jpg)
Selenium HQSelenium HQ
![Page 9: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/9.jpg)
gem install capybaragem install capybara
![Page 10: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/10.jpg)
require 'capybara/rails'require 'capybara/rspec'
spec_helper.rb
![Page 11: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/11.jpg)
Capybara.register_driver :selenium do |app|Capybara.register_driver :selenium do |app| Capybara::Driver::Selenium.new(Capybara::Driver::Selenium.new(
app, :browser => :chrome)app, :browser => :chrome) endend
Capybara.default_driver = :seleniumCapybara.default_driver = :selenium
![Page 12: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/12.jpg)
visit('/projects')visit('/projects')
visit(post_comments_path(post))visit(post_comments_path(post))
current_pathcurrent_path
![Page 13: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/13.jpg)
Simulating clickSimulating click
![Page 14: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/14.jpg)
click_link('id-of-link')click_link('id-of-link')
click_link('Link Text')click_link('Link Text')
click_button('Save')click_button('Save')
click_on('Link Text')click_on('Link Text')
click_on('Button Value')click_on('Button Value')
![Page 15: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/15.jpg)
Filling html formsFilling html forms
![Page 16: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/16.jpg)
fill_in('First Name', :with => 'John')fill_in('First Name', :with => 'John')
choose('A Radio Button')choose('A Radio Button')
check('A Checkbox')check('A Checkbox')
uncheck('A Checkbox')uncheck('A Checkbox')
attach_file('Image', '/path/to/image.jpg')attach_file('Image', '/path/to/image.jpg')
select('Option', :from => 'Select Box')select('Option', :from => 'Select Box')
![Page 17: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/17.jpg)
within("li#employee") do
fill_in 'Name', :with => 'Jimmy'
end
within(:xpath, "//li[@id='employee']") do
fill_in 'Name', :with => 'Jimmy'
end
![Page 18: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/18.jpg)
page.has_selector?('table tr')page.has_selector?('table tr')
page.has_selector?(:xpath, '//table/tr')page.has_selector?(:xpath, '//table/tr')
page.has_no_selector?(:content)page.has_no_selector?(:content)
page.has_xpath?('//table/tr')page.has_xpath?('//table/tr')
page.has_css?('table tr.foo')page.has_css?('table tr.foo')
page.has_content?('foo')page.has_content?('foo')
QueryingQuerying
![Page 19: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/19.jpg)
page.should have_selector('table tr')page.should have_selector('table tr')
page.should have_selector(:xpath, '//table/tr')page.should have_selector(:xpath, '//table/tr')
page.should have_no_selector(:content)page.should have_no_selector(:content)
page.should have_xpath('//table/tr')page.should have_xpath('//table/tr')
page.should have_css('table tr.foo')page.should have_css('table tr.foo')
page.should have_content('foo')page.should have_content('foo')
page.should have_no_content('foo')page.should have_no_content('foo')
RSpec QueryingRSpec Querying
![Page 20: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/20.jpg)
É nozes!É nozes!Valeu!
![Page 21: Capybara](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5558439dd8b42ac6078b516d/html5/thumbnails/21.jpg)
LinksLinkshttp://rubydoc.info/github/jnicklas/capybara/master/file/README.rdochttp://rubydoc.info/github/jnicklas/capybara/master/file/README.rdoc
https://github.com/jnicklas/capybarahttps://github.com/jnicklas/capybara