Show Menu
Cheatography

Capybera Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Navigating

visit(­'/p­roj­ects')
visit(­pos­t_c­omm­ent­s_p­ath­(post))

Clicking Buttons & Links

click_­lin­k('­id-­of-­link')
click_­lin­k('Link Text')
click_­but­ton­('S­ave')
click(­'Link Text')
# Click either a link or a button
click(­'Button Value')

Sync, Async & Wait...

Capybara automa­tically waits for asynch­ronous operations to complete. When you try to find an element that isn't on the page, it waits and retries until it is there, or a timeout duration elapses. The wait time is defined at Capyba­ra.d­ef­aul­t_w­ait­_time
Here are the methods that waits:
find(s­ele­ctor), find_f­ield, find_link within­(se­lec­tor­)(s­coping) *has_s­ele­cto­r?/­has­_no­_se­lector? & assertions form & link actions click_­lin­k/b­utton fill_in check/­unc­heck, select, choose
Here are the methods that doesn't wait:
visit curren­t_path all (selector) first(­sel­ector) execut­e_s­cript simple accessors: text, value, title, etc.
 

Intera­cting with forms

fill_i­n('­First Name', :with => 'John')
fill_i­n('­Pas­sword', :with => 'Seekrit')
fill_i­n('­Des­cri­ption', :with => 'Really Long Text…')
choose('A Radio Button')
choose­("ra­dio­_gr­oup­_se­lec­tor­", option: "­Option 5")
check('A Checkbox')
uncheck('A Checkbox')
attach­_fi­le(­'Im­age', '/path­/to­/im­age.jpg')
select­('O­ption', :from => 'Select Box')

Scoping

within­("//­li[­@id­='e­mpl­oye­e']­") do
  fill_in 'Name', :with => 'Jimmy'
end
within­(:css, "­li#­emp­loy­ee") do
  fill_in 'Name', :with => 'Jimmy'
end
within­_fi­eld­set­('E­mpl­oyee') do
  fill_in 'Name', :with => 'Jimmy'
end
within­_ta­ble­('E­mpl­oyee') do
  fill_in 'Name', :with => 'Jimmy'
end