Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 1.88 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #Navigating
  2.     visit('/projects')
  3.     visit(post_comments_path(post))
  4.  
  5. #Clicking links and buttons
  6.     click_link('id-of-link')
  7.     click_link('Link Text')
  8.     click_button('Save')
  9.     click('Link Text') # Click either a link or a button
  10.     click('Button Value')
  11.  
  12. #Interacting with forms
  13.     fill_in('First Name', :with => 'John')
  14.     fill_in('Password', :with => 'Seekrit')
  15.     fill_in('Description', :with => 'Really Long Text…')
  16.     choose('A Radio Button')
  17.     check('A Checkbox')
  18.     uncheck('A Checkbox')
  19.     attach_file('Image', '/path/to/image.jpg')
  20.     select('Option', :from => 'Select Box')
  21.  
  22. #scoping
  23.     within("//li[@id='employee']") do
  24.       fill_in 'Name', :with => 'Jimmy'
  25.     end
  26.     within(:css, "li#employee") do
  27.       fill_in 'Name', :with => 'Jimmy'
  28.     end
  29.     within_fieldset('Employee') do
  30.       fill_in 'Name', :with => 'Jimmy'
  31.     end
  32.     within_table('Employee') do
  33.       fill_in 'Name', :with => 'Jimmy'
  34.     end
  35.  
  36. #Querying
  37.     page.has_xpath?('//table/tr')
  38.     page.has_css?('table tr.foo')
  39.     page.has_content?('foo')
  40.     page.should have_xpath('//table/tr')
  41.     page.should have_css('table tr.foo')
  42.     page.should have_content('foo')
  43.     page.should have_no_content('foo')
  44.     find_field('First Name').value
  45.     find_link('Hello').visible?
  46.     find_button('Send').click
  47.     find('//table/tr').click
  48.     locate("//*[@id='overlay'").find("//h1").click
  49.     all('a').each { |a| a[:href] }
  50.  
  51. #Scripting
  52.     result = page.evaluate_script('4 + 4');
  53.  
  54. #Debugging
  55.     save_and_open_page
  56.  
  57. #Asynchronous JavaScript
  58.     click_link('foo')
  59.     click_link('bar')
  60.     page.should have_content('baz')
  61.     page.should_not have_xpath('//a')
  62.     page.should have_no_xpath('//a')
  63.  
  64. #XPath and CSS
  65.     within(:css, 'ul li') { ... }
  66.     find(:css, 'ul li').text
  67.     locate(:css, 'input#name').value
  68.     Capybara.default_selector = :css
  69.     within('ul li') { ... }
  70.     find('ul li').text
  71.     locate('input#name').value