Functional testing with capybara
-
Upload
koffeinfrei -
Category
Technology
-
view
2.494 -
download
3
description
Transcript of Functional testing with capybara
![Page 1: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/1.jpg)
capybara
![Page 2: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/2.jpg)
![Page 3: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/3.jpg)
overviewautomated user interaction
automatically waits for asynchronous tasks
driver agnostic
high level access to ui elements
![Page 4: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/4.jpg)
test frameworkscucumber
rspec
test::unit
minitest::spec
![Page 5: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/5.jpg)
drivers
![Page 6: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/6.jpg)
rack_testdefault
fast, no server
no js
mechanizerack_test with remote server
![Page 7: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/7.jpg)
selenium2.0 aka webdriver
firefox, chrome, ie, ...
![Page 8: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/8.jpg)
webkitheadless
QtWebKitk
logging / messages
screenshots
cookies
resizing the window
![Page 9: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/9.jpg)
poltergeistheadless
phantomjs
screenshots
resizing the window
remote debugging (web inspector)
no X (CI integration)
![Page 10: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/10.jpg)
dsl
![Page 11: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/11.jpg)
navigatingvisit('/projects')visit(post_comments_path(post))
![Page 12: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/12.jpg)
clicking links and buttonsclick_link('id-of-link')click_link('Link Text')click_button('Save')click_on('Link Text') # links or buttons
![Page 13: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/13.jpg)
interacting with formsfill_in('Username', :with => 'user')choose('A Radio Button')check('A Checkbox')attach_file('Image', '/path/to/image.jpg')select('Option', :from => 'Select Box')
![Page 14: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/14.jpg)
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')
![Page 15: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/15.jpg)
findingfind_field('First Name').valuefind_link('Hello').visible?find_button('Send').click
find("#overlay").find("h1").clickall('a').each { |a| a[:href] }
![Page 16: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/16.jpg)
scopingwithin("li#employee") do fill_in 'Name', :with => 'Jimmy'end
![Page 17: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/17.jpg)
scriptingpage.execute_script("$('body').empty()")result = page.evaluate_script('4 + 4');
![Page 18: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/18.jpg)
debuggingsave_and_open_page # snapshotprint page.html
![Page 19: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/19.jpg)
setup
![Page 20: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/20.jpg)
Capybara.default_driver = :selenium
# sinatraCapybara.app = App
# remote appCapybara.app_host = 'http://www.google.com'
![Page 21: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/21.jpg)
per specCapybara.javascript_driver = :selenium
# ...
describe 'requires js', :js => true do it 'will use the default js driver' it 'will switch to one specific driver', :driver => :webkitend
![Page 22: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/22.jpg)
set browserCapybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new( app, :browser => :chrome )end
![Page 23: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/23.jpg)
in the wild
![Page 24: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/24.jpg)
metaflopweb based platform for metafonts and
related type projects
modulator
experimental font generation
export as otf, webfont
![Page 25: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/25.jpg)
spec sample 1context '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') endend
![Page 26: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/26.jpg)
spec sample 2context 'when i enable anatomy' do it 'shows the anatomy image' do within '#menu' do click_link 'on' end page.should have_selector '#info-panel' endend
![Page 27: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/27.jpg)
spec sample 3context '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' endend
![Page 28: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/28.jpg)
problems
![Page 29: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/29.jpg)
generaldialogs (downloads)
new openend windows
driver specialties
![Page 30: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/30.jpg)
seleniumslow, startup
slow, random errors
no http response
no .trigger() (e.g. mouse over)
installation
![Page 31: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/31.jpg)
solutionavoid selenium
use headless
test visual concerns manually
![Page 32: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/32.jpg)
linkscapybara homepage
webkit
poltergeist
selenium chrome driver
metaflop
![Page 33: Functional testing with capybara](https://reader034.fdocuments.us/reader034/viewer/2022052619/555a4481d8b42ae1398b5077/html5/thumbnails/33.jpg)
@alexisreigel
koffeinfrei
koffeinfrei.org