Last active
July 10, 2017 18:21
-
-
Save darrenterhune/a9952902cf70e936154be63b445bc9c8 to your computer and use it in GitHub Desktop.
Capybara cheetsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SCOPING | |
within(*find_args) # within('div#delivery-address') do | |
within(a_node) # fill_in('Street', with: '12 Main Street') | |
# end | |
# MATCHERS | |
have_select(locator, options = {}) # expect(page).to have_select('id', options: ['Yes', 'No']) | |
# expect(page).to have_select('id', options: [1,2,3], selected: 2) | |
have_field(locator, options = {}) # expect(page).to have_field('id', placeholder: 'What city do you live in?') | |
# expect(page).to have_field('id', with: 'Some value', visible: false) | |
have_text(*args) # expect(page).to have_text('Some text on the page') | |
have_selector(*args) # expect(page).to have_selector('h1', text: 'Title on page') | |
have_css(css, options = {}) # expect(page).to have_css('id', text: 'Title on page') | |
have_checked_field(locator, options = {}) # expect(page).to have_checked_field('id') | |
have_unchecked_field(locator, options = {}) # expect(page).to have_unchecked_field('id') | |
have_link(locator, options = {}) # expect(page).to have_link('Home', href: '/') | |
have_button(locator, options = {}) # expect(page).to have_button('Save user') | |
# FORM INTERACTION | |
select(value, options = {}) # select('January', from: 'months') | |
click_button(locator, options = {}) # click_button('Submit') | |
fill_in([locator], options = {}) # fill_in('id', with: 'Text here') | |
click_link([locator], options) # click_link('Back') | |
check([locator], options) # check('id') | |
choose([locator], options) # choose('id') | |
uncheck([locator], options) # uncheck('id') | |
attach_file(locator, path, options = {}) # attach_file('id', '/path/to/file.jpg') | |
# SELECTORS | |
find(*args) # find('tr', text: 'Text inside tds').click_link('Wat?') | |
# find('#foo').find('.bar') | |
# find('li', text: 'Bla').click_link('Delete') | |
all([kind], locator, options) # all('a', text: 'Home') | |
# all('#menu li', visible: true) | |
first([kind], locator, options) # first('.trial-card') | |
# SESSION | |
save_screenshot(path = nil, options = {}) # page.save_screenshot('screen.jpg', full: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment