Guest User

Untitled

a guest
Sep 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. Capybara
  2. =================
  3.  
  4. Matchers
  5. --------
  6.  
  7. ```ruby
  8. have_button(locator)
  9.  
  10. have_checked_field(locator)
  11.  
  12. have_css('p#foo', :count => 4)
  13. have_css('li', :text => 'Horse', :visible => true)
  14.  
  15. have_field('Name', :with => 'Jonas')
  16. have_field('Email', :type => 'email')
  17.  
  18. have_link(locator, options = {})
  19.  
  20. have_select('Language', :selected => 'German')
  21. have_select('Language', :selected => ['English', 'German'])
  22. have_select('Language', :options => ['English', 'German', 'Spanish'])
  23. have_select('Language', :with_options => ['English', 'German'])
  24.  
  25. have_selector('p#foo')
  26. have_selector(:xpath, './/p[@id="foo"]')
  27. have_selector(:foo)
  28. have_selector('p#foo', :count => 4)
  29. have_selector('li', :text => 'Horse', :visible => true)
  30.  
  31. have_table('People', :rows => [['Jonas', '24'], ['Peter', '32']])
  32.  
  33. have_text(content)
  34. have_content(content)
  35.  
  36. have_unchecked_field?(locator)
  37.  
  38. have_xpath('.//p[@id="foo"]')
  39. have_xpath('.//p[@id="foo"]', :count => 4)
  40. have_xpath('.//li', :text => 'Horse', :visible => true)
  41. ```
  42.  
  43.  
  44. Actions
  45. -------
  46.  
  47. ```ruby
  48. attach_file(locator, path)
  49. page.attach_file(locator, '/path/to/file.png')
  50.  
  51. check(locator)
  52. page.check('German')
  53.  
  54. choose(locator)
  55. page.choose('Male')
  56.  
  57. click_button(locator)
  58. click_link(locator)
  59. click_link_or_button(locator) (also: #click_on)
  60.  
  61. fill_in(locator, options = {})
  62. page.fill_in 'Name', :with => 'Bob'
  63.  
  64. select(value, options = {})
  65. page.select 'March', :from => 'Month'
  66.  
  67. uncheck(locator)
  68. page.uncheck('German')
  69.  
  70. unselect(value, options = {})
  71. page.unselect 'March', :from => 'Month'
  72. ```
  73.  
  74. Session
  75. -------
  76.  
  77. ```ruby
  78. current_host
  79. current_path
  80. current_url
  81. evaluate_script(script)
  82. execute_script(script)
  83. html
  84. reset! # (also: #cleanup!, #reset_session!)
  85. response_headers # Returns a hash of response headers.
  86. save_and_open_page
  87. save_page
  88. source # (also: #body)
  89. status_code
  90. visit(url)
  91. within(*args)
  92. within_fieldset(locator)
  93. within_frame(frame_id)
  94. within_table(locator)
  95. within_window(handle, &blk)
  96. ```
  97.  
  98. Finders
  99. -------
  100.  
  101. ```ruby
  102. all([kind], locator, options)
  103. all(:css, 'a#person_123')
  104. all(:xpath, '//a[@id="person_123"]')
  105. all("a#person_123")
  106. all('a', :text => 'Home')
  107. all('#menu li', :visible => true)
  108.  
  109. find('#foo').find('.bar')
  110. find(:xpath, '//div[contains(., "bar")]')
  111. find('li', :text => 'Quox').click_link('Delete')
  112.  
  113. find_button(locator)
  114. find_by_id(id)
  115. find_field(locator) # aka field_labeled
  116. find_link(locator)
  117. first([kind], locator, options)
  118. ```
Add Comment
Please, Sign In to add comment