Guest User

Untitled

a guest
Jan 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  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. sleep(inspection_time=)
  57.  
  58.  
  59. =Asynchronous JavaScript=
  60. click_link('foo')
  61. click_link('bar')
  62. page.should have_content('baz')
  63. page.should_not have_xpath('//a')
  64. page.should have_no_xpath('//a')
  65.  
  66. =XPath and CSS=
  67. within(:css, 'ul li') { ... }
  68. find(:css, 'ul li').text
  69. locate(:css, 'input#name').value
  70. Capybara.default_selector = :css
  71. within('ul li') { ... }
  72. find('ul li').text
  73. locate('input#name').value
Add Comment
Please, Sign In to add comment