Skip to content

Instantly share code, notes, and snippets.

@pironim
Forked from zhengjia/capybara cheat sheet
Last active October 5, 2015 16:18

Revisions

  1. Vladimir Zhukov revised this gist May 30, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions capybara cheat sheet
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@
    click_button('Save')
    click('Link Text') # Click either a link or a button
    click('Button Value')
    click_on('text') ???

    =Interacting with forms=
    fill_in('First Name', :with => 'John')
  2. Vladimir Zhukov revised this gist Apr 26, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions capybara cheat sheet
    Original file line number Diff line number Diff line change
    @@ -73,3 +73,7 @@
    have_xpath("//div[@class='field sms_me_only_at_work']/input[@type='checkbox'][@value='1']")
    page.should have_xpath('//input[@type="checkbox"][@name="service_provider[online_app_email_notification]"][not(property[@checked="checked"])]')

    =--------=
    =matchers=
    should be_checked
    find('#some', :visible => false).should_not be_visible
  3. Vladimir Zhukov revised this gist Jun 22, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions capybara cheat sheet
    Original file line number Diff line number Diff line change
    @@ -71,3 +71,5 @@
    locate('input#name').value
    =XPath syntax=
    have_xpath("//div[@class='field sms_me_only_at_work']/input[@type='checkbox'][@value='1']")
    page.should have_xpath('//input[@type="checkbox"][@name="service_provider[online_app_email_notification]"][not(property[@checked="checked"])]')

  4. Vladimir Zhukov revised this gist May 31, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions capybara cheat sheet
    Original file line number Diff line number Diff line change
    @@ -69,3 +69,5 @@
    within('ul li') { ... }
    find('ul li').text
    locate('input#name').value
    =XPath syntax=
    have_xpath("//div[@class='field sms_me_only_at_work']/input[@type='checkbox'][@value='1']")
  5. @zhengjia zhengjia created this gist Jun 7, 2010.
    71 changes: 71 additions & 0 deletions capybara cheat sheet
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    =Navigating=
    visit('/projects')
    visit(post_comments_path(post))

    =Clicking links and buttons=
    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')

    =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')
    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

    =Querying=
    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')
    page.should have_content('foo')
    page.should have_no_content('foo')
    find_field('First Name').value
    find_link('Hello').visible?
    find_button('Send').click
    find('//table/tr').click
    locate("//*[@id='overlay'").find("//h1").click
    all('a').each { |a| a[:href] }

    =Scripting=
    result = page.evaluate_script('4 + 4');

    =Debugging=
    save_and_open_page

    =Asynchronous JavaScript=
    click_link('foo')
    click_link('bar')
    page.should have_content('baz')
    page.should_not have_xpath('//a')
    page.should have_no_xpath('//a')

    =XPath and CSS=
    within(:css, 'ul li') { ... }
    find(:css, 'ul li').text
    locate(:css, 'input#name').value
    Capybara.default_selector = :css
    within('ul li') { ... }
    find('ul li').text
    locate('input#name').value