mega-max-rb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. checksums.yaml +7 -0
  2. data/capybara-3.40.0/History.md +2043 -0
  3. data/capybara-3.40.0/License.txt +22 -0
  4. data/capybara-3.40.0/README.md +1264 -0
  5. data/capybara-3.40.0/lib/capybara/config.rb +104 -0
  6. data/capybara-3.40.0/lib/capybara/cucumber.rb +27 -0
  7. data/capybara-3.40.0/lib/capybara/driver/base.rb +178 -0
  8. data/capybara-3.40.0/lib/capybara/driver/node.rb +143 -0
  9. data/capybara-3.40.0/lib/capybara/dsl.rb +59 -0
  10. data/capybara-3.40.0/lib/capybara/helpers.rb +127 -0
  11. data/capybara-3.40.0/lib/capybara/minitest/spec.rb +279 -0
  12. data/capybara-3.40.0/lib/capybara/minitest.rb +398 -0
  13. data/capybara-3.40.0/lib/capybara/node/actions.rb +420 -0
  14. data/capybara-3.40.0/lib/capybara/node/base.rb +144 -0
  15. data/capybara-3.40.0/lib/capybara/node/document.rb +48 -0
  16. data/capybara-3.40.0/lib/capybara/node/document_matchers.rb +67 -0
  17. data/capybara-3.40.0/lib/capybara/node/element.rb +613 -0
  18. data/capybara-3.40.0/lib/capybara/node/finders.rb +335 -0
  19. data/capybara-3.40.0/lib/capybara/node/matchers.rb +908 -0
  20. data/capybara-3.40.0/lib/capybara/node/simple.rb +216 -0
  21. data/capybara-3.40.0/lib/capybara/node/whitespace_normalizer.rb +81 -0
  22. data/capybara-3.40.0/lib/capybara/queries/active_element_query.rb +18 -0
  23. data/capybara-3.40.0/lib/capybara/queries/ancestor_query.rb +28 -0
  24. data/capybara-3.40.0/lib/capybara/queries/base_query.rb +106 -0
  25. data/capybara-3.40.0/lib/capybara/queries/current_path_query.rb +61 -0
  26. data/capybara-3.40.0/lib/capybara/queries/match_query.rb +26 -0
  27. data/capybara-3.40.0/lib/capybara/queries/selector_query.rb +761 -0
  28. data/capybara-3.40.0/lib/capybara/queries/sibling_query.rb +27 -0
  29. data/capybara-3.40.0/lib/capybara/queries/style_query.rb +45 -0
  30. data/capybara-3.40.0/lib/capybara/queries/text_query.rb +116 -0
  31. data/capybara-3.40.0/lib/capybara/queries/title_query.rb +39 -0
  32. data/capybara-3.40.0/lib/capybara/rack_test/browser.rb +200 -0
  33. data/capybara-3.40.0/lib/capybara/rack_test/css_handlers.rb +13 -0
  34. data/capybara-3.40.0/lib/capybara/rack_test/driver.rb +110 -0
  35. data/capybara-3.40.0/lib/capybara/rack_test/errors.rb +6 -0
  36. data/capybara-3.40.0/lib/capybara/rack_test/form.rb +149 -0
  37. data/capybara-3.40.0/lib/capybara/rack_test/node.rb +324 -0
  38. data/capybara-3.40.0/lib/capybara/rails.rb +16 -0
  39. data/capybara-3.40.0/lib/capybara/registration_container.rb +41 -0
  40. data/capybara-3.40.0/lib/capybara/registrations/drivers.rb +42 -0
  41. data/capybara-3.40.0/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
  42. data/capybara-3.40.0/lib/capybara/registrations/servers.rb +66 -0
  43. data/capybara-3.40.0/lib/capybara/result.rb +186 -0
  44. data/capybara-3.40.0/lib/capybara/rspec/features.rb +23 -0
  45. data/capybara-3.40.0/lib/capybara/rspec/matcher_proxies.rb +82 -0
  46. data/capybara-3.40.0/lib/capybara/rspec/matchers/base.rb +113 -0
  47. data/capybara-3.40.0/lib/capybara/rspec/matchers/become_closed.rb +33 -0
  48. data/capybara-3.40.0/lib/capybara/rspec/matchers/compound.rb +88 -0
  49. data/capybara-3.40.0/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
  50. data/capybara-3.40.0/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
  51. data/capybara-3.40.0/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
  52. data/capybara-3.40.0/lib/capybara/rspec/matchers/have_selector.rb +69 -0
  53. data/capybara-3.40.0/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
  54. data/capybara-3.40.0/lib/capybara/rspec/matchers/have_text.rb +33 -0
  55. data/capybara-3.40.0/lib/capybara/rspec/matchers/have_title.rb +29 -0
  56. data/capybara-3.40.0/lib/capybara/rspec/matchers/match_selector.rb +27 -0
  57. data/capybara-3.40.0/lib/capybara/rspec/matchers/match_style.rb +43 -0
  58. data/capybara-3.40.0/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  59. data/capybara-3.40.0/lib/capybara/rspec/matchers.rb +207 -0
  60. data/capybara-3.40.0/lib/capybara/rspec.rb +31 -0
  61. data/capybara-3.40.0/lib/capybara/selector/builders/css_builder.rb +84 -0
  62. data/capybara-3.40.0/lib/capybara/selector/builders/xpath_builder.rb +71 -0
  63. data/capybara-3.40.0/lib/capybara/selector/css.rb +102 -0
  64. data/capybara-3.40.0/lib/capybara/selector/definition/button.rb +68 -0
  65. data/capybara-3.40.0/lib/capybara/selector/definition/checkbox.rb +26 -0
  66. data/capybara-3.40.0/lib/capybara/selector/definition/css.rb +10 -0
  67. data/capybara-3.40.0/lib/capybara/selector/definition/datalist_input.rb +35 -0
  68. data/capybara-3.40.0/lib/capybara/selector/definition/datalist_option.rb +25 -0
  69. data/capybara-3.40.0/lib/capybara/selector/definition/element.rb +28 -0
  70. data/capybara-3.40.0/lib/capybara/selector/definition/field.rb +40 -0
  71. data/capybara-3.40.0/lib/capybara/selector/definition/fieldset.rb +14 -0
  72. data/capybara-3.40.0/lib/capybara/selector/definition/file_field.rb +13 -0
  73. data/capybara-3.40.0/lib/capybara/selector/definition/fillable_field.rb +33 -0
  74. data/capybara-3.40.0/lib/capybara/selector/definition/frame.rb +17 -0
  75. data/capybara-3.40.0/lib/capybara/selector/definition/id.rb +6 -0
  76. data/capybara-3.40.0/lib/capybara/selector/definition/label.rb +62 -0
  77. data/capybara-3.40.0/lib/capybara/selector/definition/link.rb +55 -0
  78. data/capybara-3.40.0/lib/capybara/selector/definition/link_or_button.rb +16 -0
  79. data/capybara-3.40.0/lib/capybara/selector/definition/option.rb +27 -0
  80. data/capybara-3.40.0/lib/capybara/selector/definition/radio_button.rb +27 -0
  81. data/capybara-3.40.0/lib/capybara/selector/definition/select.rb +81 -0
  82. data/capybara-3.40.0/lib/capybara/selector/definition/table.rb +109 -0
  83. data/capybara-3.40.0/lib/capybara/selector/definition/table_row.rb +21 -0
  84. data/capybara-3.40.0/lib/capybara/selector/definition/xpath.rb +5 -0
  85. data/capybara-3.40.0/lib/capybara/selector/definition.rb +280 -0
  86. data/capybara-3.40.0/lib/capybara/selector/filter.rb +5 -0
  87. data/capybara-3.40.0/lib/capybara/selector/filter_set.rb +121 -0
  88. data/capybara-3.40.0/lib/capybara/selector/filters/base.rb +77 -0
  89. data/capybara-3.40.0/lib/capybara/selector/filters/expression_filter.rb +22 -0
  90. data/capybara-3.40.0/lib/capybara/selector/filters/locator_filter.rb +29 -0
  91. data/capybara-3.40.0/lib/capybara/selector/filters/node_filter.rb +31 -0
  92. data/capybara-3.40.0/lib/capybara/selector/regexp_disassembler.rb +211 -0
  93. data/capybara-3.40.0/lib/capybara/selector/selector.rb +159 -0
  94. data/capybara-3.40.0/lib/capybara/selector/xpath_extensions.rb +17 -0
  95. data/capybara-3.40.0/lib/capybara/selector.rb +494 -0
  96. data/capybara-3.40.0/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
  97. data/capybara-3.40.0/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
  98. data/capybara-3.40.0/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
  99. data/capybara-3.40.0/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
  100. data/capybara-3.40.0/lib/capybara/selenium/driver.rb +517 -0
  101. data/capybara-3.40.0/lib/capybara/selenium/driver_specializations/chrome_driver.rb +117 -0
  102. data/capybara-3.40.0/lib/capybara/selenium/driver_specializations/edge_driver.rb +128 -0
  103. data/capybara-3.40.0/lib/capybara/selenium/driver_specializations/firefox_driver.rb +84 -0
  104. data/capybara-3.40.0/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
  105. data/capybara-3.40.0/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
  106. data/capybara-3.40.0/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  107. data/capybara-3.40.0/lib/capybara/selenium/extensions/find.rb +110 -0
  108. data/capybara-3.40.0/lib/capybara/selenium/extensions/html5_drag.rb +229 -0
  109. data/capybara-3.40.0/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  110. data/capybara-3.40.0/lib/capybara/selenium/extensions/scroll.rb +76 -0
  111. data/capybara-3.40.0/lib/capybara/selenium/node.rb +636 -0
  112. data/capybara-3.40.0/lib/capybara/selenium/nodes/chrome_node.rb +125 -0
  113. data/capybara-3.40.0/lib/capybara/selenium/nodes/edge_node.rb +110 -0
  114. data/capybara-3.40.0/lib/capybara/selenium/nodes/firefox_node.rb +136 -0
  115. data/capybara-3.40.0/lib/capybara/selenium/nodes/ie_node.rb +22 -0
  116. data/capybara-3.40.0/lib/capybara/selenium/nodes/safari_node.rb +118 -0
  117. data/capybara-3.40.0/lib/capybara/selenium/patches/atoms.rb +18 -0
  118. data/capybara-3.40.0/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  119. data/capybara-3.40.0/lib/capybara/selenium/patches/logs.rb +45 -0
  120. data/capybara-3.40.0/lib/capybara/selenium/patches/pause_duration_fix.rb +9 -0
  121. data/capybara-3.40.0/lib/capybara/selenium/patches/persistent_client.rb +20 -0
  122. data/capybara-3.40.0/lib/capybara/server/animation_disabler.rb +80 -0
  123. data/capybara-3.40.0/lib/capybara/server/checker.rb +44 -0
  124. data/capybara-3.40.0/lib/capybara/server/middleware.rb +71 -0
  125. data/capybara-3.40.0/lib/capybara/server.rb +126 -0
  126. data/capybara-3.40.0/lib/capybara/session/config.rb +128 -0
  127. data/capybara-3.40.0/lib/capybara/session/matchers.rb +87 -0
  128. data/capybara-3.40.0/lib/capybara/session.rb +951 -0
  129. data/capybara-3.40.0/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  130. data/capybara-3.40.0/lib/capybara/spec/fixtures/capybara.jpg +3 -0
  131. data/capybara-3.40.0/lib/capybara/spec/fixtures/no_extension +1 -0
  132. data/capybara-3.40.0/lib/capybara/spec/fixtures/test_file.txt +1 -0
  133. data/capybara-3.40.0/lib/capybara/spec/public/jquery-ui.js +13 -0
  134. data/capybara-3.40.0/lib/capybara/spec/public/jquery.js +5 -0
  135. data/capybara-3.40.0/lib/capybara/spec/public/offset.js +6 -0
  136. data/capybara-3.40.0/lib/capybara/spec/public/test.js +284 -0
  137. data/capybara-3.40.0/lib/capybara/spec/session/accept_alert_spec.rb +81 -0
  138. data/capybara-3.40.0/lib/capybara/spec/session/accept_confirm_spec.rb +32 -0
  139. data/capybara-3.40.0/lib/capybara/spec/session/accept_prompt_spec.rb +78 -0
  140. data/capybara-3.40.0/lib/capybara/spec/session/active_element_spec.rb +31 -0
  141. data/capybara-3.40.0/lib/capybara/spec/session/all_spec.rb +274 -0
  142. data/capybara-3.40.0/lib/capybara/spec/session/ancestor_spec.rb +88 -0
  143. data/capybara-3.40.0/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +140 -0
  144. data/capybara-3.40.0/lib/capybara/spec/session/assert_current_path_spec.rb +75 -0
  145. data/capybara-3.40.0/lib/capybara/spec/session/assert_selector_spec.rb +143 -0
  146. data/capybara-3.40.0/lib/capybara/spec/session/assert_style_spec.rb +26 -0
  147. data/capybara-3.40.0/lib/capybara/spec/session/assert_text_spec.rb +258 -0
  148. data/capybara-3.40.0/lib/capybara/spec/session/assert_title_spec.rb +93 -0
  149. data/capybara-3.40.0/lib/capybara/spec/session/attach_file_spec.rb +222 -0
  150. data/capybara-3.40.0/lib/capybara/spec/session/body_spec.rb +23 -0
  151. data/capybara-3.40.0/lib/capybara/spec/session/check_spec.rb +251 -0
  152. data/capybara-3.40.0/lib/capybara/spec/session/choose_spec.rb +127 -0
  153. data/capybara-3.40.0/lib/capybara/spec/session/click_button_spec.rb +517 -0
  154. data/capybara-3.40.0/lib/capybara/spec/session/click_link_or_button_spec.rb +138 -0
  155. data/capybara-3.40.0/lib/capybara/spec/session/click_link_spec.rb +240 -0
  156. data/capybara-3.40.0/lib/capybara/spec/session/current_scope_spec.rb +31 -0
  157. data/capybara-3.40.0/lib/capybara/spec/session/current_url_spec.rb +125 -0
  158. data/capybara-3.40.0/lib/capybara/spec/session/dismiss_confirm_spec.rb +36 -0
  159. data/capybara-3.40.0/lib/capybara/spec/session/dismiss_prompt_spec.rb +21 -0
  160. data/capybara-3.40.0/lib/capybara/spec/session/element/assert_match_selector_spec.rb +38 -0
  161. data/capybara-3.40.0/lib/capybara/spec/session/element/match_css_spec.rb +31 -0
  162. data/capybara-3.40.0/lib/capybara/spec/session/element/match_xpath_spec.rb +25 -0
  163. data/capybara-3.40.0/lib/capybara/spec/session/element/matches_selector_spec.rb +120 -0
  164. data/capybara-3.40.0/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
  165. data/capybara-3.40.0/lib/capybara/spec/session/evaluate_script_spec.rb +49 -0
  166. data/capybara-3.40.0/lib/capybara/spec/session/execute_script_spec.rb +28 -0
  167. data/capybara-3.40.0/lib/capybara/spec/session/fill_in_spec.rb +292 -0
  168. data/capybara-3.40.0/lib/capybara/spec/session/find_button_spec.rb +74 -0
  169. data/capybara-3.40.0/lib/capybara/spec/session/find_by_id_spec.rb +33 -0
  170. data/capybara-3.40.0/lib/capybara/spec/session/find_field_spec.rb +113 -0
  171. data/capybara-3.40.0/lib/capybara/spec/session/find_link_spec.rb +80 -0
  172. data/capybara-3.40.0/lib/capybara/spec/session/find_spec.rb +545 -0
  173. data/capybara-3.40.0/lib/capybara/spec/session/first_spec.rb +156 -0
  174. data/capybara-3.40.0/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
  175. data/capybara-3.40.0/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
  176. data/capybara-3.40.0/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +116 -0
  177. data/capybara-3.40.0/lib/capybara/spec/session/frame/within_frame_spec.rb +114 -0
  178. data/capybara-3.40.0/lib/capybara/spec/session/go_back_spec.rb +12 -0
  179. data/capybara-3.40.0/lib/capybara/spec/session/go_forward_spec.rb +14 -0
  180. data/capybara-3.40.0/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
  181. data/capybara-3.40.0/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
  182. data/capybara-3.40.0/lib/capybara/spec/session/has_any_selectors_spec.rb +29 -0
  183. data/capybara-3.40.0/lib/capybara/spec/session/has_button_spec.rb +150 -0
  184. data/capybara-3.40.0/lib/capybara/spec/session/has_css_spec.rb +375 -0
  185. data/capybara-3.40.0/lib/capybara/spec/session/has_current_path_spec.rb +151 -0
  186. data/capybara-3.40.0/lib/capybara/spec/session/has_element_spec.rb +47 -0
  187. data/capybara-3.40.0/lib/capybara/spec/session/has_field_spec.rb +389 -0
  188. data/capybara-3.40.0/lib/capybara/spec/session/has_link_spec.rb +79 -0
  189. data/capybara-3.40.0/lib/capybara/spec/session/has_none_selectors_spec.rb +78 -0
  190. data/capybara-3.40.0/lib/capybara/spec/session/has_select_spec.rb +316 -0
  191. data/capybara-3.40.0/lib/capybara/spec/session/has_selector_spec.rb +217 -0
  192. data/capybara-3.40.0/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
  193. data/capybara-3.40.0/lib/capybara/spec/session/has_table_spec.rb +209 -0
  194. data/capybara-3.40.0/lib/capybara/spec/session/has_text_spec.rb +375 -0
  195. data/capybara-3.40.0/lib/capybara/spec/session/has_title_spec.rb +71 -0
  196. data/capybara-3.40.0/lib/capybara/spec/session/has_xpath_spec.rb +149 -0
  197. data/capybara-3.40.0/lib/capybara/spec/session/headers_spec.rb +8 -0
  198. data/capybara-3.40.0/lib/capybara/spec/session/html_spec.rb +47 -0
  199. data/capybara-3.40.0/lib/capybara/spec/session/matches_style_spec.rb +37 -0
  200. data/capybara-3.40.0/lib/capybara/spec/session/node_spec.rb +1399 -0
  201. data/capybara-3.40.0/lib/capybara/spec/session/node_wrapper_spec.rb +39 -0
  202. data/capybara-3.40.0/lib/capybara/spec/session/refresh_spec.rb +34 -0
  203. data/capybara-3.40.0/lib/capybara/spec/session/reset_session_spec.rb +161 -0
  204. data/capybara-3.40.0/lib/capybara/spec/session/response_code_spec.rb +8 -0
  205. data/capybara-3.40.0/lib/capybara/spec/session/save_and_open_page_spec.rb +21 -0
  206. data/capybara-3.40.0/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +43 -0
  207. data/capybara-3.40.0/lib/capybara/spec/session/save_page_spec.rb +110 -0
  208. data/capybara-3.40.0/lib/capybara/spec/session/save_screenshot_spec.rb +55 -0
  209. data/capybara-3.40.0/lib/capybara/spec/session/screenshot_spec.rb +18 -0
  210. data/capybara-3.40.0/lib/capybara/spec/session/scroll_spec.rb +119 -0
  211. data/capybara-3.40.0/lib/capybara/spec/session/select_spec.rb +229 -0
  212. data/capybara-3.40.0/lib/capybara/spec/session/selectors_spec.rb +98 -0
  213. data/capybara-3.40.0/lib/capybara/spec/session/sibling_spec.rb +52 -0
  214. data/capybara-3.40.0/lib/capybara/spec/session/text_spec.rb +74 -0
  215. data/capybara-3.40.0/lib/capybara/spec/session/title_spec.rb +29 -0
  216. data/capybara-3.40.0/lib/capybara/spec/session/uncheck_spec.rb +100 -0
  217. data/capybara-3.40.0/lib/capybara/spec/session/unselect_spec.rb +116 -0
  218. data/capybara-3.40.0/lib/capybara/spec/session/visit_spec.rb +224 -0
  219. data/capybara-3.40.0/lib/capybara/spec/session/window/become_closed_spec.rb +89 -0
  220. data/capybara-3.40.0/lib/capybara/spec/session/window/current_window_spec.rb +28 -0
  221. data/capybara-3.40.0/lib/capybara/spec/session/window/open_new_window_spec.rb +31 -0
  222. data/capybara-3.40.0/lib/capybara/spec/session/window/switch_to_window_spec.rb +132 -0
  223. data/capybara-3.40.0/lib/capybara/spec/session/window/window_opened_by_spec.rb +99 -0
  224. data/capybara-3.40.0/lib/capybara/spec/session/window/window_spec.rb +203 -0
  225. data/capybara-3.40.0/lib/capybara/spec/session/window/windows_spec.rb +34 -0
  226. data/capybara-3.40.0/lib/capybara/spec/session/window/within_window_spec.rb +157 -0
  227. data/capybara-3.40.0/lib/capybara/spec/session/within_spec.rb +212 -0
  228. data/capybara-3.40.0/lib/capybara/spec/spec_helper.rb +141 -0
  229. data/capybara-3.40.0/lib/capybara/spec/test_app.rb +305 -0
  230. data/capybara-3.40.0/lib/capybara/spec/views/animated.erb +49 -0
  231. data/capybara-3.40.0/lib/capybara/spec/views/buttons.erb +5 -0
  232. data/capybara-3.40.0/lib/capybara/spec/views/fieldsets.erb +30 -0
  233. data/capybara-3.40.0/lib/capybara/spec/views/form.erb +738 -0
  234. data/capybara-3.40.0/lib/capybara/spec/views/frame_child.erb +18 -0
  235. data/capybara-3.40.0/lib/capybara/spec/views/frame_one.erb +10 -0
  236. data/capybara-3.40.0/lib/capybara/spec/views/frame_parent.erb +9 -0
  237. data/capybara-3.40.0/lib/capybara/spec/views/frame_two.erb +9 -0
  238. data/capybara-3.40.0/lib/capybara/spec/views/header_links.erb +8 -0
  239. data/capybara-3.40.0/lib/capybara/spec/views/host_links.erb +13 -0
  240. data/capybara-3.40.0/lib/capybara/spec/views/initial_alert.erb +11 -0
  241. data/capybara-3.40.0/lib/capybara/spec/views/layout.erb +10 -0
  242. data/capybara-3.40.0/lib/capybara/spec/views/obscured.erb +47 -0
  243. data/capybara-3.40.0/lib/capybara/spec/views/offset.erb +33 -0
  244. data/capybara-3.40.0/lib/capybara/spec/views/path.erb +13 -0
  245. data/capybara-3.40.0/lib/capybara/spec/views/popup_one.erb +9 -0
  246. data/capybara-3.40.0/lib/capybara/spec/views/popup_two.erb +9 -0
  247. data/capybara-3.40.0/lib/capybara/spec/views/postback.erb +14 -0
  248. data/capybara-3.40.0/lib/capybara/spec/views/react.erb +45 -0
  249. data/capybara-3.40.0/lib/capybara/spec/views/scroll.erb +21 -0
  250. data/capybara-3.40.0/lib/capybara/spec/views/spatial.erb +31 -0
  251. data/capybara-3.40.0/lib/capybara/spec/views/tables.erb +130 -0
  252. data/capybara-3.40.0/lib/capybara/spec/views/with_animation.erb +81 -0
  253. data/capybara-3.40.0/lib/capybara/spec/views/with_base_tag.erb +11 -0
  254. data/capybara-3.40.0/lib/capybara/spec/views/with_count.erb +8 -0
  255. data/capybara-3.40.0/lib/capybara/spec/views/with_dragula.erb +24 -0
  256. data/capybara-3.40.0/lib/capybara/spec/views/with_fixed_header_footer.erb +18 -0
  257. data/capybara-3.40.0/lib/capybara/spec/views/with_hover.erb +24 -0
  258. data/capybara-3.40.0/lib/capybara/spec/views/with_hover1.erb +10 -0
  259. data/capybara-3.40.0/lib/capybara/spec/views/with_html.erb +210 -0
  260. data/capybara-3.40.0/lib/capybara/spec/views/with_html5_svg.erb +20 -0
  261. data/capybara-3.40.0/lib/capybara/spec/views/with_html_entities.erb +2 -0
  262. data/capybara-3.40.0/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  263. data/capybara-3.40.0/lib/capybara/spec/views/with_js.erb +162 -0
  264. data/capybara-3.40.0/lib/capybara/spec/views/with_jstree.erb +26 -0
  265. data/capybara-3.40.0/lib/capybara/spec/views/with_namespace.erb +21 -0
  266. data/capybara-3.40.0/lib/capybara/spec/views/with_scope.erb +42 -0
  267. data/capybara-3.40.0/lib/capybara/spec/views/with_scope_other.erb +6 -0
  268. data/capybara-3.40.0/lib/capybara/spec/views/with_shadow.erb +31 -0
  269. data/capybara-3.40.0/lib/capybara/spec/views/with_simple_html.erb +2 -0
  270. data/capybara-3.40.0/lib/capybara/spec/views/with_slow_unload.erb +18 -0
  271. data/capybara-3.40.0/lib/capybara/spec/views/with_sortable_js.erb +21 -0
  272. data/capybara-3.40.0/lib/capybara/spec/views/with_unload_alert.erb +15 -0
  273. data/capybara-3.40.0/lib/capybara/spec/views/with_windows.erb +54 -0
  274. data/capybara-3.40.0/lib/capybara/spec/views/within_frames.erb +15 -0
  275. data/capybara-3.40.0/lib/capybara/version.rb +5 -0
  276. data/capybara-3.40.0/lib/capybara/window.rb +142 -0
  277. data/capybara-3.40.0/lib/capybara.rb +521 -0
  278. data/capybara-3.40.0/spec/basic_node_spec.rb +168 -0
  279. data/capybara-3.40.0/spec/capybara_spec.rb +124 -0
  280. data/capybara-3.40.0/spec/counter_spec.rb +35 -0
  281. data/capybara-3.40.0/spec/css_builder_spec.rb +101 -0
  282. data/capybara-3.40.0/spec/css_splitter_spec.rb +38 -0
  283. data/capybara-3.40.0/spec/dsl_spec.rb +291 -0
  284. data/capybara-3.40.0/spec/filter_set_spec.rb +46 -0
  285. data/capybara-3.40.0/spec/fixtures/capybara.csv +1 -0
  286. data/capybara-3.40.0/spec/fixtures/certificate.pem +25 -0
  287. data/capybara-3.40.0/spec/fixtures/key.pem +27 -0
  288. data/capybara-3.40.0/spec/fixtures/selenium_driver_rspec_failure.rb +13 -0
  289. data/capybara-3.40.0/spec/fixtures/selenium_driver_rspec_success.rb +13 -0
  290. data/capybara-3.40.0/spec/minitest_spec.rb +175 -0
  291. data/capybara-3.40.0/spec/minitest_spec_spec.rb +166 -0
  292. data/capybara-3.40.0/spec/per_session_config_spec.rb +68 -0
  293. data/capybara-3.40.0/spec/rack_test_spec.rb +297 -0
  294. data/capybara-3.40.0/spec/regexp_dissassembler_spec.rb +250 -0
  295. data/capybara-3.40.0/spec/result_spec.rb +202 -0
  296. data/capybara-3.40.0/spec/rspec/features_spec.rb +101 -0
  297. data/capybara-3.40.0/spec/rspec/scenarios_spec.rb +23 -0
  298. data/capybara-3.40.0/spec/rspec/shared_spec_matchers.rb +983 -0
  299. data/capybara-3.40.0/spec/rspec/views_spec.rb +14 -0
  300. data/capybara-3.40.0/spec/rspec_matchers_spec.rb +87 -0
  301. data/capybara-3.40.0/spec/rspec_spec.rb +149 -0
  302. data/capybara-3.40.0/spec/sauce_spec_chrome.rb +43 -0
  303. data/capybara-3.40.0/spec/selector_spec.rb +528 -0
  304. data/capybara-3.40.0/spec/selenium_spec_chrome.rb +209 -0
  305. data/capybara-3.40.0/spec/selenium_spec_chrome_remote.rb +96 -0
  306. data/capybara-3.40.0/spec/selenium_spec_edge.rb +60 -0
  307. data/capybara-3.40.0/spec/selenium_spec_firefox.rb +228 -0
  308. data/capybara-3.40.0/spec/selenium_spec_firefox_remote.rb +94 -0
  309. data/capybara-3.40.0/spec/selenium_spec_ie.rb +149 -0
  310. data/capybara-3.40.0/spec/selenium_spec_safari.rb +162 -0
  311. data/capybara-3.40.0/spec/server_spec.rb +315 -0
  312. data/capybara-3.40.0/spec/session_spec.rb +91 -0
  313. data/capybara-3.40.0/spec/shared_selenium_node.rb +79 -0
  314. data/capybara-3.40.0/spec/shared_selenium_session.rb +566 -0
  315. data/capybara-3.40.0/spec/spec_helper.rb +133 -0
  316. data/capybara-3.40.0/spec/whitespace_normalizer_spec.rb +54 -0
  317. data/capybara-3.40.0/spec/xpath_builder_spec.rb +93 -0
  318. data/mega-max-rb.gemspec +12 -0
  319. metadata +358 -0
