Functional testing with capybara
Upcoming SlideShare
Loading in...5
×
 

Functional testing with capybara

on

  • 2,816 views

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

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

Statistics

Views

Total Views
2,816
Views on SlideShare
2,816
Embed Views
0

Actions

Likes
2
Downloads
19
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Functional testing with capybara Functional testing with capybara Presentation Transcript

  • capybara
  • overview automated user interactionautomatically 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 mechanizerack_test with remote server
  • selenium 2.0 aka webdriverfirefox, chrome, ie, ...
  • webkit headless QtWebKitklogging / messages screenshots cookiesresizing the window
  • poltergeist headless phantomjs screenshots resizing the windowremote debugging (web inspector) no X (CI integration)
  • dsl
  • navigatingvisit(/projects)visit(post_comments_path(post))
  • clicking links and buttonsclick_link(id-of-link)click_link(Link Text)click_button(Save)click_on(Link Text) # links or buttons
  • 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)
  • 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)
  • findingfind_field(First Name).valuefind_link(Hello).visible?find_button(Send).clickfind("#overlay").find("h1").clickall(a).each { |a| a[:href] }
  • scopingwithin("li#employee") do fill_in Name, :with => Jimmyend
  • scriptingpage.execute_script("$(body).empty()")result = page.evaluate_script(4 + 4);
  • debuggingsave_and_open_page # snapshotprint page.html
  • setup
  • Capybara.default_driver = :selenium# sinatraCapybara.app = App# remote appCapybara.app_host = http://www.google.com
  • 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
  • set browserCapybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new( app, :browser => :chrome )end
  • in the wild
  • metaflopweb based platform for metafonts and related type projects modulator experimental font generation export as otf, webfont
  • 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
  • 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
  • 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
  • problems
  • general dialogs (downloads)new openend windows driver specialties
  • selenium slow, startup slow, random errors no http responseno .trigger() (e.g. mouse over) installation
  • solution avoid selenium use headlesstest visual concerns manually
  • links capybara homepage webkit poltergeistselenium chrome driver metaflop
  • @alexisreigel koffeinfreikoffeinfrei.org