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,951 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'capybara/session/matchers'
4
+ require 'addressable/uri'
5
+
6
+ module Capybara
7
+ ##
8
+ #
9
+ # The {Session} class represents a single user's interaction with the system. The {Session} can use
10
+ # any of the underlying drivers. A session can be initialized manually like this:
11
+ #
12
+ # session = Capybara::Session.new(:culerity, MyRackApp)
13
+ #
14
+ # The application given as the second argument is optional. When running Capybara against an external
15
+ # page, you might want to leave it out:
16
+ #
17
+ # session = Capybara::Session.new(:culerity)
18
+ # session.visit('http://www.google.com')
19
+ #
20
+ # When {Capybara.configure threadsafe} is `true` the sessions options will be initially set to the
21
+ # current values of the global options and a configuration block can be passed to the session initializer.
22
+ # For available options see {Capybara::SessionConfig::OPTIONS}:
23
+ #
24
+ # session = Capybara::Session.new(:driver, MyRackApp) do |config|
25
+ # config.app_host = "http://my_host.dev"
26
+ # end
27
+ #
28
+ # The {Session} provides a number of methods for controlling the navigation of the page, such as {#visit},
29
+ # {#current_path}, and so on. It also delegates a number of methods to a {Capybara::Document}, representing
30
+ # the current HTML document. This allows interaction:
31
+ #
32
+ # session.fill_in('q', with: 'Capybara')
33
+ # session.click_button('Search')
34
+ # expect(session).to have_content('Capybara')
35
+ #
36
+ # When using `capybara/dsl`, the {Session} is initialized automatically for you.
37
+ #
38
+ class Session
39
+ include Capybara::SessionMatchers
40
+
41
+ NODE_METHODS = %i[
42
+ all first attach_file text check choose scroll_to scroll_by
43
+ click double_click right_click
44
+ click_link_or_button click_button click_link
45
+ fill_in find find_all find_button find_by_id find_field find_link
46
+ has_content? has_text? has_css? has_no_content? has_no_text?
47
+ has_no_css? has_no_xpath? has_xpath? select uncheck
48
+ has_element? has_no_element?
49
+ has_link? has_no_link? has_button? has_no_button? has_field?
50
+ has_no_field? has_checked_field? has_unchecked_field?
51
+ has_no_table? has_table? unselect has_select? has_no_select?
52
+ has_selector? has_no_selector? click_on has_no_checked_field?
53
+ has_no_unchecked_field? query assert_selector assert_no_selector
54
+ assert_all_of_selectors assert_none_of_selectors assert_any_of_selectors
55
+ refute_selector assert_text assert_no_text
56
+ ].freeze
57
+ # @api private
58
+ DOCUMENT_METHODS = %i[
59
+ title assert_title assert_no_title has_title? has_no_title?
60
+ ].freeze
61
+ SESSION_METHODS = %i[
62
+ body html source current_url current_host current_path
63
+ execute_script evaluate_script evaluate_async_script visit refresh go_back go_forward send_keys
64
+ within within_element within_fieldset within_table within_frame switch_to_frame
65
+ current_window windows open_new_window switch_to_window within_window window_opened_by
66
+ save_page save_and_open_page save_screenshot
67
+ save_and_open_screenshot reset_session! response_headers
68
+ status_code current_scope
69
+ assert_current_path assert_no_current_path has_current_path? has_no_current_path?
70
+ ].freeze + DOCUMENT_METHODS
71
+ MODAL_METHODS = %i[
72
+ accept_alert accept_confirm dismiss_confirm accept_prompt dismiss_prompt
73
+ ].freeze
74
+ DSL_METHODS = NODE_METHODS + SESSION_METHODS + MODAL_METHODS
75
+
76
+ attr_reader :mode, :app, :server
77
+ attr_accessor :synchronized
78
+
79
+ def initialize(mode, app = nil)
80
+ if app && !app.respond_to?(:call)
81
+ raise TypeError, 'The second parameter to Session::new should be a rack app if passed.'
82
+ end
83
+
84
+ @@instance_created = true # rubocop:disable Style/ClassVars
85
+ @mode = mode
86
+ @app = app
87
+ if block_given?
88
+ raise 'A configuration block is only accepted when Capybara.threadsafe == true' unless Capybara.threadsafe
89
+
90
+ yield config
91
+ end
92
+ @server = if config.run_server && @app && driver.needs_server?
93
+ server_options = { port: config.server_port, host: config.server_host, reportable_errors: config.server_errors }
94
+ server_options[:extra_middleware] = [Capybara::Server::AnimationDisabler] if config.disable_animation
95
+ Capybara::Server.new(@app, **server_options).boot
96
+ end
97
+ @touched = false
98
+ end
99
+
100
+ def driver
101
+ @driver ||= begin
102
+ unless Capybara.drivers[mode]
103
+ other_drivers = Capybara.drivers.names.map(&:inspect)
104
+ raise Capybara::DriverNotFoundError, "no driver called #{mode.inspect} was found, available drivers: #{other_drivers.join(', ')}"
105
+ end
106
+ driver = Capybara.drivers[mode].call(app)
107
+ driver.session = self if driver.respond_to?(:session=)
108
+ driver
109
+ end
110
+ end
111
+
112
+ ##
113
+ #
114
+ # Reset the session (i.e. remove cookies and navigate to blank page).
115
+ #
116
+ # This method does not:
117
+ #
118
+ # * accept modal dialogs if they are present (Selenium driver now does, others may not)
119
+ # * clear browser cache/HTML 5 local storage/IndexedDB/Web SQL database/etc.
120
+ # * modify state of the driver/underlying browser in any other way
121
+ #
122
+ # as doing so will result in performance downsides and it's not needed to do everything from the list above for most apps.
123
+ #
124
+ # If you want to do anything from the list above on a general basis you can:
125
+ #
126
+ # * write RSpec/Cucumber/etc. after hook
127
+ # * monkeypatch this method
128
+ # * use Ruby's `prepend` method
129
+ #
130
+ def reset!
131
+ if @touched
132
+ driver.reset!
133
+ @touched = false
134
+ switch_to_frame(:top) rescue nil # rubocop:disable Style/RescueModifier
135
+ @scopes = [nil]
136
+ end
137
+ @server&.wait_for_pending_requests
138
+ raise_server_error!
139
+ end
140
+ alias_method :cleanup!, :reset!
141
+ alias_method :reset_session!, :reset!
142
+
143
+ ##
144
+ #
145
+ # Disconnect from the current driver. A new driver will be instantiated on the next interaction.
146
+ #
147
+ def quit
148
+ @driver.quit if @driver.respond_to? :quit
149
+ @document = @driver = nil
150
+ @touched = false
151
+ @server&.reset_error!
152
+ end
153
+
154
+ ##
155
+ #
156
+ # Raise errors encountered in the server.
157
+ #
158
+ def raise_server_error!
159
+ return unless @server&.error
160
+
161
+ # Force an explanation for the error being raised as the exception cause
162
+ begin
163
+ if config.raise_server_errors
164
+ raise CapybaraError, 'Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true'
165
+ end
166
+ rescue CapybaraError => capy_error # rubocop:disable Naming/RescuedExceptionsVariableName
167
+ raise @server.error, cause: capy_error
168
+ ensure
169
+ @server.reset_error!
170
+ end
171
+ end
172
+
173
+ ##
174
+ #
175
+ # Returns a hash of response headers. Not supported by all drivers (e.g. Selenium).
176
+ #
177
+ # @return [Hash<String, String>] A hash of response headers.
178
+ #
179
+ def response_headers
180
+ driver.response_headers
181
+ end
182
+
183
+ ##
184
+ #
185
+ # Returns the current HTTP status code as an integer. Not supported by all drivers (e.g. Selenium).
186
+ #
187
+ # @return [Integer] Current HTTP status code
188
+ #
189
+ def status_code
190
+ driver.status_code
191
+ end
192
+
193
+ ##
194
+ #
195
+ # @return [String] A snapshot of the DOM of the current document, as it looks right now (potentially modified by JavaScript).
196
+ #
197
+ def html
198
+ driver.html || ''
199
+ end
200
+ alias_method :body, :html
201
+ alias_method :source, :html
202
+
203
+ ##
204
+ #
205
+ # @return [String] Path of the current page, without any domain information
206
+ #
207
+ def current_path
208
+ # Addressable parsing is more lenient than URI
209
+ uri = ::Addressable::URI.parse(current_url)
210
+
211
+ # Addressable doesn't support opaque URIs - we want nil here
212
+ return nil if uri&.scheme == 'about'
213
+
214
+ path = uri&.path
215
+ path unless path&.empty?
216
+ end
217
+
218
+ ##
219
+ #
220
+ # @return [String] Host of the current page
221
+ #
222
+ def current_host
223
+ uri = URI.parse(current_url)
224
+ "#{uri.scheme}://#{uri.host}" if uri.host
225
+ end
226
+
227
+ ##
228
+ #
229
+ # @return [String] Fully qualified URL of the current page
230
+ #
231
+ def current_url
232
+ driver.current_url
233
+ end
234
+
235
+ ##
236
+ #
237
+ # Navigate to the given URL. The URL can either be a relative URL or an absolute URL
238
+ # The behaviour of either depends on the driver.
239
+ #
240
+ # session.visit('/foo')
241
+ # session.visit('http://google.com')
242
+ #
243
+ # For drivers which can run against an external application, such as the selenium driver
244
+ # giving an absolute URL will navigate to that page. This allows testing applications
245
+ # running on remote servers. For these drivers, setting {Capybara.configure app_host} will make the
246
+ # remote server the default. For example:
247
+ #
248
+ # Capybara.app_host = 'http://google.com'
249
+ # session.visit('/') # visits the google homepage
250
+ #
251
+ # If {Capybara.configure always_include_port} is set to `true` and this session is running against
252
+ # a rack application, then the port that the rack application is running on will automatically
253
+ # be inserted into the URL. Supposing the app is running on port `4567`, doing something like:
254
+ #
255
+ # visit("http://google.com/test")
256
+ #
257
+ # Will actually navigate to `http://google.com:4567/test`.
258
+ #
259
+ # @param [#to_s] visit_uri The URL to navigate to. The parameter will be cast to a String.
260
+ #
261
+ def visit(visit_uri)
262
+ raise_server_error!
263
+ @touched = true
264
+
265
+ visit_uri = ::Addressable::URI.parse(visit_uri.to_s)
266
+ base_uri = ::Addressable::URI.parse(config.app_host || server_url)
267
+
268
+ if base_uri && [nil, 'http', 'https'].include?(visit_uri.scheme)
269
+ if visit_uri.relative?
270
+ visit_uri_parts = visit_uri.to_hash.compact
271
+
272
+ # Useful to people deploying to a subdirectory
273
+ # and/or single page apps where only the url fragment changes
274
+ visit_uri_parts[:path] = base_uri.path + visit_uri.path
275
+
276
+ visit_uri = base_uri.merge(visit_uri_parts)
277
+ end
278
+ adjust_server_port(visit_uri)
279
+ end
280
+
281
+ driver.visit(visit_uri.to_s)
282
+ end
283
+
284
+ ##
285
+ #
286
+ # Refresh the page.
287
+ #
288
+ def refresh
289
+ raise_server_error!
290
+ driver.refresh
291
+ end
292
+
293
+ ##
294
+ #
295
+ # Move back a single entry in the browser's history.
296
+ #
297
+ def go_back
298
+ driver.go_back
299
+ end
300
+
301
+ ##
302
+ #
303
+ # Move forward a single entry in the browser's history.
304
+ #
305
+ def go_forward
306
+ driver.go_forward
307
+ end
308
+
309
+ ##
310
+ # @!method send_keys
311
+ # @see Capybara::Node::Element#send_keys
312
+ #
313
+ def send_keys(...)
314
+ driver.send_keys(...)
315
+ end
316
+
317
+ ##
318
+ #
319
+ # Returns the element with focus.
320
+ #
321
+ # Not supported by Rack Test
322
+ #
323
+ def active_element
324
+ Capybara::Queries::ActiveElementQuery.new.resolve_for(self)[0].tap(&:allow_reload!)
325
+ end
326
+
327
+ ##
328
+ #
329
+ # Executes the given block within the context of a node. {#within} takes the
330
+ # same options as {Capybara::Node::Finders#find #find}, as well as a block. For the duration of the
331
+ # block, any command to Capybara will be handled as though it were scoped
332
+ # to the given element.
333
+ #
334
+ # within(:xpath, './/div[@id="delivery-address"]') do
335
+ # fill_in('Street', with: '12 Main Street')
336
+ # end
337
+ #
338
+ # Just as with `#find`, if multiple elements match the selector given to
339
+ # {#within}, an error will be raised, and just as with `#find`, this
340
+ # behaviour can be controlled through the `:match` and `:exact` options.
341
+ #
342
+ # It is possible to omit the first parameter, in that case, the selector is
343
+ # assumed to be of the type set in {Capybara.configure default_selector}.
344
+ #
345
+ # within('div#delivery-address') do
346
+ # fill_in('Street', with: '12 Main Street')
347
+ # end
348
+ #
349
+ # Note that a lot of uses of {#within} can be replaced more succinctly with
350
+ # chaining:
351
+ #
352
+ # find('div#delivery-address').fill_in('Street', with: '12 Main Street')
353
+ #
354
+ # @overload within(*find_args)
355
+ # @param (see Capybara::Node::Finders#all)
356
+ #
357
+ # @overload within(a_node)
358
+ # @param [Capybara::Node::Base] a_node The node in whose scope the block should be evaluated
359
+ #
360
+ # @raise [Capybara::ElementNotFound] If the scope can't be found before time expires
361
+ #
362
+ def within(*args, **kw_args)
363
+ new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args, **kw_args)
364
+ begin
365
+ scopes.push(new_scope)
366
+ yield new_scope if block_given?
367
+ ensure
368
+ scopes.pop
369
+ end
370
+ end
371
+ alias_method :within_element, :within
372
+
373
+ ##
374
+ #
375
+ # Execute the given block within the a specific fieldset given the id or legend of that fieldset.
376
+ #
377
+ # @param [String] locator Id or legend of the fieldset
378
+ #
379
+ def within_fieldset(locator, &block)
380
+ within(:fieldset, locator, &block)
381
+ end
382
+
383
+ ##
384
+ #
385
+ # Execute the given block within the a specific table given the id or caption of that table.
386
+ #
387
+ # @param [String] locator Id or caption of the table
388
+ #
389
+ def within_table(locator, &block)
390
+ within(:table, locator, &block)
391
+ end
392
+
393
+ ##
394
+ #
395
+ # Switch to the given frame.
396
+ #
397
+ # If you use this method you are responsible for making sure you switch back to the parent frame when done in the frame changed to.
398
+ # {#within_frame} is preferred over this method and should be used when possible.
399
+ # May not be supported by all drivers.
400
+ #
401
+ # @overload switch_to_frame(element)
402
+ # @param [Capybara::Node::Element] element iframe/frame element to switch to
403
+ # @overload switch_to_frame(location)
404
+ # @param [Symbol] location relative location of the frame to switch to
405
+ # * :parent - the parent frame
406
+ # * :top - the top level document
407
+ #
408
+ def switch_to_frame(frame)
409
+ case frame
410
+ when Capybara::Node::Element
411
+ driver.switch_to_frame(frame)
412
+ scopes.push(:frame)
413
+ when :parent
414
+ if scopes.last != :frame
415
+ raise Capybara::ScopeError, "`switch_to_frame(:parent)` cannot be called from inside a descendant frame's " \
416
+ '`within` block.'
417
+ end
418
+ scopes.pop
419
+ driver.switch_to_frame(:parent)
420
+ when :top
421
+ idx = scopes.index(:frame)
422
+ top_level_scopes = [:frame, nil]
423
+ if idx
424
+ if scopes.slice(idx..).any? { |scope| !top_level_scopes.include?(scope) }
425
+ raise Capybara::ScopeError, "`switch_to_frame(:top)` cannot be called from inside a descendant frame's " \
426
+ '`within` block.'
427
+ end
428
+ scopes.slice!(idx..)
429
+ driver.switch_to_frame(:top)
430
+ end
431
+ else
432
+ raise ArgumentError, 'You must provide a frame element, :parent, or :top when calling switch_to_frame'
433
+ end
434
+ end
435
+
436
+ ##
437
+ #
438
+ # Execute the given block within the given iframe using given frame, frame name/id or index.
439
+ # May not be supported by all drivers.
440
+ #
441
+ # @overload within_frame(element)
442
+ # @param [Capybara::Node::Element] frame element
443
+ # @overload within_frame([kind = :frame], locator, **options)
444
+ # @param [Symbol] kind Optional selector type (:frame, :css, :xpath, etc.) - Defaults to :frame
445
+ # @param [String] locator The locator for the given selector kind. For :frame this is the name/id of a frame/iframe element
446
+ # @overload within_frame(index)
447
+ # @param [Integer] index index of a frame (0 based)
448
+ def within_frame(*args, **kw_args)
449
+ switch_to_frame(_find_frame(*args, **kw_args))
450
+ begin
451
+ yield if block_given?
452
+ ensure
453
+ switch_to_frame(:parent)
454
+ end
455
+ end
456
+
457
+ ##
458
+ # @return [Capybara::Window] current window
459
+ #
460
+ def current_window
461
+ Window.new(self, driver.current_window_handle)
462
+ end
463
+
464
+ ##
465
+ # Get all opened windows.
466
+ # The order of windows in returned array is not defined.
467
+ # The driver may sort windows by their creation time but it's not required.
468
+ #
469
+ # @return [Array<Capybara::Window>] an array of all windows
470
+ #
471
+ def windows
472
+ driver.window_handles.map do |handle|
473
+ Window.new(self, handle)
474
+ end
475
+ end
476
+
477
+ ##
478
+ # Open a new window.
479
+ # The current window doesn't change as the result of this call.
480
+ # It should be switched to explicitly.
481
+ #
482
+ # @return [Capybara::Window] window that has been opened
483
+ #
484
+ def open_new_window(kind = :tab)
485
+ window_opened_by do
486
+ if driver.method(:open_new_window).arity.zero?
487
+ driver.open_new_window
488
+ else
489
+ driver.open_new_window(kind)
490
+ end
491
+ end
492
+ end
493
+
494
+ ##
495
+ # Switch to the given window.
496
+ #
497
+ # @overload switch_to_window(&block)
498
+ # Switches to the first window for which given block returns a value other than false or nil.
499
+ # If window that matches block can't be found, the window will be switched back and {Capybara::WindowError} will be raised.
500
+ # @example
501
+ # window = switch_to_window { title == 'Page title' }
502
+ # @raise [Capybara::WindowError] if no window matches given block
503
+ # @overload switch_to_window(window)
504
+ # @param window [Capybara::Window] window that should be switched to
505
+ # @raise [Capybara::Driver::Base#no_such_window_error] if nonexistent (e.g. closed) window was passed
506
+ #
507
+ # @return [Capybara::Window] window that has been switched to
508
+ # @raise [Capybara::ScopeError] if this method is invoked inside {#within} or
509
+ # {#within_frame} methods
510
+ # @raise [ArgumentError] if both or neither arguments were provided
511
+ #
512
+ def switch_to_window(window = nil, **options, &window_locator)
513
+ raise ArgumentError, '`switch_to_window` can take either a block or a window, not both' if window && window_locator
514
+ raise ArgumentError, '`switch_to_window`: either window or block should be provided' if !window && !window_locator
515
+
516
+ unless scopes.last.nil?
517
+ raise Capybara::ScopeError, '`switch_to_window` is not supposed to be invoked from ' \
518
+ '`within` or `within_frame` blocks.'
519
+ end
520
+
521
+ _switch_to_window(window, **options, &window_locator)
522
+ end
523
+
524
+ ##
525
+ # This method does the following:
526
+ #
527
+ # 1. Switches to the given window (it can be located by window instance/lambda/string).
528
+ # 2. Executes the given block (within window located at previous step).
529
+ # 3. Switches back (this step will be invoked even if an exception occurs at the second step).
530
+ #
531
+ # @overload within_window(window) { do_something }
532
+ # @param window [Capybara::Window] instance of {Capybara::Window} class
533
+ # that will be switched to
534
+ # @raise [driver#no_such_window_error] if nonexistent (e.g. closed) window was passed
535
+ # @overload within_window(proc_or_lambda) { do_something }
536
+ # @param lambda [Proc] First window for which lambda
537
+ # returns a value other than false or nil will be switched to.
538
+ # @example
539
+ # within_window(->{ page.title == 'Page title' }) { click_button 'Submit' }
540
+ # @raise [Capybara::WindowError] if no window matching lambda was found
541
+ #
542
+ # @raise [Capybara::ScopeError] if this method is invoked inside {#within_frame} method
543
+ # @return value returned by the block
544
+ #
545
+ def within_window(window_or_proc)
546
+ original = current_window
547
+ scopes << nil
548
+ begin
549
+ case window_or_proc
550
+ when Capybara::Window
551
+ _switch_to_window(window_or_proc) unless original == window_or_proc
552
+ when Proc
553
+ _switch_to_window { window_or_proc.call }
554
+ else
555
+ raise ArgumentError, '`#within_window` requires a `Capybara::Window` instance or a lambda'
556
+ end
557
+
558
+ begin
559
+ yield if block_given?
560
+ ensure
561
+ _switch_to_window(original) unless original == window_or_proc
562
+ end
563
+ ensure
564
+ scopes.pop
565
+ end
566
+ end
567
+
568
+ ##
569
+ # Get the window that has been opened by the passed block.
570
+ # It will wait for it to be opened (in the same way as other Capybara methods wait).
571
+ # It's better to use this method than `windows.last`
572
+ # {https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html#h_note_10 as order of windows isn't defined in some drivers}.
573
+ #
574
+ # @overload window_opened_by(**options, &block)
575
+ # @param options [Hash]
576
+ # @option options [Numeric] :wait maximum wait time. Defaults to {Capybara.configure default_max_wait_time}
577
+ # @return [Capybara::Window] the window that has been opened within a block
578
+ # @raise [Capybara::WindowError] if block passed to window hasn't opened window
579
+ # or opened more than one window
580
+ #
581
+ def window_opened_by(**options)
582
+ old_handles = driver.window_handles
583
+ yield
584
+
585
+ synchronize_windows(options) do
586
+ opened_handles = (driver.window_handles - old_handles)
587
+ if opened_handles.size != 1
588
+ raise Capybara::WindowError, 'block passed to #window_opened_by ' \
589
+ "opened #{opened_handles.size} windows instead of 1"
590
+ end
591
+ Window.new(self, opened_handles.first)
592
+ end
593
+ end
594
+
595
+ ##
596
+ #
597
+ # Execute the given script, not returning a result. This is useful for scripts that return
598
+ # complex objects, such as jQuery statements. {#execute_script} should be used over
599
+ # {#evaluate_script} whenever possible.
600
+ #
601
+ # @param [String] script A string of JavaScript to execute
602
+ # @param args Optional arguments that will be passed to the script. Driver support for this is optional and types of objects supported may differ between drivers
603
+ #
604
+ def execute_script(script, *args)
605
+ @touched = true
606
+ driver.execute_script(script, *driver_args(args))
607
+ end
608
+
609
+ ##
610
+ #
611
+ # Evaluate the given JavaScript and return the result. Be careful when using this with
612
+ # scripts that return complex objects, such as jQuery statements. {#execute_script} might
613
+ # be a better alternative.
614
+ #
615
+ # @param [String] script A string of JavaScript to evaluate
616
+ # @param args Optional arguments that will be passed to the script
617
+ # @return [Object] The result of the evaluated JavaScript (may be driver specific)
618
+ #
619
+ def evaluate_script(script, *args)
620
+ @touched = true
621
+ result = driver.evaluate_script(script.strip, *driver_args(args))
622
+ element_script_result(result)
623
+ end
624
+
625
+ ##
626
+ #
627
+ # Evaluate the given JavaScript and obtain the result from a callback function which will be passed as the last argument to the script.
628
+ #
629
+ # @param [String] script A string of JavaScript to evaluate
630
+ # @param args Optional arguments that will be passed to the script
631
+ # @return [Object] The result of the evaluated JavaScript (may be driver specific)
632
+ #
633
+ def evaluate_async_script(script, *args)
634
+ @touched = true
635
+ result = driver.evaluate_async_script(script, *driver_args(args))
636
+ element_script_result(result)
637
+ end
638
+
639
+ ##
640
+ #
641
+ # Execute the block, accepting a alert.
642
+ #
643
+ # @!macro modal_params
644
+ # Expects a block whose actions will trigger the display modal to appear.
645
+ # @example
646
+ # $0 do
647
+ # click_link('link that triggers appearance of system modal')
648
+ # end
649
+ # @overload $0(text, **options, &blk)
650
+ # @param text [String, Regexp] Text or regex to match against the text in the modal. If not provided any modal is matched.
651
+ # @option options [Numeric] :wait Maximum time to wait for the modal to appear after executing the block. Defaults to {Capybara.configure default_max_wait_time}.
652
+ # @yield Block whose actions will trigger the system modal
653
+ # @overload $0(**options, &blk)
654
+ # @option options [Numeric] :wait Maximum time to wait for the modal to appear after executing the block. Defaults to {Capybara.configure default_max_wait_time}.
655
+ # @yield Block whose actions will trigger the system modal
656
+ # @return [String] the message shown in the modal
657
+ # @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
658
+ #
659
+ def accept_alert(text = nil, **options, &blk)
660
+ accept_modal(:alert, text, options, &blk)
661
+ end
662
+
663
+ ##
664
+ #
665
+ # Execute the block, accepting a confirm.
666
+ #
667
+ # @macro modal_params
668
+ #
669
+ def accept_confirm(text = nil, **options, &blk)
670
+ accept_modal(:confirm, text, options, &blk)
671
+ end
672
+
673
+ ##
674
+ #
675
+ # Execute the block, dismissing a confirm.
676
+ #
677
+ # @macro modal_params
678
+ #
679
+ def dismiss_confirm(text = nil, **options, &blk)
680
+ dismiss_modal(:confirm, text, options, &blk)
681
+ end
682
+
683
+ ##
684
+ #
685
+ # Execute the block, accepting a prompt, optionally responding to the prompt.
686
+ #
687
+ # @macro modal_params
688
+ # @option options [String] :with Response to provide to the prompt
689
+ #
690
+ def accept_prompt(text = nil, **options, &blk)
691
+ accept_modal(:prompt, text, options, &blk)
692
+ end
693
+
694
+ ##
695
+ #
696
+ # Execute the block, dismissing a prompt.
697
+ #
698
+ # @macro modal_params
699
+ #
700
+ def dismiss_prompt(text = nil, **options, &blk)
701
+ dismiss_modal(:prompt, text, options, &blk)
702
+ end
703
+
704
+ ##
705
+ #
706
+ # Save a snapshot of the page. If {Capybara.configure asset_host} is set it will inject `base` tag
707
+ # pointing to {Capybara.configure asset_host}.
708
+ #
709
+ # If invoked without arguments it will save file to {Capybara.configure save_path}
710
+ # and file will be given randomly generated filename. If invoked with a relative path
711
+ # the path will be relative to {Capybara.configure save_path}.
712
+ #
713
+ # @param [String] path the path to where it should be saved
714
+ # @return [String] the path to which the file was saved
715
+ #
716
+ def save_page(path = nil)
717
+ prepare_path(path, 'html').tap do |p_path|
718
+ File.write(p_path, Capybara::Helpers.inject_asset_host(body, host: config.asset_host), mode: 'wb')
719
+ end
720
+ end
721
+
722
+ ##
723
+ #
724
+ # Save a snapshot of the page and open it in a browser for inspection.
725
+ #
726
+ # If invoked without arguments it will save file to {Capybara.configure save_path}
727
+ # and file will be given randomly generated filename. If invoked with a relative path
728
+ # the path will be relative to {Capybara.configure save_path}.
729
+ #
730
+ # @param [String] path the path to where it should be saved
731
+ #
732
+ def save_and_open_page(path = nil)
733
+ save_page(path).tap { |s_path| open_file(s_path) }
734
+ end
735
+
736
+ ##
737
+ #
738
+ # Save a screenshot of page.
739
+ #
740
+ # If invoked without arguments it will save file to {Capybara.configure save_path}
741
+ # and file will be given randomly generated filename. If invoked with a relative path
742
+ # the path will be relative to {Capybara.configure save_path}.
743
+ #
744
+ # @param [String] path the path to where it should be saved
745
+ # @param [Hash] options a customizable set of options
746
+ # @return [String] the path to which the file was saved
747
+ def save_screenshot(path = nil, **options)
748
+ prepare_path(path, 'png').tap { |p_path| driver.save_screenshot(p_path, **options) }
749
+ end
750
+
751
+ ##
752
+ #
753
+ # Save a screenshot of the page and open it for inspection.
754
+ #
755
+ # If invoked without arguments it will save file to {Capybara.configure save_path}
756
+ # and file will be given randomly generated filename. If invoked with a relative path
757
+ # the path will be relative to {Capybara.configure save_path}.
758
+ #
759
+ # @param [String] path the path to where it should be saved
760
+ # @param [Hash] options a customizable set of options
761
+ #
762
+ def save_and_open_screenshot(path = nil, **options)
763
+ save_screenshot(path, **options).tap { |s_path| open_file(s_path) }
764
+ end
765
+
766
+ def document
767
+ @document ||= Capybara::Node::Document.new(self, driver)
768
+ end
769
+
770
+ NODE_METHODS.each do |method|
771
+ class_eval <<~METHOD, __FILE__, __LINE__ + 1
772
+ def #{method}(...)
773
+ @touched = true
774
+ current_scope.#{method}(...)
775
+ end
776
+ METHOD
777
+ end
778
+
779
+ DOCUMENT_METHODS.each do |method|
780
+ class_eval <<~METHOD, __FILE__, __LINE__ + 1
781
+ def #{method}(...)
782
+ document.#{method}(...)
783
+ end
784
+ METHOD
785
+ end
786
+
787
+ def inspect
788
+ %(#<Capybara::Session>)
789
+ end
790
+
791
+ def current_scope
792
+ scope = scopes.last
793
+ [nil, :frame].include?(scope) ? document : scope
794
+ end
795
+
796
+ ##
797
+ #
798
+ # Yield a block using a specific maximum wait time.
799
+ #
800
+ def using_wait_time(seconds, &block)
801
+ if Capybara.threadsafe
802
+ begin
803
+ previous_wait_time = config.default_max_wait_time
804
+ config.default_max_wait_time = seconds
805
+ yield
806
+ ensure
807
+ config.default_max_wait_time = previous_wait_time
808
+ end
809
+ else
810
+ Capybara.using_wait_time(seconds, &block)
811
+ end
812
+ end
813
+
814
+ ##
815
+ #
816
+ # Accepts a block to set the configuration options if {Capybara.configure threadsafe} is `true`. Note that some options only have an effect
817
+ # if set at initialization time, so look at the configuration block that can be passed to the initializer too.
818
+ #
819
+ def configure
820
+ raise 'Session configuration is only supported when Capybara.threadsafe == true' unless Capybara.threadsafe
821
+
822
+ yield config
823
+ end
824
+
825
+ def self.instance_created?
826
+ @@instance_created
827
+ end
828
+
829
+ def config
830
+ @config ||= if Capybara.threadsafe
831
+ Capybara.session_options.dup
832
+ else
833
+ Capybara::ReadOnlySessionConfig.new(Capybara.session_options)
834
+ end
835
+ end
836
+
837
+ def server_url
838
+ @server&.base_url
839
+ end
840
+
841
+ private
842
+
843
+ @@instance_created = false # rubocop:disable Style/ClassVars
844
+
845
+ def driver_args(args)
846
+ args.map { |arg| arg.is_a?(Capybara::Node::Element) ? arg.base : arg }
847
+ end
848
+
849
+ def accept_modal(type, text_or_options, options, &blk)
850
+ driver.accept_modal(type, **modal_options(text_or_options, **options), &blk)
851
+ end
852
+
853
+ def dismiss_modal(type, text_or_options, options, &blk)
854
+ driver.dismiss_modal(type, **modal_options(text_or_options, **options), &blk)
855
+ end
856
+
857
+ def modal_options(text = nil, **options)
858
+ options[:text] ||= text unless text.nil?
859
+ options[:wait] ||= config.default_max_wait_time
860
+ options
861
+ end
862
+
863
+ def open_file(path)
864
+ require 'launchy'
865
+ Launchy.open(path)
866
+ rescue LoadError
867
+ warn "File saved to #{path}.\nPlease install the launchy gem to open the file automatically."
868
+ end
869
+
870
+ def prepare_path(path, extension)
871
+ File.expand_path(path || default_fn(extension), config.save_path).tap do |p_path|
872
+ FileUtils.mkdir_p(File.dirname(p_path))
873
+ end
874
+ end
875
+
876
+ def default_fn(extension)
877
+ timestamp = Time.new.strftime('%Y%m%d%H%M%S')
878
+ "capybara-#{timestamp}#{rand(10**10)}.#{extension}"
879
+ end
880
+
881
+ def scopes
882
+ @scopes ||= [nil]
883
+ end
884
+
885
+ def element_script_result(arg)
886
+ case arg
887
+ when Array
888
+ arg.map { |subarg| element_script_result(subarg) }
889
+ when Hash
890
+ arg.transform_values! { |value| element_script_result(value) }
891
+ when Capybara::Driver::Node
892
+ Capybara::Node::Element.new(self, arg, nil, nil)
893
+ else
894
+ arg
895
+ end
896
+ end
897
+
898
+ def adjust_server_port(uri)
899
+ uri.port ||= @server.port if @server && config.always_include_port
900
+ end
901
+
902
+ def _find_frame(*args, **kw_args)
903
+ case args[0]
904
+ when Capybara::Node::Element
905
+ args[0]
906
+ when String, nil
907
+ find(:frame, *args, **kw_args)
908
+ when Symbol
909
+ find(*args, **kw_args)
910
+ when Integer
911
+ idx = args[0]
912
+ all(:frame, minimum: idx + 1)[idx]
913
+ else
914
+ raise TypeError
915
+ end
916
+ end
917
+
918
+ def _switch_to_window(window = nil, **options, &window_locator)
919
+ raise Capybara::ScopeError, 'Window cannot be switched inside a `within_frame` block' if scopes.include?(:frame)
920
+ raise Capybara::ScopeError, 'Window cannot be switched inside a `within` block' unless scopes.last.nil?
921
+
922
+ if window
923
+ driver.switch_to_window(window.handle)
924
+ window
925
+ else
926
+ synchronize_windows(options) do
927
+ original_window_handle = driver.current_window_handle
928
+ begin
929
+ _switch_to_window_by_locator(&window_locator)
930
+ rescue StandardError
931
+ driver.switch_to_window(original_window_handle)
932
+ raise
933
+ end
934
+ end
935
+ end
936
+ end
937
+
938
+ def _switch_to_window_by_locator
939
+ driver.window_handles.each do |handle|
940
+ driver.switch_to_window handle
941
+ return Window.new(self, handle) if yield
942
+ end
943
+ raise Capybara::WindowError, 'Could not find a window matching block/lambda'
944
+ end
945
+
946
+ def synchronize_windows(options, &block)
947
+ wait_time = Capybara::Queries::BaseQuery.wait(options, config.default_max_wait_time)
948
+ document.synchronize(wait_time, errors: [Capybara::WindowError], &block)
949
+ end
950
+ end
951
+ end