Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Functional testing with capybara
Search
koffeinfrei
August 22, 2012
Programming
3
210
Functional testing with capybara
Functional testing with capybara, shown by examples from the metaflop project.
koffeinfrei
August 22, 2012
Tweet
Share
More Decks by koffeinfrei
See All by koffeinfrei
Volt Showcase - Planning Poker
koffeinfrei
0
48
Other Decks in Programming
See All in Programming
RuboCop: Modularity and AST Insights
koic
2
740
趣味全開のAITuber開発
kokushin
0
200
海外のアプリで見かけたかっこいいTransitionを真似てみる
shogotakasaki
1
170
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
0
110
状態と共に暮らす:ステートフルへの挑戦
ypresto
1
530
「”誤った使い方をすることが困難”な設計」で良いコードの基礎を固めよう / phpcon-odawara-2025
taniguhey
0
150
ウォンテッドリーの「ココロオドル」モバイル開発 / Wantedly's "kokoro odoru" mobile development
kubode
1
140
AIコードエディタの基盤となるLLMのFlutter性能評価
alquist4121
0
210
「影響が少ない」を自分の目でみてみる
o0h
PRO
2
1.1k
AWS で実現する安全な AI エージェントの作り方 〜 Bedrock Engineer の実装例を添えて 〜 / how-to-build-secure-ai-agents
gawa
8
810
AHC045_解説
shun_pi
0
530
Empowering Developers with HTML-Aware ERB Tooling @ RubyKaigi 2025, Matsuyama, Ehime
marcoroth
2
640
Featured
See All Featured
Optimizing for Happiness
mojombo
377
70k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.8k
Making Projects Easy
brettharned
116
6.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.1k
Faster Mobile Websites
deanohume
306
31k
Designing Experiences People Love
moore
141
24k
We Have a Design System, Now What?
morganepeng
52
7.5k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Optimising Largest Contentful Paint
csswizardry
36
3.2k
Transcript
capybara
None
overview automated user interaction automatically waits for asynchronous tasks driver
agnostic high level access to ui elements
test frameworks cucumber rspec test::unit minitest::spec
drivers
rack_test default fast, no server no js mechanize rack_test with
remote server
selenium 2.0 aka webdriver firefox, chrome, ie, ...
webkit headless QtWebKitk logging / messages screenshots cookies resizing the
window
poltergeist headless phantomjs screenshots resizing the window remote debugging (web
inspector) no X (CI integration)
dsl
navigating visit('/projects') visit(post_comments_path(post))
clicking links and buttons click_link('id-of-link') click_link('Link Text') click_button('Save') click_on('Link Text')
# links or buttons
interacting with forms fill_in('Username', :with => 'user') choose('A Radio Button')
check('A Checkbox') attach_file('Image', '/path/to/image.jpg') select('Option', :from => 'Select Box')
querying (rspec matchers) page.should have_selector('table tr') page.should have_selector( :xpath, '//table/tr')
page.should have_xpath('//table/tr') page.should have_css('table tr.foo') page.should have_content('foo')
finding find_field('First Name').value find_link('Hello').visible? find_button('Send').click find("#overlay").find("h1").click all('a').each { |a| a[:href]
}
scoping within("li#employee") do fill_in 'Name', :with => 'Jimmy' end
scripting page.execute_script("$('body').empty()") result = page.evaluate_script('4 + 4');
debugging save_and_open_page # snapshot print page.html
setup
Capybara.default_driver = :selenium # sinatra Capybara.app = App # remote
app Capybara.app_host = 'http://www.google.com'
per spec Capybara.javascript_driver = :selenium # ... describe 'requires js',
:js => true do it 'will use the default js driver' it 'will switch to one specific driver', :driver => :webkit end
set browser Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new( app, :browser =>
:chrome ) end
in the wild
metaflop web based platform for metafonts and related type projects
modulator experimental font generation export as otf, webfont
spec sample 1 context 'when i change the unit width'
do it 'should show the loading indicator' do fill_in 'param-unit-width', :with => 2 page.should have_selector( '.preview-loading-text') end end
spec sample 2 context 'when i enable anatomy' do it
'shows the anatomy image' do within '#menu' do click_link 'on' end page.should have_selector '#info-panel' end end
spec sample 3 context 'when i click the "webfont" link'
do it 'should call the font generator url' do click_link('webfont') current_url.should include 'modulator/export/font/web' end end
problems
general dialogs (downloads) new openend windows driver specialties
selenium slow, startup slow, random errors no http response no
.trigger() (e.g. mouse over) installation
solution avoid selenium use headless test visual concerns manually
links capybara homepage webkit poltergeist selenium chrome driver metaflop
@alexisreigel koffeinfrei koffeinfrei.org