Capybara Cheat Sheet
Capybara helps to test web applications by simulating a real user.
Navigating #
visit products_path
visit '/products/new'
visit post_comments_path(post)
Clicking links and buttons #
click_button 'New Product'
click_link 'Delete'
find("#product_#{@product.id}").click_link 'Delete' #if there exists multiple link with the same name
click_link('id-of-link')
click('Link Text') # Click either a link or a button
Interacting with forms #
fill_in :Name, :with => 'Nexus 5'
fill_in 'Price', :with => '25000'
Querying #
page.should have_content '25000'
page.should have_no_content '30000'
find_field('Name').value.should eq 'Nexus 5'
find_field('Price').value.should eq '30000'
page.has_xpath?('//table/tr')
page.has_css?('table tr.foo')
page.has_content?('foo')
page.should have_xpath('//table/tr')
page.should have_css('table tr.foo')
find_link('Hello').visible?
find_button('Send').click
find('//table/tr').click
locate("//*[@id='overlay'").find("//h1").click
all('a').each { |a| a[:href] }