Functional testing with capybara

3,315 views
3,054 views

Published on

Functional testing with capybara, shown by examples from the metaflop project.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,315
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
37
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Functional testing with capybara

  1. 1. capybara
  2. 2. overview automated user interactionautomatically waits for asynchronous tasks driver agnostic high level access to ui elements
  3. 3. test frameworks cucumber rspec test::unit minitest::spec
  4. 4. drivers
  5. 5. rack_test default fast, no server no js mechanizerack_test with remote server
  6. 6. selenium 2.0 aka webdriverfirefox, chrome, ie, ...
  7. 7. webkit headless QtWebKitklogging / messages screenshots cookiesresizing the window
  8. 8. poltergeist headless phantomjs screenshots resizing the windowremote debugging (web inspector) no X (CI integration)
  9. 9. dsl
  10. 10. navigatingvisit(/projects)visit(post_comments_path(post))
  11. 11. clicking links and buttonsclick_link(id-of-link)click_link(Link Text)click_button(Save)click_on(Link Text) # links or buttons
  12. 12. 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)
  13. 13. 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)
  14. 14. findingfind_field(First Name).valuefind_link(Hello).visible?find_button(Send).clickfind("#overlay").find("h1").clickall(a).each { |a| a[:href] }
  15. 15. scopingwithin("li#employee") do fill_in Name, :with => Jimmyend
  16. 16. scriptingpage.execute_script("$(body).empty()")result = page.evaluate_script(4 + 4);
  17. 17. debuggingsave_and_open_page # snapshotprint page.html
  18. 18. setup
  19. 19. Capybara.default_driver = :selenium# sinatraCapybara.app = App# remote appCapybara.app_host = http://www.google.com
  20. 20. 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
  21. 21. set browserCapybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new( app, :browser => :chrome )end
  22. 22. in the wild
  23. 23. metaflopweb based platform for metafonts and related type projects modulator experimental font generation export as otf, webfont
  24. 24. 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
  25. 25. 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
  26. 26. 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
  27. 27. problems
  28. 28. general dialogs (downloads)new openend windows driver specialties
  29. 29. selenium slow, startup slow, random errors no http responseno .trigger() (e.g. mouse over) installation
  30. 30. solution avoid selenium use headlesstest visual concerns manually
  31. 31. links capybara homepage webkit poltergeistselenium chrome driver metaflop
  32. 32. @alexisreigel koffeinfreikoffeinfrei.org

×