Capybara Cheat Sheet

Capybara helps to test web applications by simulating a real user.

visit products_path
visit '/products/new'
visit post_comments_path(post)

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] }
 
28
Kudos
 
28
Kudos

Now read this

DS and Algo

Given a list of area telephone codes along with their location, find the location of a given telephone number. The area codes can be minimum three digits and maximum six digits. Area codes are unique for a particular length between three... Continue →