Capybara
-
Upload
flavia-missi -
Category
Technology
-
view
3.022 -
download
0
description
Transcript of Capybara
Unit testsUnit testsFunctional test Functional test
User + BrowserUser + Browser
Integration testsIntegration tests
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!
Sinatra
Selenium HQSelenium HQ
gem install capybaragem install capybara
require 'capybara/rails'require 'capybara/rspec'
spec_helper.rb
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
visit('/projects')visit('/projects')
visit(post_comments_path(post))visit(post_comments_path(post))
current_pathcurrent_path
Simulating clickSimulating click
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')
Filling html formsFilling html forms
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')
within("li#employee") do
fill_in 'Name', :with => 'Jimmy'
end
within(:xpath, "//li[@id='employee']") do
fill_in 'Name', :with => 'Jimmy'
end
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.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
É nozes!É nozes!Valeu!
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