This is a draft cheat sheet. It is a work in progress and is not finished yet.
Navigating
visit('/projects') |
visit(post_comments_path(post)) |
Clicking Buttons & Links
click_link('id-of-link') |
click_link('Link Text') |
click_button('Save') |
click('Link Text') # Click either a link or a button |
click('Button Value') |
Sync, Async & Wait...
Capybara automatically waits for asynchronous 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 Capybara.default_wait_time |
Here are the methods that waits: |
find(selector), find_field, find_link within(selector)(scoping) *has_selector?/has_no_selector? & assertions form & link actions click_link/button fill_in check/uncheck, select, choose |
Here are the methods that doesn't wait: |
visit current_path all (selector) first(selector) execute_script simple accessors: text, value, title, etc. |
|
|
Interacting with forms
fill_in('First Name', :with => 'John') |
fill_in('Password', :with => 'Seekrit') |
fill_in('Description', :with => 'Really Long Text…') |
choose('A Radio Button') |
choose("radio_group_selector", option: "Option 5") |
check('A Checkbox') |
uncheck('A Checkbox') |
attach_file('Image', '/path/to/image.jpg') |
select('Option', :from => 'Select Box') |
Scoping
within("//li[@id='employee']") do fill_in 'Name', :with => 'Jimmy' end |
within(:css, "li#employee") do fill_in 'Name', :with => 'Jimmy' end |
within_fieldset('Employee') do fill_in 'Name', :with => 'Jimmy' end |
within_table('Employee') do fill_in 'Name', :with => 'Jimmy' end |
|
|
|