@@ -0,0 +1,1264 @@
1
+ # Capybara
2
+
3
+ [![Build Status](https://github.com/teamcapybara/capybara/actions/workflows/build.yml/badge.svg)](https://github.com/teamcapybara/capybara/actions/workflows/build.yml)
4
+ [![Code Climate](https://codeclimate.com/github/teamcapybara/capybara.svg)](https://codeclimate.com/github/teamcapybara/capybara)
5
+ [![Coverage Status](https://coveralls.io/repos/github/teamcapybara/capybara/badge.svg?branch=master)](https://coveralls.io/github/teamcapybara/capybara?branch=master)
6
+
7
+ Capybara helps you test web applications by simulating how a real user would
8
+ interact with your app. It is agnostic about the driver running your tests and
9
+ comes with Rack::Test and Selenium support built in. WebKit is supported
10
+ through an external gem.
11
+
12
+ ## Support Capybara
13
+
14
+ If you and/or your company find value in Capybara and would like to contribute financially to its ongoing maintenance and development, please visit
15
+ <a href="https://www.patreon.com/capybara">Patreon</a>
16
+
17
+
18
+ **Need help?** Ask on the discussions (please do not open an issue): https://github.com/orgs/teamcapybara/discussions/categories/q-a
19
+
20
+ ## Table of contents
21
+
22
+ - [Key benefits](#key-benefits)
23
+ - [Setup](#setup)
24
+ - [Using Capybara with Cucumber](#using-capybara-with-cucumber)
25
+ - [Using Capybara with RSpec](#using-capybara-with-rspec)
26
+ - [Using Capybara with Test::Unit](#using-capybara-with-testunit)
27
+ - [Using Capybara with Minitest](#using-capybara-with-minitest)
28
+ - [Using Capybara with Minitest::Spec](#using-capybara-with-minitestspec)
29
+ - [Drivers](#drivers)
30
+ - [Selecting the Driver](#selecting-the-driver)
31
+ - [RackTest](#racktest)
32
+ - [Selenium](#selenium)
33
+ - [The DSL](#the-dsl)
34
+ - [Navigating](#navigating)
35
+ - [Clicking links and buttons](#clicking-links-and-buttons)
36
+ - [Interacting with forms](#interacting-with-forms)
37
+ - [Querying](#querying)
38
+ - [Finding](#finding)
39
+ - [Scoping](#scoping)
40
+ - [Working with windows](#working-with-windows)
41
+ - [Scripting](#scripting)
42
+ - [Modals](#modals)
43
+ - [Debugging](#debugging)
44
+ - [Selectors](#selectors)
45
+ - [Name](#selectors-name)
46
+ - [Locator](#selectors-locator)
47
+ - [Filters](#selectors-filters)
48
+ - [Matching](#matching)
49
+ - [Exactness](#exactness)
50
+ - [Strategy](#strategy)
51
+ - [Transactions and database setup](#transactions-and-database-setup)
52
+ - [Asynchronous JavaScript (Ajax and friends)](#asynchronous-javascript-ajax-and-friends)
53
+ - [Using the DSL elsewhere](#using-the-dsl-elsewhere)
54
+ - [Calling remote servers](#calling-remote-servers)
55
+ - [Using sessions](#using-sessions)
56
+ - [Named sessions](#named-sessions)
57
+ - [Using sessions manually](#using-sessions-manually)
58
+ - [XPath, CSS and selectors](#xpath-css-and-selectors)
59
+ - [Beware the XPath // trap](#beware-the-xpath--trap)
60
+ - [Configuring and adding drivers](#configuring-and-adding-drivers)
61
+ - [Gotchas:](#gotchas)
62
+ - ["Threadsafe" mode](#threadsafe-mode)
63
+ - [Development](#development)
64
+
65
+ ## <a name="key-benefits"></a>Key benefits
66
+
67
+ - **No setup** necessary for Rails and Rack application. Works out of the box.
68
+ - **Intuitive API** which mimics the language an actual user would use.
69
+ - **Switch the backend** your tests run against from fast headless mode
70
+ to an actual browser with no changes to your tests.
71
+ - **Powerful synchronization** features mean you never have to manually wait
72
+ for asynchronous processes to complete.
73
+
74
+ ## <a name="setup"></a>Setup
75
+
76
+ Capybara requires Ruby 3.0.0 or later. To install, add this line to your
77
+ `Gemfile` and run `bundle install`:
78
+
79
+ ```ruby
80
+ gem 'capybara'
81
+ ```
82
+
83
+ If the application that you are testing is a Rails app, add this line to your test helper file:
84
+
85
+ ```ruby
86
+ require 'capybara/rails'
87
+ ```
88
+
89
+ If the application that you are testing is a Rack app, but not Rails, set Capybara.app to your Rack app:
90
+
91
+ ```ruby
92
+ Capybara.app = MyRackApp
93
+ ```
94
+
95
+ If you need to test JavaScript, or if your app interacts with (or is located at)
96
+ a remote URL, you'll need to [use a different driver](#drivers). If using Rails 5.0+, but not using the Rails system tests from 5.1, you'll probably also
97
+ want to swap the "server" used to launch your app to Puma in order to match Rails defaults.
98
+
99
+ ```ruby
100
+ Capybara.server = :puma # Until your setup is working
101
+ Capybara.server = :puma, { Silent: true } # To clean up your test output
102
+ ```
103
+
104
+ ## <a name="using-capybara-with-cucumber"></a>Using Capybara with Cucumber
105
+
106
+ The `cucumber-rails` gem comes with Capybara support built-in. If you
107
+ are not using Rails, manually load the `capybara/cucumber` module:
108
+
109
+ ```ruby
110
+ require 'capybara/cucumber'
111
+ Capybara.app = MyRackApp
112
+ ```
113
+
114
+ You can use the Capybara DSL in your steps, like so:
115
+
116
+ ```ruby
117
+ When /I sign in/ do
118
+ within("#session") do
119
+ fill_in 'Email', with: 'user@example.com'
120
+ fill_in 'Password', with: 'password'
121
+ end
122
+ click_button 'Sign in'
123
+ end
124
+ ```
125
+
126
+ You can switch to the `Capybara.javascript_driver` (`:selenium`
127
+ by default) by tagging scenarios (or features) with `@javascript`:
128
+
129
+ ```ruby
130
+ @javascript
131
+ Scenario: do something Ajaxy
132
+ When I click the Ajax link
133
+ ...
134
+ ```
135
+
136
+ There are also explicit tags for each registered driver set up for you (`@selenium`, `@rack_test`, etc).
137
+
138
+ ## <a name="using-capybara-with-rspec"></a>Using Capybara with RSpec
139
+
140
+ Load RSpec 3.5+ support by adding the following line (typically to your
141
+ `spec_helper.rb` file):
142
+
143
+ ```ruby
144
+ require 'capybara/rspec'
145
+ ```
146
+
147
+ If you are using Rails, put your Capybara specs in `spec/features` or `spec/system` (only works if
148
+ [you have it configured in RSpec](https://rspec.info/features/6-0/rspec-rails/directory-structure/))
149
+ and if you have your Capybara specs in a different directory, then tag the example groups with
150
+ `type: :feature` or `type: :system` depending on which type of test you're writing.
151
+
152
+ If you are using Rails system specs please see [their documentation](https://rspec.info/features/6-0/rspec-rails/system-specs/system-specs)
153
+ for selecting the driver you wish to use.
154
+
155
+ If you are not using Rails, tag all the example groups in which you want to use
156
+ Capybara with `type: :feature`.
157
+
158
+ You can now write your specs like so:
159
+
160
+ ```ruby
161
+ describe "the signin process", type: :feature do
162
+ before :each do
163
+ User.create(email: 'user@example.com', password: 'password')
164
+ end
165
+
166
+ it "signs me in" do
167
+ visit '/sessions/new'
168
+ within("#session") do
169
+ fill_in 'Email', with: 'user@example.com'
170
+ fill_in 'Password', with: 'password'
171
+ end
172
+ click_button 'Sign in'
173
+ expect(page).to have_content 'Success'
174
+ end
175
+ end
176
+ ```
177
+
178
+ Use `js: true` to switch to the `Capybara.javascript_driver`
179
+ (`:selenium` by default), or provide a `:driver` option to switch
180
+ to one specific driver. For example:
181
+
182
+ ```ruby
183
+ describe 'some stuff which requires js', js: true do
184
+ it 'will use the default js driver'
185
+ it 'will switch to one specific driver', driver: :selenium
186
+ end
187
+ ```
188
+
189
+ Capybara also comes with a built in DSL for creating descriptive acceptance tests:
190
+
191
+ ```ruby
192
+ feature "Signing in" do
193
+ background do
194
+ User.create(email: 'user@example.com', password: 'caplin')
195
+ end
196
+
197
+ scenario "Signing in with correct credentials" do
198
+ visit '/sessions/new'
199
+ within("#session") do
200
+ fill_in 'Email', with: 'user@example.com'
201
+ fill_in 'Password', with: 'caplin'
202
+ end
203
+ click_button 'Sign in'
204
+ expect(page).to have_content 'Success'
205
+ end
206
+
207
+ given(:other_user) { User.create(email: 'other@example.com', password: 'rous') }
208
+
209
+ scenario "Signing in as another user" do
210
+ visit '/sessions/new'
211
+ within("#session") do
212
+ fill_in 'Email', with: other_user.email
213
+ fill_in 'Password', with: other_user.password
214
+ end
215
+ click_button 'Sign in'
216
+ expect(page).to have_content 'Invalid email or password'
217
+ end
218
+ end
219
+ ```
220
+
221
+ `feature` is in fact just an alias for `describe ..., type: :feature`,
222
+ `background` is an alias for `before`, `scenario` for `it`, and
223
+ `given`/`given!` aliases for `let`/`let!`, respectively.
224
+
225
+ Finally, Capybara matchers are also supported in view specs:
226
+
227
+ ```ruby
228
+ RSpec.describe "todos/show.html.erb", type: :view do
229
+ it "displays the todo title" do
230
+ assign :todo, Todo.new(title: "Buy milk")
231
+
232
+ render
233
+
234
+ expect(rendered).to have_css("header h1", text: "Buy milk")
235
+ end
236
+ end
237
+ ```
238
+
239
+ **Note: When you require 'capybara/rspec' proxy methods are installed to work around name collisions between Capybara::DSL methods
240
+ `all`/`within` and the identically named built-in RSpec matchers. If you opt not to require 'capybara/rspec' you can install the proxy methods by requiring 'capybara/rspec/matcher_proxies' after requiring RSpec and 'capybara/dsl'**
241
+
242
+ ## <a name="using-capybara-with-testunit"></a>Using Capybara with Test::Unit
243
+
244
+ * If you are using `Test::Unit`, define a base class for your Capybara tests
245
+ like so:
246
+
247
+ ```ruby
248
+ require 'capybara/dsl'
249
+
250
+ class CapybaraTestCase < Test::Unit::TestCase
251
+ include Capybara::DSL
252
+
253
+ def teardown
254
+ Capybara.reset_sessions!
255
+ Capybara.use_default_driver
256
+ end
257
+ end
258
+ ```
259
+
260
+ ## <a name="using-capybara-with-minitest"></a>Using Capybara with Minitest
261
+
262
+ * If you are using Rails system tests please see their documentation for information on selecting the driver you wish to use.
263
+
264
+ * If you are using Rails, but not using Rails system tests, add the following code in your `test_helper.rb`
265
+ file to make Capybara available in all test cases deriving from
266
+ `ActionDispatch::IntegrationTest`:
267
+
268
+ ```ruby
269
+ require 'capybara/rails'
270
+ require 'capybara/minitest'
271
+
272
+ class ActionDispatch::IntegrationTest
273
+ # Make the Capybara DSL available in all integration tests
274
+ include Capybara::DSL
275
+ # Make `assert_*` methods behave like Minitest assertions
276
+ include Capybara::Minitest::Assertions
277
+
278
+ # Reset sessions and driver between tests
279
+ teardown do
280
+ Capybara.reset_sessions!
281
+ Capybara.use_default_driver
282
+ end
283
+ end
284
+ ```
285
+
286
+ * If you are not using Rails, define a base class for your Capybara tests like
287
+ so:
288
+
289
+ ```ruby
290
+ require 'capybara/minitest'
291
+
292
+ class CapybaraTestCase < Minitest::Test
293
+ include Capybara::DSL
294
+ include Capybara::Minitest::Assertions
295
+
296
+ def teardown
297
+ Capybara.reset_sessions!
298
+ Capybara.use_default_driver
299
+ end
300
+ end
301
+ ```
302
+
303
+ Remember to call `super` in any subclasses that override
304
+ `teardown`.
305
+
306
+ To switch the driver, set `Capybara.current_driver`. For instance,
307
+
308
+ ```ruby
309
+ class BlogTest < ActionDispatch::IntegrationTest
310
+ setup do
311
+ Capybara.current_driver = Capybara.javascript_driver # :selenium by default
312
+ end
313
+
314
+ test 'shows blog posts' do
315
+ # ... this test is run with Selenium ...
316
+ end
317
+ end
318
+ ```
319
+
320
+ ## <a name="using-capybara-with-minitestspec"></a>Using Capybara with Minitest::Spec
321
+
322
+ Follow the above instructions for Minitest and additionally require capybara/minitest/spec
323
+
324
+ ```ruby
325
+ page.must_have_content('Important!')
326
+ ```
327
+
328
+ ## <a name="drivers"></a>Drivers
329
+
330
+ Capybara uses the same DSL to drive a variety of browser and headless drivers.
331
+
332
+ ### <a name="selecting-the-driver"></a>Selecting the Driver
333
+
334
+ By default, Capybara uses the `:rack_test` driver, which is fast but limited: it
335
+ does not support JavaScript, nor is it able to access HTTP resources outside of
336
+ your Rack application, such as remote APIs and OAuth services. To get around
337
+ these limitations, you can set up a different default driver for your features.
338
+ For example, if you'd prefer to run everything in Selenium, you could do:
339
+
340
+ ```ruby
341
+ Capybara.default_driver = :selenium # :selenium_chrome and :selenium_chrome_headless are also registered
342
+ ```
343
+
344
+ However, if you are using RSpec or Cucumber (and your app runs correctly without JS),
345
+ you may instead want to consider leaving the faster `:rack_test` as the __default_driver__, and
346
+ marking only those tests that require a JavaScript-capable driver using `js: true` or
347
+ `@javascript`, respectively. By default, JavaScript tests are run using the
348
+ `:selenium` driver. You can change this by setting
349
+ `Capybara.javascript_driver`.
350
+
351
+ You can also change the driver temporarily (typically in the Before/setup and
352
+ After/teardown blocks):
353
+
354
+ ```ruby
355
+ Capybara.current_driver = :selenium # temporarily select different driver
356
+ # tests here
357
+ Capybara.use_default_driver # switch back to default driver
358
+ ```
359
+
360
+ **Note**: switching the driver creates a new session, so you may not be able to
361
+ switch in the middle of a test.
362
+
363
+ ### <a name="racktest"></a>RackTest
364
+
365
+ RackTest is Capybara's default driver. It is written in pure Ruby and does not
366
+ have any support for executing JavaScript. Since the RackTest driver interacts
367
+ directly with Rack interfaces, it does not require a server to be started.
368
+ However, this means that if your application is not a Rack application (Rails,
369
+ Sinatra and most other Ruby frameworks are Rack applications) then you cannot
370
+ use this driver. Furthermore, you cannot use the RackTest driver to test a
371
+ remote application, or to access remote URLs (e.g., redirects to external
372
+ sites, external APIs, or OAuth services) that your application might interact
373
+ with.
374
+
375
+ [capybara-mechanize](https://github.com/jeroenvandijk/capybara-mechanize)
376
+ provides a similar driver that can access remote servers.
377
+
378
+ RackTest can be configured with a set of headers like this:
379
+
380
+ ```ruby
381
+ Capybara.register_driver :rack_test do |app|
382
+ Capybara::RackTest::Driver.new(app, headers: { 'HTTP_USER_AGENT' => 'Capybara' })
383
+ end
384
+ ```
385
+
386
+ See the section on adding and configuring drivers.
387
+
388
+ ### <a name="selenium"></a>Selenium
389
+
390
+ Capybara supports [Selenium 3.5+
391
+ (Webdriver)](https://www.seleniumhq.org/projects/webdriver/).
392
+ In order to use Selenium, you'll need to install the `selenium-webdriver` gem,
393
+ and add it to your Gemfile if you're using bundler.
394
+
395
+ Capybara pre-registers a number of named drivers that use Selenium - they are:
396
+
397
+ * :selenium => Selenium driving Firefox
398
+ * :selenium_headless => Selenium driving Firefox in a headless configuration
399
+ * :selenium_chrome => Selenium driving Chrome
400
+ * :selenium_chrome_headless => Selenium driving Chrome in a headless configuration
401
+
402
+ These should work (with relevant software installation) in a local desktop configuration but you may
403
+ need to customize them if using in a CI environment where additional options may need to be passed
404
+ to the browsers. See the section on adding and configuring drivers.
405
+
406
+
407
+ **Note**: drivers which run the server in a different thread may not share the
408
+ same transaction as your tests, causing data not to be shared between your test
409
+ and test server, see [Transactions and database setup](#transactions-and-database-setup) below.
410
+
411
+ ## <a name="the-dsl"></a>The DSL
412
+
413
+ *A complete reference is available at
414
+ [rubydoc.info](http://rubydoc.info/github/teamcapybara/capybara/master)*.
415
+
416
+ **Note: By default Capybara will only locate visible elements. This is because
417
+ a real user would not be able to interact with non-visible elements.**
418
+
419
+ **Note**: All searches in Capybara are *case sensitive*. This is because
420
+ Capybara heavily uses XPath, which doesn't support case insensitivity.
421
+
422
+ ### <a name="navigating"></a>Navigating
423
+
424
+ You can use the
425
+ <tt>[visit](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Session#visit-instance_method)</tt>
426
+ method to navigate to other pages:
427
+
428
+ ```ruby
429
+ visit('/projects')
430
+ visit(post_comments_path(post))
431
+ ```
432
+
433
+ The visit method only takes a single parameter, the request method is **always**
434
+ GET.
435
+
436
+ You can get the [current path](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Session#current_path-instance_method)
437
+ of the browsing session, and test it using the [`have_current_path`](http://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method) matcher:
438
+
439
+ ```ruby
440
+ expect(page).to have_current_path(post_comments_path(post))
441
+ ```
442
+
443
+ **Note**: You can also assert the current path by testing the value of
444
+ `current_path` directly. However, using the `have_current_path` matcher is
445
+ safer since it uses Capybara's [waiting behaviour](#asynchronous-javascript-ajax-and-friends)
446
+ to ensure that preceding actions (such as a `click_link`) have completed.
447
+
448
+ ### <a name="clicking-links-and-buttons"></a>Clicking links and buttons
449
+
450
+ *Full reference: [Capybara::Node::Actions](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Actions)*
451
+
452
+ You can interact with the webapp by following links and buttons. Capybara
453
+ automatically follows any redirects, and submits forms associated with buttons.
454
+
455
+ ```ruby
456
+ click_link('id-of-link')
457
+ click_link('Link Text')
458
+ click_button('Save')
459
+ click_on('Link Text') # clicks on either links or buttons
460
+ click_on('Button Value')
461
+ ```
462
+
463
+ ### <a name="interacting-with-forms"></a>Interacting with forms
464
+
465
+ *Full reference: [Capybara::Node::Actions](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Actions)*
466
+
467
+ There are a number of tools for interacting with form elements:
468
+
469
+ ```ruby
470
+ fill_in('First Name', with: 'John')
471
+ fill_in('Password', with: 'Seekrit')
472
+ fill_in('Description', with: 'Really Long Text...')
473
+ choose('A Radio Button')
474
+ check('A Checkbox')
475
+ uncheck('A Checkbox')
476
+ attach_file('Image', '/path/to/image.jpg')
477
+ select('Option', from: 'Select Box')
478
+ ```
479
+
480
+ ### <a name="querying"></a>Querying
481
+
482
+ *Full reference: [Capybara::Node::Matchers](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Matchers)*
483
+
484
+ Capybara has a rich set of options for querying the page for the existence of
485
+ certain elements, and working with and manipulating those elements.
486
+
487
+ ```ruby
488
+ page.has_selector?('table tr')
489
+ page.has_selector?(:xpath, './/table/tr')
490
+
491
+ page.has_xpath?('.//table/tr')
492
+ page.has_css?('table tr.foo')
493
+ page.has_content?('foo')
494
+ ```
495
+
496
+ **Note:** The negative forms like `has_no_selector?` are different from `not
497
+ has_selector?`. Read the section on asynchronous JavaScript for an explanation.
498
+
499
+ You can use these with RSpec's magic matchers:
500
+
501
+ ```ruby
502
+ expect(page).to have_selector('table tr')
503
+ expect(page).to have_selector(:xpath, './/table/tr')
504
+
505
+ expect(page).to have_xpath('.//table/tr')
506
+ expect(page).to have_css('table tr.foo')
507
+ expect(page).to have_content('foo')
508
+ ```
509
+
510
+ ### <a name="finding"></a>Finding
511
+
512
+ _Full reference: [Capybara::Node::Finders](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders)_
513
+
514
+ You can also find specific elements, in order to manipulate them:
515
+
516
+ ```ruby
517
+ find_field('First Name').value
518
+ find_field(id: 'my_field').value
519
+ find_link('Hello', :visible => :all).visible?
520
+ find_link(class: ['some_class', 'some_other_class'], :visible => :all).visible?
521
+
522
+ find_button('Send').click
523
+ find_button(value: '1234').click
524
+
525
+ find(:xpath, ".//table/tr").click
526
+ find("#overlay").find("h1").click
527
+ all('a').each { |a| a[:href] }
528
+ ```
529
+
530
+ If you need to find elements by additional attributes/properties you can also pass a filter block, which will be checked inside the normal waiting behavior.
531
+ If you find yourself needing to use this a lot you may be better off adding a [custom selector](http://www.rubydoc.info/github/teamcapybara/capybara/Capybara#add_selector-class_method) or [adding a filter to an existing selector](http://www.rubydoc.info/github/teamcapybara/capybara/Capybara#modify_selector-class_method).
532
+
533
+ ```ruby
534
+ find_field('First Name'){ |el| el['data-xyz'] == '123' }
535
+ find("#img_loading"){ |img| img['complete'] == true }
536
+ ```
537
+
538
+ **Note**: `find` will wait for an element to appear on the page, as explained in the
539
+ Ajax section. If the element does not appear it will raise an error.
540
+
541
+ These elements all have all the Capybara DSL methods available, so you can restrict them
542
+ to specific parts of the page:
543
+
544
+ ```ruby
545
+ find('#navigation').click_link('Home')
546
+ expect(find('#navigation')).to have_button('Sign out')
547
+ ```
548
+
549
+ ### <a name="scoping"></a>Scoping
550
+
551
+ Capybara makes it possible to restrict certain actions, such as interacting with
552
+ forms or clicking links and buttons, to within a specific area of the page. For
553
+ this purpose you can use the generic
554
+ <tt>[within](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Session#within-instance_method)</tt>
555
+ method. Optionally you can specify which kind of selector to use.
556
+
557
+ ```ruby
558
+ within("li#employee") do
559
+ fill_in 'Name', with: 'Jimmy'
560
+ end
561
+
562
+ within(:xpath, ".//li[@id='employee']") do
563
+ fill_in 'Name', with: 'Jimmy'
564
+ end
565
+ ```
566
+
567
+ There are special methods for restricting the scope to a specific fieldset,
568
+ identified by either an id or the text of the fieldset's legend tag, and to a
569
+ specific table, identified by either id or text of the table's caption tag.
570
+
571
+ ```ruby
572
+ within_fieldset('Employee') do
573
+ fill_in 'Name', with: 'Jimmy'
574
+ end
575
+
576
+ within_table('Employee') do
577
+ fill_in 'Name', with: 'Jimmy'
578
+ end
579
+ ```
580
+
581
+ ### <a name="working-with-windows"></a>Working with windows
582
+
583
+ Capybara provides some methods to ease finding and switching windows:
584
+
585
+ ```ruby
586
+ facebook_window = window_opened_by do
587
+ click_button 'Like'
588
+ end
589
+ within_window facebook_window do
590
+ find('#login_email').set('a@example.com')
591
+ find('#login_password').set('qwerty')
592
+ click_button 'Submit'
593
+ end
594
+ ```
595
+
596
+ ### <a name="scripting"></a>Scripting
597
+
598
+ In drivers which support it, you can easily execute JavaScript:
599
+
600
+ ```ruby
601
+ page.execute_script("$('body').empty()")
602
+ ```
603
+
604
+ For simple expressions, you can return the result of the script.
605
+
606
+ ```ruby
607
+ result = page.evaluate_script('4 + 4');
608
+ ```
609
+
610
+ For more complicated scripts you'll need to write them as one expression.
611
+
612
+ ```ruby
613
+ result = page.evaluate_script(<<~JS, 3, element)
614
+ (function(n, el){
615
+ var val = parseInt(el.value, 10);
616
+ return n+val;
617
+ })(arguments[0], arguments[1])
618
+ JS
619
+ ```
620
+
621
+ ### <a name="modals"></a>Modals
622
+
623
+ In drivers which support it, you can accept, dismiss and respond to alerts, confirms, and prompts.
624
+
625
+ You can accept alert messages by wrapping the code that produces an alert in a block:
626
+
627
+ ```ruby
628
+ accept_alert 'optional text or regex' do
629
+ click_link('Show Alert')
630
+ end
631
+ ```
632
+
633
+ You can accept or dismiss a confirmation by wrapping it in a block, as well:
634
+
635
+ ```ruby
636
+ accept_confirm 'optional text' do
637
+ click_link('Show Confirm')
638
+ end
639
+ ```
640
+
641
+ ```ruby
642
+ dismiss_confirm 'optional text' do
643
+ click_link('Show Confirm')
644
+ end
645
+ ```
646
+
647
+ You can accept or dismiss prompts as well, and also provide text to fill in for the response:
648
+
649
+ ```ruby
650
+ accept_prompt('optional text', with: 'Linus Torvalds') do
651
+ click_link('Show Prompt About Linux')
652
+ end
653
+ ```
654
+
655
+ ```ruby
656
+ dismiss_prompt('optional text') do
657
+ click_link('Show Prompt About Linux')
658
+ end
659
+ ```
660
+
661
+ All modal methods return the message that was presented. So, you can access the prompt message
662
+ by assigning the return to a variable:
663
+
664
+ ```ruby
665
+ message = accept_prompt(with: 'Linus Torvalds') do
666
+ click_link('Show Prompt About Linux')
667
+ end
668
+ expect(message).to eq('Who is the chief architect of Linux?')
669
+ ```
670
+
671
+ ### <a name="debugging"></a>Debugging
672
+
673
+ It can be useful to take a snapshot of the page as it currently is and take a
674
+ look at it:
675
+
676
+ ```ruby
677
+ save_and_open_page
678
+ ```
679
+
680
+ You can also retrieve the current state of the DOM as a string using
681
+ <tt>[page.html](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Session#html-instance_method)</tt>.
682
+
683
+ ```ruby
684
+ print page.html
685
+ ```
686
+
687
+ This is mostly useful for debugging. You should avoid testing against the
688
+ contents of `page.html` and use the more expressive finder methods instead.
689
+
690
+ Finally, in drivers that support it, you can save a screenshot:
691
+
692
+ ```ruby
693
+ page.save_screenshot('screenshot.png')
694
+ ```
695
+
696
+ Or have it save and automatically open:
697
+
698
+ ```ruby
699
+ save_and_open_screenshot
700
+ ```
701
+
702
+ Screenshots are saved to `Capybara.save_path`, relative to the app directory.
703
+ If you have required `capybara/rails`, `Capybara.save_path` will default to
704
+ `tmp/capybara`.
705
+
706
+ ## <a name="selectors"></a>Selectors
707
+
708
+ Helpers and matchers that accept Selectors share a common method signature that
709
+ includes:
710
+
711
+ 1. a positional Name argument
712
+ 2. a positional Locator argument
713
+ 3. keyword Filter arguments
714
+ 4. a predicate Filter block argument
715
+
716
+ These arguments are usually optional in one way or another.
717
+
718
+ ### <a name="selectors-name"></a>Name
719
+
720
+ The name argument determines the Selector to use. The argument is optional when
721
+ a helper explicitly conveys the selector name (for example, [`find_field`][]
722
+ uses `:field`, [`find_link`][] uses `:link`, etc):
723
+
724
+ ```ruby
725
+ page.html # => '<a href="/">Home</a>'
726
+
727
+ page.find(:link) == page.find_link
728
+
729
+ page.html # => '<input>'
730
+
731
+ page.find(:field) == page.find_field
732
+ ```
733
+
734
+ ### <a name="selectors-locator"></a>Locator
735
+
736
+ The locator argument usually represents information that can most meaningfully
737
+ distinguish an element that matches the selector from an element that does not:
738
+
739
+ ```ruby
740
+ page.html # => '<div id="greeting">Hello world</div>'
741
+
742
+ page.find(:css, 'div').text # => 'Hello world'
743
+ page.find(:xpath, './/div').text # => 'Hello world'
744
+ ```
745
+
746
+ General purpose finder methods like [`find`][] and [`all`][] can accept the
747
+ locator as their first positional argument when the method can infer the default
748
+ value from the [`Capybara.default_selector`][] configuration:
749
+
750
+ ```ruby
751
+ page.html # => '<div id="greeting">Hello world</div>'
752
+
753
+ Capybara.default_selector = :css
754
+
755
+ page.find('div').text # => 'Hello world'
756
+
757
+ Capybara.default_selector = :xpath
758
+
759
+ page.find('.//div').text # => 'Hello world'
760
+ ```
761
+
762
+ The locator argument's semantics are context-specific, and depend on the
763
+ selector. The types of arguments are varied. Some selectors support `String` or
764
+ `Regexp` arguments, while others like `:table_row` support `Array<String>` and
765
+ `Hash<String, String>`:
766
+
767
+ ```ruby
768
+ page.html # => '<label for="greeting">Greeting</label>
769
+ <input id="greeting" name="content">'
770
+
771
+ # find by the <input> element's [id] attribute
772
+ page.find(:id, 'greeting') == page.find_by_id('greeting') # => true
773
+
774
+ # find by the <input> element's [id] attribute
775
+ page.find(:field, 'greeting') == page.find_field('greeting') # => true
776
+
777
+ # find by the <input> element's [name] attribute
778
+ page.find(:field, 'content') == page.find_field('content') # => true
779
+
780
+ # find by the <label> element's text
781
+ page.find(:field, 'Greeting') == page.find_field('Greeting') # => true
782
+
783
+ page.html # => '<table>
784
+ <tr>
785
+ <th>A</th>
786
+ <th>B</th>
787
+ </tr>
788
+ <tr>
789
+ <td>1</td>
790
+ <td>2</td>
791
+ </tr>
792
+ </table>'
793
+
794
+ # find by <td> content
795
+ page.find(:table_row, ['1', '2']) == page.find(:css, 'tr:last-of-type') # => true
796
+
797
+ # find by <th> content paired with corresponding <td> content
798
+ page.find(:table_row, 'A' => '1') == page.find(:table_row, 'B' => '2') # => true
799
+ ```
800
+
801
+ ### <a name="selectors-filters"></a> Filters
802
+
803
+ All filters are optional. The supported set of keys is a mixture of both global
804
+ and context-specific filters.The supported types of values depend on the
805
+ context:
806
+
807
+ ```ruby
808
+ page.html # => '<a href="/">Home</a>'
809
+
810
+ # find by the [href] attribute
811
+ page.find_link(href: '/') == page.find_link(text: 'Home') # => true
812
+
813
+ page.html # => '<div id="element" data-attribute="value">Content</div>'
814
+
815
+ # find by the [id] attribute
816
+ page.find(id: 'element') == page.find(text: 'Content') # => true
817
+
818
+ # find by the [data-attribute] attribute
819
+ page.find(:element, 'data-attribute': /value/) == page.find(text: 'Content') # => true
820
+
821
+ page.html # => '<input type="checkbox">'
822
+
823
+ # find by the absence of the [checked] attribute
824
+ page.find_field(checked: false) == page.find_field(unchecked: true) # => true
825
+ ```
826
+
827
+ The predicate block is always optional. When there are results for a selector
828
+ query, the block is called with each item in the result set. When the block
829
+ evaluates to true, the item is included from the result set. Otherwise, the item
830
+ is excluded:
831
+
832
+ ```ruby
833
+ page.html # => '<input role="switch" type="checkbox" checked>'
834
+
835
+ switch = page.find_field { |input| input["role"] == "switch" }
836
+ field = page.find_field(checked: true)
837
+
838
+ switch == field # => true
839
+ ```
840
+
841
+ [`find`]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders:find
842
+ [`all`]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders:all
843
+ [`Capybara.default_selector`]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2Econfigure
844
+ [`find_by_id`]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders:find_by_id
845
+ [`find_field`]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders:find_field
846
+ [`find_link`]: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Finders:find_link
847
+
848
+ ## <a name="matching"></a>Matching
849
+
850
+ It is possible to customize how Capybara finds elements. At your disposal
851
+ are two options, `Capybara.exact` and `Capybara.match`.
852
+
853
+ ### <a name="exactness"></a>Exactness
854
+
855
+ `Capybara.exact` and the `exact` option work together with the `is` expression
856
+ inside the XPath gem. When `exact` is true, all `is` expressions match exactly,
857
+ when it is false, they allow substring matches. Many of the selectors built into
858
+ Capybara use the `is` expression. This way you can specify whether you want to
859
+ allow substring matches or not. `Capybara.exact` is false by default.
860
+
861
+ For example:
862
+
863
+ ```ruby
864
+ click_link("Password") # also matches "Password confirmation"
865
+ Capybara.exact = true
866
+ click_link("Password") # does not match "Password confirmation"
867
+ click_link("Password", exact: false) # can be overridden
868
+ ```
869
+
870
+ ### <a name="strategy"></a>Strategy
871
+
872
+ Using `Capybara.match` and the equivalent `match` option, you can control how
873
+ Capybara behaves when multiple elements all match a query. There are currently
874
+ four different strategies built into Capybara:
875
+
876
+ 1. **first:** Just picks the first element that matches.
877
+ 2. **one:** Raises an error if more than one element matches.
878
+ 3. **smart:** If `exact` is `true`, raises an error if more than one element
879
+ matches, just like `one`. If `exact` is `false`, it will first try to find
880
+ an exact match. An error is raised if more than one element is found. If no
881
+ element is found, a new search is performed which allows partial matches. If
882
+ that search returns multiple matches, an error is raised.
883
+ 4. **prefer_exact:** If multiple matches are found, some of which are exact,
884
+ and some of which are not, then the first exactly matching element is
885
+ returned.
886
+
887
+ The default for `Capybara.match` is `:smart`. To emulate the behaviour in
888
+ Capybara 2.0.x, set `Capybara.match` to `:one`. To emulate the behaviour in
889
+ Capybara 1.x, set `Capybara.match` to `:prefer_exact`.
890
+
891
+ ## <a name="transactions-and-database-setup"></a>Transactions and database setup
892
+
893
+ **Note:** Rails 5.1+ "safely" shares the database connection between the app and test threads. Therefore,
894
+ if using Rails 5.1+ you SHOULD be able to ignore this section.
895
+
896
+ Some Capybara drivers need to run against an actual HTTP server. Capybara takes
897
+ care of this and starts one for you in the same process as your test, but on
898
+ another thread. Selenium is one of those drivers, whereas RackTest is not.
899
+
900
+ If you are using a SQL database, it is common to run every test in a
901
+ transaction, which is rolled back at the end of the test, rspec-rails does this
902
+ by default out of the box for example. Since transactions are usually not
903
+ shared across threads, this will cause data you have put into the database in
904
+ your test code to be invisible to Capybara.
905
+
906
+ Cucumber handles this by using truncation instead of transactions, i.e. they
907
+ empty out the entire database after each test. You can get the same behaviour
908
+ by using a gem such as [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner).
909
+
910
+ ## <a name="asynchronous-javascript-ajax-and-friends"></a>Asynchronous JavaScript (Ajax and friends)
911
+
912
+ When working with asynchronous JavaScript, you might come across situations
913
+ where you are attempting to interact with an element which is not yet present
914
+ on the page. Capybara automatically deals with this by waiting for elements
915
+ to appear on the page.
916
+
917
+ When issuing instructions to the DSL such as:
918
+
919
+ ```ruby
920
+ click_link('foo')
921
+ click_link('bar')
922
+ expect(page).to have_content('baz')
923
+ ```
924
+
925
+ If clicking on the *foo* link triggers an asynchronous process, such as
926
+ an Ajax request, which, when complete will add the *bar* link to the page,
927
+ clicking on the *bar* link would be expected to fail, since that link doesn't
928
+ exist yet. However, Capybara is smart enough to retry finding the link for a
929
+ brief period of time before giving up and throwing an error. The same is true of
930
+ the next line, which looks for the content *baz* on the page; it will retry
931
+ looking for that content for a brief time. You can adjust how long this period
932
+ is (the default is 2 seconds):
933
+
934
+ ```ruby
935
+ Capybara.default_max_wait_time = 5
936
+ ```
937
+
938
+ Be aware that because of this behaviour, the following two statements are **not**
939
+ equivalent, and you should **always** use the latter!
940
+
941
+ ```ruby
942
+ # Given use of a driver where the page is loaded when visit returns
943
+ # and that Capybara.predicates_wait is `true`
944
+ # consider a page where the `a` tag is removed through AJAX after 1s
945
+ visit(some_path)
946
+ !page.has_xpath?('a') # is false
947
+ page.has_no_xpath?('a') # is true
948
+ ```
949
+
950
+ First expression:
951
+ - `has_xpath?('a')` is called right after `visit` returns. It is `true` because the link has not yet been removed
952
+ - Capybara does not wait upon successful predicates/assertions, therefore **has_xpath? returns `true` immediately**
953
+ - The expression returns `false` (because it is negated with the leading `!`)
954
+
955
+ Second expression:
956
+ - `has_no_xpath?('a')` is called right after `visit` returns. It is `false` because the link has not yet been removed.
957
+ - Capybara waits upon failed predicates/assertions, therefore **has_no_xpath? does not return `false` immediately**
958
+ - Capybara will periodically re-check the predicate/assertion up to the `default_max_wait_time` defined
959
+ - after 1s, the predicate becomes `true` (because the link has been removed)
960
+ - The expression returns `true`
961
+
962
+ Capybara's RSpec matchers, however, are smart enough to handle either form.
963
+ The two following statements are functionally equivalent:
964
+
965
+ ```ruby
966
+ expect(page).not_to have_xpath('a')
967
+ expect(page).to have_no_xpath('a')
968
+ ```
969
+
970
+ Capybara's waiting behaviour is quite advanced, and can deal with situations
971
+ such as the following line of code:
972
+
973
+ ```ruby
974
+ expect(find('#sidebar').find('h1')).to have_content('Something')
975
+ ```
976
+
977
+ Even if JavaScript causes `#sidebar` to disappear off the page, Capybara
978
+ will automatically reload it and any elements it contains. So if an AJAX
979
+ request causes the contents of `#sidebar` to change, which would update
980
+ the text of the `h1` to "Something", and this happened, this test would
981
+ pass. If you do not want this behaviour, you can set
982
+ `Capybara.automatic_reload` to `false`.
983
+
984
+ ## <a name="using-the-dsl-elsewhere"></a>Using the DSL elsewhere
985
+
986
+ You can mix the DSL into any context by including <tt>Capybara::DSL</tt>:
987
+
988
+
989
+ ```ruby
990
+ require 'capybara/dsl'
991
+
992
+ Capybara.default_driver = :webkit
993
+
994
+ module MyModule
995
+ include Capybara::DSL
996
+
997
+ def login!
998
+ within(:xpath, ".//form[@id='session']") do
999
+ fill_in 'Email', with: 'user@example.com'
1000
+ fill_in 'Password', with: 'password'
1001
+ end
1002
+ click_button 'Sign in'
1003
+ end
1004
+ end
1005
+ ```
1006
+
1007
+ This enables its use in unsupported testing frameworks, and for general-purpose scripting.
1008
+
1009
+ ## <a name="calling-remote-servers"></a>Calling remote servers
1010
+
1011
+ Normally Capybara expects to be testing an in-process Rack application, but you
1012
+ can also use it to talk to a web server running anywhere on the internet, by
1013
+ setting app_host:
1014
+
1015
+ ```ruby
1016
+ Capybara.current_driver = :selenium
1017
+ Capybara.app_host = 'http://www.google.com'
1018
+ ...
1019
+ visit('/')
1020
+ ```
1021
+
1022
+ **Note**: the default driver (`:rack_test`) does not support running
1023
+ against a remote server. With drivers that support it, you can also visit any
1024
+ URL directly:
1025
+
1026
+ ```ruby
1027
+ visit('http://www.google.com')
1028
+ ```
1029
+
1030
+ By default Capybara will try to boot a rack application automatically. You
1031
+ might want to switch off Capybara's rack server if you are running against a
1032
+ remote application:
1033
+
1034
+ ```ruby
1035
+ Capybara.run_server = false
1036
+ ```
1037
+
1038
+ ## <a name="using-sessions"></a>Using sessions
1039
+
1040
+ Capybara manages named sessions (:default if not specified) allowing multiple sessions using the same driver and test app instance to be interacted with.
1041
+ A new session will be created using the current driver if a session with the given name using the current driver and test app instance is not found.
1042
+
1043
+ ### Named sessions
1044
+ To perform operations in a different session and then revert to the previous session
1045
+
1046
+ ```ruby
1047
+ Capybara.using_session("Bob's session") do
1048
+ #do something in Bob's browser session
1049
+ end
1050
+ #reverts to previous session
1051
+ ```
1052
+
1053
+ To permanently switch the current session to a different session
1054
+
1055
+ ```ruby
1056
+ Capybara.session_name = "some other session"
1057
+ ```
1058
+
1059
+ ### <a name="using-sessions-manually"></a>Using sessions manually
1060
+
1061
+ For ultimate control, you can instantiate and use a
1062
+ [Session](http://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Session)
1063
+ manually.
1064
+
1065
+ ```ruby
1066
+ require 'capybara'
1067
+
1068
+ session = Capybara::Session.new(:webkit, my_rack_app)
1069
+ session.within("form#session") do
1070
+ session.fill_in 'Email', with: 'user@example.com'
1071
+ session.fill_in 'Password', with: 'password'
1072
+ end
1073
+ session.click_button 'Sign in'
1074
+ ```
1075
+
1076
+ ## <a name="xpath-css-and-selectors"></a>XPath, CSS and selectors
1077
+
1078
+ Capybara does not try to guess what kind of selector you are going to give it,
1079
+ and will always use CSS by default. If you want to use XPath, you'll need to
1080
+ do:
1081
+
1082
+ ```ruby
1083
+ within(:xpath, './/ul/li') { ... }
1084
+ find(:xpath, './/ul/li').text
1085
+ find(:xpath, './/li[contains(.//a[@href = "#"]/text(), "foo")]').value
1086
+ ```
1087
+
1088
+ Alternatively you can set the default selector to XPath:
1089
+
1090
+ ```ruby
1091
+ Capybara.default_selector = :xpath
1092
+ find('.//ul/li').text
1093
+ ```
1094
+
1095
+ Capybara provides a number of other built-in selector types. The full list, along
1096
+ with applicable filters, can be seen at [built-in selectors](https://www.rubydoc.info/github/teamcapybara/capybara/Capybara/Selector)
1097
+
1098
+ Capybara also allows you to add custom selectors, which can be very useful if you
1099
+ find yourself using the same kinds of selectors very often. The examples below are very
1100
+ simple, and there are many available features not demonstrated. For more in-depth examples
1101
+ please see Capybaras built-in selector definitions.
1102
+
1103
+ ```ruby
1104
+ Capybara.add_selector(:my_attribute) do
1105
+ xpath { |id| XPath.descendant[XPath.attr(:my_attribute) == id.to_s] }
1106
+ end
1107
+
1108
+ Capybara.add_selector(:row) do
1109
+ xpath { |num| ".//tbody/tr[#{num}]" }
1110
+ end
1111
+
1112
+ Capybara.add_selector(:flash_type) do
1113
+ css { |type| "#flash.#{type}" }
1114
+ end
1115
+ ```
1116
+
1117
+ The block given to xpath must always return an XPath expression as a String, or
1118
+ an XPath expression generated through the XPath gem. You can now use these
1119
+ selectors like this:
1120
+
1121
+ ```ruby
1122
+ find(:my_attribute, 'post_123') # find element with matching attribute
1123
+ find(:row, 3) # find 3rd row in table body
1124
+ find(:flash_type, :notice) # find element with id of 'flash' and class of 'notice'
1125
+ ```
1126
+
1127
+ ## <a name="beware-the-xpath--trap"></a>Beware the XPath // trap
1128
+
1129
+ In XPath the expression // means something very specific, and it might not be what
1130
+ you think. Contrary to common belief, // means "anywhere in the document" not "anywhere
1131
+ in the current context". As an example:
1132
+
1133
+ ```ruby
1134
+ page.find(:xpath, '//body').all(:xpath, '//script')
1135
+ ```
1136
+
1137
+ You might expect this to find all script tags in the body, but actually, it finds all
1138
+ script tags in the entire document, not only those in the body! What you're looking
1139
+ for is the .// expression which means "any descendant of the current node":
1140
+
1141
+ ```ruby
1142
+ page.find(:xpath, '//body').all(:xpath, './/script')
1143
+ ```
1144
+ The same thing goes for within:
1145
+
1146
+ ```ruby
1147
+ within(:xpath, '//body') do
1148
+ page.find(:xpath, './/script')
1149
+ within(:xpath, './/table/tbody') do
1150
+ ...
1151
+ end
1152
+ end
1153
+ ```
1154
+
1155
+ ## <a name="configuring-and-adding-drivers"></a>Configuring and adding drivers
1156
+
1157
+ Capybara makes it convenient to switch between different drivers. It also exposes
1158
+ an API to tweak those drivers with whatever settings you want, or to add your own
1159
+ drivers. This is how to override the selenium driver configuration to use chrome:
1160
+
1161
+ ```ruby
1162
+ Capybara.register_driver :selenium do |app|
1163
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
1164
+ end
1165
+ ```
1166
+
1167
+ However, it's also possible to give this configuration a different name.
1168
+
1169
+ ```ruby
1170
+ # Note: Capybara registers this by default
1171
+ Capybara.register_driver :selenium_chrome do |app|
1172
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
1173
+ end
1174
+ ```
1175
+
1176
+ Then tests can switch between using different browsers effortlessly:
1177
+ ```ruby
1178
+ Capybara.current_driver = :selenium_chrome
1179
+ ```
1180
+
1181
+ Whatever is returned from the block should conform to the API described by
1182
+ Capybara::Driver::Base, it does not however have to inherit from this class.
1183
+ Gems can use this API to add their own drivers to Capybara.
1184
+
1185
+ The [Selenium wiki](https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings) has
1186
+ additional info about how the underlying driver can be configured.
1187
+
1188
+ ## <a name="gotchas"></a>Gotchas:
1189
+
1190
+ * Access to session and request is not possible from the test, Access to
1191
+ response is limited. Some drivers allow access to response headers and HTTP
1192
+ status code, but this kind of functionality is not provided by some drivers,
1193
+ such as Selenium.
1194
+
1195
+ * Access to Rails specific stuff (such as `controller`) is unavailable,
1196
+ since we're not using Rails' integration testing.
1197
+
1198
+ * Freezing time: It's common practice to mock out the Time so that features
1199
+ that depend on the current Date work as expected. This can be problematic on
1200
+ ruby/platform combinations that don't support access to a monotonic process clock,
1201
+ since Capybara's Ajax timing uses the system time, resulting in Capybara
1202
+ never timing out and just hanging when a failure occurs. It's still possible to
1203
+ use gems which allow you to travel in time, rather than freeze time.
1204
+ One such gem is [Timecop](https://github.com/travisjeffery/timecop).
1205
+
1206
+ * When using Rack::Test, beware if attempting to visit absolute URLs. For
1207
+ example, a session might not be shared between visits to `posts_path`
1208
+ and `posts_url`. If testing an absolute URL in an Action Mailer email,
1209
+ set `default_url_options` to match the Rails default of
1210
+ `www.example.com`.
1211
+
1212
+ * Server errors will only be raised in the session that initiates the server thread. If you
1213
+ are testing for specific server errors and using multiple sessions make sure to test for the
1214
+ errors using the initial session (usually :default)
1215
+
1216
+ * If WebMock is enabled, you may encounter a "Too many open files"
1217
+ error. A simple `page.find` call may cause thousands of HTTP requests
1218
+ until the timeout occurs. By default, WebMock will cause each of these
1219
+ requests to spawn a new connection. To work around this problem, you
1220
+ may need to [enable WebMock's `net_http_connect_on_start: true`
1221
+ parameter](https://github.com/bblimke/webmock/blob/master/README.md#connecting-on-nethttpstart).
1222
+
1223
+ ## <a name="threadsafe"></a>"Threadsafe" mode
1224
+
1225
+ In normal mode most of Capybara's configuration options are global settings which can cause issues
1226
+ if using multiple sessions and wanting to change a setting for only one of the sessions. To provide
1227
+ support for this type of usage Capybara now provides a "threadsafe" mode which can be enabled by setting
1228
+
1229
+ ```ruby
1230
+ Capybara.threadsafe = true
1231
+ ```
1232
+
1233
+ This setting can only be changed before any sessions have been created. In "threadsafe" mode the following
1234
+ behaviors of Capybara change
1235
+
1236
+ * Most options can now be set on a session. These can either be set at session creation time or after, and
1237
+ default to the global options at the time of session creation. Options which are NOT session specific are
1238
+ `app`, `reuse_server`, `default_driver`, `javascript_driver`, and (obviously) `threadsafe`. Any drivers and servers
1239
+ registered through `register_driver` and `register_server` are also global.
1240
+
1241
+ ```ruby
1242
+ my_session = Capybara::Session.new(:driver, some_app) do |config|
1243
+ config.automatic_label_click = true # only set for my_session
1244
+ end
1245
+ my_session.config.default_max_wait_time = 10 # only set for my_session
1246
+ Capybara.default_max_wait_time = 2 # will not change the default_max_wait in my_session
1247
+ ```
1248
+
1249
+ * `current_driver` and `session_name` are thread specific. This means that `using_session` and
1250
+ `using_driver` also only affect the current thread.
1251
+
1252
+ ## <a name="development"></a>Development
1253
+
1254
+ To set up a development environment, simply do:
1255
+
1256
+ ```bash
1257
+ bundle install
1258
+ bundle exec rake # run the test suite with Firefox - requires `geckodriver` to be installed
1259
+ bundle exec rake spec_chrome # run the test suite with Chrome - require `chromedriver` to be installed
1260
+ ```
1261
+
1262
+ See
1263
+ [CONTRIBUTING.md](https://github.com/teamcapybara/capybara/blob/master/CONTRIBUTING.md)
1264
+ for how to send issues and pull requests.