capybara 3.3.0 → 3.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/History.md +803 -13
  4. data/License.txt +1 -1
  5. data/README.md +257 -84
  6. data/lib/capybara/config.rb +25 -9
  7. data/lib/capybara/cucumber.rb +1 -1
  8. data/lib/capybara/driver/base.rb +17 -3
  9. data/lib/capybara/driver/node.rb +31 -6
  10. data/lib/capybara/dsl.rb +9 -7
  11. data/lib/capybara/helpers.rb +31 -7
  12. data/lib/capybara/minitest/spec.rb +180 -88
  13. data/lib/capybara/minitest.rb +262 -149
  14. data/lib/capybara/node/actions.rb +202 -116
  15. data/lib/capybara/node/base.rb +34 -19
  16. data/lib/capybara/node/document.rb +14 -2
  17. data/lib/capybara/node/document_matchers.rb +10 -12
  18. data/lib/capybara/node/element.rb +269 -115
  19. data/lib/capybara/node/finders.rb +99 -77
  20. data/lib/capybara/node/matchers.rb +327 -151
  21. data/lib/capybara/node/simple.rb +48 -13
  22. data/lib/capybara/node/whitespace_normalizer.rb +81 -0
  23. data/lib/capybara/queries/active_element_query.rb +18 -0
  24. data/lib/capybara/queries/ancestor_query.rb +8 -9
  25. data/lib/capybara/queries/base_query.rb +23 -16
  26. data/lib/capybara/queries/current_path_query.rb +16 -6
  27. data/lib/capybara/queries/match_query.rb +1 -0
  28. data/lib/capybara/queries/selector_query.rb +587 -130
  29. data/lib/capybara/queries/sibling_query.rb +8 -6
  30. data/lib/capybara/queries/style_query.rb +6 -2
  31. data/lib/capybara/queries/text_query.rb +28 -14
  32. data/lib/capybara/queries/title_query.rb +2 -2
  33. data/lib/capybara/rack_test/browser.rb +92 -25
  34. data/lib/capybara/rack_test/driver.rb +16 -7
  35. data/lib/capybara/rack_test/errors.rb +6 -0
  36. data/lib/capybara/rack_test/form.rb +68 -41
  37. data/lib/capybara/rack_test/node.rb +106 -39
  38. data/lib/capybara/rails.rb +1 -1
  39. data/lib/capybara/registration_container.rb +41 -0
  40. data/lib/capybara/registrations/drivers.rb +42 -0
  41. data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
  42. data/lib/capybara/registrations/servers.rb +66 -0
  43. data/lib/capybara/result.rb +75 -52
  44. data/lib/capybara/rspec/features.rb +7 -7
  45. data/lib/capybara/rspec/matcher_proxies.rb +39 -18
  46. data/lib/capybara/rspec/matchers/base.rb +113 -0
  47. data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
  48. data/lib/capybara/rspec/matchers/compound.rb +88 -0
  49. data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
  50. data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
  51. data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
  52. data/lib/capybara/rspec/matchers/have_selector.rb +69 -0
  53. data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
  54. data/lib/capybara/rspec/matchers/have_text.rb +33 -0
  55. data/lib/capybara/rspec/matchers/have_title.rb +29 -0
  56. data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
  57. data/lib/capybara/rspec/matchers/match_style.rb +43 -0
  58. data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  59. data/lib/capybara/rspec/matchers.rb +141 -339
  60. data/lib/capybara/rspec.rb +2 -0
  61. data/lib/capybara/selector/builders/css_builder.rb +84 -0
  62. data/lib/capybara/selector/builders/xpath_builder.rb +71 -0
  63. data/lib/capybara/selector/css.rb +27 -25
  64. data/lib/capybara/selector/definition/button.rb +68 -0
  65. data/lib/capybara/selector/definition/checkbox.rb +26 -0
  66. data/lib/capybara/selector/definition/css.rb +10 -0
  67. data/lib/capybara/selector/definition/datalist_input.rb +35 -0
  68. data/lib/capybara/selector/definition/datalist_option.rb +25 -0
  69. data/lib/capybara/selector/definition/element.rb +28 -0
  70. data/lib/capybara/selector/definition/field.rb +40 -0
  71. data/lib/capybara/selector/definition/fieldset.rb +14 -0
  72. data/lib/capybara/selector/definition/file_field.rb +13 -0
  73. data/lib/capybara/selector/definition/fillable_field.rb +33 -0
  74. data/lib/capybara/selector/definition/frame.rb +17 -0
  75. data/lib/capybara/selector/definition/id.rb +6 -0
  76. data/lib/capybara/selector/definition/label.rb +62 -0
  77. data/lib/capybara/selector/definition/link.rb +55 -0
  78. data/lib/capybara/selector/definition/link_or_button.rb +16 -0
  79. data/lib/capybara/selector/definition/option.rb +27 -0
  80. data/lib/capybara/selector/definition/radio_button.rb +27 -0
  81. data/lib/capybara/selector/definition/select.rb +81 -0
  82. data/lib/capybara/selector/definition/table.rb +109 -0
  83. data/lib/capybara/selector/definition/table_row.rb +21 -0
  84. data/lib/capybara/selector/definition/xpath.rb +5 -0
  85. data/lib/capybara/selector/definition.rb +280 -0
  86. data/lib/capybara/selector/filter.rb +1 -0
  87. data/lib/capybara/selector/filter_set.rb +73 -25
  88. data/lib/capybara/selector/filters/base.rb +24 -5
  89. data/lib/capybara/selector/filters/expression_filter.rb +3 -3
  90. data/lib/capybara/selector/filters/locator_filter.rb +29 -0
  91. data/lib/capybara/selector/filters/node_filter.rb +16 -2
  92. data/lib/capybara/selector/regexp_disassembler.rb +211 -0
  93. data/lib/capybara/selector/selector.rb +85 -348
  94. data/lib/capybara/selector/xpath_extensions.rb +17 -0
  95. data/lib/capybara/selector.rb +474 -447
  96. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
  97. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
  98. data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
  99. data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
  100. data/lib/capybara/selenium/driver.rb +255 -143
  101. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +93 -11
  102. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +128 -0
  103. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +84 -0
  104. data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
  105. data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
  106. data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  107. data/lib/capybara/selenium/extensions/find.rb +110 -0
  108. data/lib/capybara/selenium/extensions/html5_drag.rb +229 -0
  109. data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  110. data/lib/capybara/selenium/extensions/scroll.rb +76 -0
  111. data/lib/capybara/selenium/node.rb +436 -134
  112. data/lib/capybara/selenium/nodes/chrome_node.rb +125 -0
  113. data/lib/capybara/selenium/nodes/edge_node.rb +110 -0
  114. data/lib/capybara/selenium/nodes/firefox_node.rb +136 -0
  115. data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
  116. data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
  117. data/lib/capybara/selenium/patches/atoms.rb +18 -0
  118. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  119. data/lib/capybara/selenium/patches/logs.rb +45 -0
  120. data/lib/capybara/selenium/patches/pause_duration_fix.rb +9 -0
  121. data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
  122. data/lib/capybara/server/animation_disabler.rb +56 -19
  123. data/lib/capybara/server/checker.rb +9 -3
  124. data/lib/capybara/server/middleware.rb +28 -12
  125. data/lib/capybara/server.rb +33 -10
  126. data/lib/capybara/session/config.rb +34 -10
  127. data/lib/capybara/session/matchers.rb +23 -16
  128. data/lib/capybara/session.rb +230 -170
  129. data/lib/capybara/spec/public/jquery.js +5 -5
  130. data/lib/capybara/spec/public/offset.js +6 -0
  131. data/lib/capybara/spec/public/test.js +121 -8
  132. data/lib/capybara/spec/session/accept_alert_spec.rb +11 -11
  133. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
  134. data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
  135. data/lib/capybara/spec/session/active_element_spec.rb +31 -0
  136. data/lib/capybara/spec/session/all_spec.rb +127 -40
  137. data/lib/capybara/spec/session/ancestor_spec.rb +24 -19
  138. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +67 -38
  139. data/lib/capybara/spec/session/assert_current_path_spec.rb +21 -18
  140. data/lib/capybara/spec/session/assert_selector_spec.rb +52 -58
  141. data/lib/capybara/spec/session/assert_style_spec.rb +7 -7
  142. data/lib/capybara/spec/session/assert_text_spec.rb +74 -50
  143. data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
  144. data/lib/capybara/spec/session/attach_file_spec.rb +126 -72
  145. data/lib/capybara/spec/session/body_spec.rb +6 -6
  146. data/lib/capybara/spec/session/check_spec.rb +102 -47
  147. data/lib/capybara/spec/session/choose_spec.rb +58 -32
  148. data/lib/capybara/spec/session/click_button_spec.rb +219 -163
  149. data/lib/capybara/spec/session/click_link_or_button_spec.rb +49 -23
  150. data/lib/capybara/spec/session/click_link_spec.rb +77 -54
  151. data/lib/capybara/spec/session/current_scope_spec.rb +8 -8
  152. data/lib/capybara/spec/session/current_url_spec.rb +38 -29
  153. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
  154. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -2
  155. data/lib/capybara/spec/session/element/assert_match_selector_spec.rb +8 -8
  156. data/lib/capybara/spec/session/element/match_css_spec.rb +16 -10
  157. data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
  158. data/lib/capybara/spec/session/element/matches_selector_spec.rb +68 -56
  159. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
  160. data/lib/capybara/spec/session/evaluate_script_spec.rb +28 -8
  161. data/lib/capybara/spec/session/execute_script_spec.rb +8 -7
  162. data/lib/capybara/spec/session/fill_in_spec.rb +101 -46
  163. data/lib/capybara/spec/session/find_button_spec.rb +23 -23
  164. data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
  165. data/lib/capybara/spec/session/find_field_spec.rb +32 -30
  166. data/lib/capybara/spec/session/find_link_spec.rb +31 -21
  167. data/lib/capybara/spec/session/find_spec.rb +244 -141
  168. data/lib/capybara/spec/session/first_spec.rb +43 -43
  169. data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
  170. data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
  171. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +30 -18
  172. data/lib/capybara/spec/session/frame/within_frame_spec.rb +45 -18
  173. data/lib/capybara/spec/session/go_back_spec.rb +1 -1
  174. data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
  175. data/lib/capybara/spec/session/has_all_selectors_spec.rb +23 -23
  176. data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
  177. data/lib/capybara/spec/session/has_any_selectors_spec.rb +29 -0
  178. data/lib/capybara/spec/session/has_button_spec.rb +94 -13
  179. data/lib/capybara/spec/session/has_css_spec.rb +272 -132
  180. data/lib/capybara/spec/session/has_current_path_spec.rb +50 -35
  181. data/lib/capybara/spec/session/has_element_spec.rb +47 -0
  182. data/lib/capybara/spec/session/has_field_spec.rb +137 -58
  183. data/lib/capybara/spec/session/has_link_spec.rb +44 -4
  184. data/lib/capybara/spec/session/has_none_selectors_spec.rb +31 -31
  185. data/lib/capybara/spec/session/has_select_spec.rb +84 -50
  186. data/lib/capybara/spec/session/has_selector_spec.rb +111 -71
  187. data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
  188. data/lib/capybara/spec/session/has_table_spec.rb +181 -4
  189. data/lib/capybara/spec/session/has_text_spec.rb +101 -53
  190. data/lib/capybara/spec/session/has_title_spec.rb +19 -14
  191. data/lib/capybara/spec/session/has_xpath_spec.rb +56 -38
  192. data/lib/capybara/spec/session/headers_spec.rb +1 -1
  193. data/lib/capybara/spec/session/html_spec.rb +13 -6
  194. data/lib/capybara/spec/session/matches_style_spec.rb +37 -0
  195. data/lib/capybara/spec/session/node_spec.rb +894 -142
  196. data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
  197. data/lib/capybara/spec/session/refresh_spec.rb +9 -7
  198. data/lib/capybara/spec/session/reset_session_spec.rb +63 -35
  199. data/lib/capybara/spec/session/response_code_spec.rb +1 -1
  200. data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
  201. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  202. data/lib/capybara/spec/session/save_page_spec.rb +37 -37
  203. data/lib/capybara/spec/session/save_screenshot_spec.rb +10 -10
  204. data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
  205. data/lib/capybara/spec/session/scroll_spec.rb +119 -0
  206. data/lib/capybara/spec/session/select_spec.rb +85 -85
  207. data/lib/capybara/spec/session/selectors_spec.rb +49 -18
  208. data/lib/capybara/spec/session/sibling_spec.rb +9 -9
  209. data/lib/capybara/spec/session/text_spec.rb +25 -24
  210. data/lib/capybara/spec/session/title_spec.rb +7 -6
  211. data/lib/capybara/spec/session/uncheck_spec.rb +33 -21
  212. data/lib/capybara/spec/session/unselect_spec.rb +37 -37
  213. data/lib/capybara/spec/session/visit_spec.rb +68 -49
  214. data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
  215. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
  216. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +20 -16
  217. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +6 -2
  218. data/lib/capybara/spec/session/window/window_spec.rb +62 -63
  219. data/lib/capybara/spec/session/window/windows_spec.rb +5 -1
  220. data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
  221. data/lib/capybara/spec/session/within_spec.rb +79 -42
  222. data/lib/capybara/spec/spec_helper.rb +41 -53
  223. data/lib/capybara/spec/test_app.rb +132 -43
  224. data/lib/capybara/spec/views/animated.erb +49 -0
  225. data/lib/capybara/spec/views/form.erb +139 -42
  226. data/lib/capybara/spec/views/frame_child.erb +4 -3
  227. data/lib/capybara/spec/views/frame_one.erb +2 -1
  228. data/lib/capybara/spec/views/frame_parent.erb +1 -1
  229. data/lib/capybara/spec/views/frame_two.erb +1 -1
  230. data/lib/capybara/spec/views/initial_alert.erb +2 -1
  231. data/lib/capybara/spec/views/layout.erb +10 -0
  232. data/lib/capybara/spec/views/obscured.erb +47 -0
  233. data/lib/capybara/spec/views/offset.erb +33 -0
  234. data/lib/capybara/spec/views/path.erb +2 -2
  235. data/lib/capybara/spec/views/popup_one.erb +1 -1
  236. data/lib/capybara/spec/views/popup_two.erb +1 -1
  237. data/lib/capybara/spec/views/react.erb +45 -0
  238. data/lib/capybara/spec/views/scroll.erb +21 -0
  239. data/lib/capybara/spec/views/spatial.erb +31 -0
  240. data/lib/capybara/spec/views/tables.erb +67 -0
  241. data/lib/capybara/spec/views/with_animation.erb +39 -4
  242. data/lib/capybara/spec/views/with_base_tag.erb +2 -2
  243. data/lib/capybara/spec/views/with_dragula.erb +24 -0
  244. data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
  245. data/lib/capybara/spec/views/with_hover.erb +3 -2
  246. data/lib/capybara/spec/views/with_hover1.erb +10 -0
  247. data/lib/capybara/spec/views/with_html.erb +37 -9
  248. data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
  249. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  250. data/lib/capybara/spec/views/with_js.erb +26 -5
  251. data/lib/capybara/spec/views/with_jstree.erb +26 -0
  252. data/lib/capybara/spec/views/with_namespace.erb +1 -0
  253. data/lib/capybara/spec/views/with_scope.erb +2 -2
  254. data/lib/capybara/spec/views/with_scope_other.erb +6 -0
  255. data/lib/capybara/spec/views/with_shadow.erb +31 -0
  256. data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
  257. data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
  258. data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
  259. data/lib/capybara/spec/views/with_windows.erb +1 -1
  260. data/lib/capybara/spec/views/within_frames.erb +1 -1
  261. data/lib/capybara/version.rb +1 -1
  262. data/lib/capybara/window.rb +19 -25
  263. data/lib/capybara.rb +126 -111
  264. data/spec/basic_node_spec.rb +59 -34
  265. data/spec/capybara_spec.rb +56 -44
  266. data/spec/counter_spec.rb +35 -0
  267. data/spec/css_builder_spec.rb +101 -0
  268. data/spec/css_splitter_spec.rb +8 -8
  269. data/spec/dsl_spec.rb +79 -52
  270. data/spec/filter_set_spec.rb +9 -9
  271. data/spec/fixtures/selenium_driver_rspec_failure.rb +4 -4
  272. data/spec/fixtures/selenium_driver_rspec_success.rb +4 -4
  273. data/spec/minitest_spec.rb +45 -7
  274. data/spec/minitest_spec_spec.rb +87 -64
  275. data/spec/per_session_config_spec.rb +6 -6
  276. data/spec/rack_test_spec.rb +172 -116
  277. data/spec/regexp_dissassembler_spec.rb +250 -0
  278. data/spec/result_spec.rb +80 -72
  279. data/spec/rspec/features_spec.rb +21 -16
  280. data/spec/rspec/scenarios_spec.rb +10 -6
  281. data/spec/rspec/shared_spec_matchers.rb +407 -365
  282. data/spec/rspec/views_spec.rb +3 -3
  283. data/spec/rspec_matchers_spec.rb +35 -10
  284. data/spec/rspec_spec.rb +63 -41
  285. data/spec/sauce_spec_chrome.rb +43 -0
  286. data/spec/selector_spec.rb +334 -89
  287. data/spec/selenium_spec_chrome.rb +176 -62
  288. data/spec/selenium_spec_chrome_remote.rb +54 -14
  289. data/spec/selenium_spec_edge.rb +41 -8
  290. data/spec/selenium_spec_firefox.rb +228 -0
  291. data/spec/selenium_spec_firefox_remote.rb +94 -0
  292. data/spec/selenium_spec_ie.rb +129 -11
  293. data/spec/selenium_spec_safari.rb +162 -0
  294. data/spec/server_spec.rb +171 -97
  295. data/spec/session_spec.rb +34 -18
  296. data/spec/shared_selenium_node.rb +79 -0
  297. data/spec/shared_selenium_session.rb +344 -80
  298. data/spec/spec_helper.rb +124 -2
  299. data/spec/whitespace_normalizer_spec.rb +54 -0
  300. data/spec/xpath_builder_spec.rb +93 -0
  301. metadata +326 -28
  302. data/lib/capybara/rspec/compound.rb +0 -94
  303. data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -31
  304. data/lib/capybara/selenium/nodes/marionette_node.rb +0 -31
  305. data/lib/capybara/spec/session/has_style_spec.rb +0 -25
  306. data/lib/capybara/spec/session/source_spec.rb +0 -0
  307. data/lib/capybara/spec/views/with_title.erb +0 -5
  308. data/spec/selenium_spec_marionette.rb +0 -167
@@ -5,426 +5,482 @@ Capybara::SpecHelper.spec '#click_button' do
5
5
  @session.visit('/form')
6
6
  end
7
7
 
8
- it "should wait for asynchronous load", requires: [:js] do
8
+ it 'should wait for asynchronous load', requires: [:js] do
9
9
  @session.visit('/with_js')
10
- @session.click_link('Click me')
11
- @session.click_button('New Here')
10
+ @session.using_wait_time(1.5) do
11
+ @session.click_link('Click me')
12
+ @session.click_button('New Here')
13
+ end
12
14
  end
13
15
 
14
- it "casts to string" do
16
+ it 'casts to string' do
15
17
  @session.click_button(:'Relative Action')
16
18
  expect(extract_results(@session)['relative']).to eq('Relative Action')
17
19
  expect(@session.current_path).to eq('/relative')
18
20
  end
19
21
 
20
- context "with multiple values with the same name" do
21
- it "should use the latest given value" do
22
+ context 'with multiple values with the same name' do
23
+ it 'should use the latest given value' do
22
24
  @session.check('Terms of Use')
23
25
  @session.click_button('awesome')
24
26
  expect(extract_results(@session)['terms_of_use']).to eq('1')
25
27
  end
26
28
  end
27
29
 
28
- context "with a form that has a relative url as an action" do
29
- it "should post to the correct url" do
30
+ context 'with a form that has a relative url as an action' do
31
+ it 'should post to the correct url' do
30
32
  @session.click_button('Relative Action')
31
33
  expect(extract_results(@session)['relative']).to eq('Relative Action')
32
34
  expect(@session.current_path).to eq('/relative')
33
35
  end
34
36
  end
35
37
 
36
- context "with a form that has no action specified" do
37
- it "should post to the correct url" do
38
+ context 'with a form that has no action specified' do
39
+ it 'should post to the correct url' do
38
40
  @session.click_button('No Action')
39
41
  expect(extract_results(@session)['no_action']).to eq('No Action')
40
42
  expect(@session.current_path).to eq('/form')
41
43
  end
42
44
  end
43
45
 
44
- context "with value given on a submit button" do
45
- context "on a form with HTML5 fields" do
46
+ context 'with value given on a submit button' do
47
+ context 'on a form with HTML5 fields' do
48
+ let(:results) { extract_results(@session) }
49
+
46
50
  before do
47
51
  @session.click_button('html5_submit')
48
- @results = extract_results(@session)
49
52
  end
50
53
 
51
- it "should serialise and submit search fields" do
52
- expect(@results['html5_search']).to eq('what are you looking for')
54
+ it 'should serialise and submit search fields' do
55
+ expect(results['html5_search']).to eq('what are you looking for')
53
56
  end
54
57
 
55
- it "should serialise and submit email fields" do
56
- expect(@results['html5_email']).to eq('person@email.com')
58
+ it 'should serialise and submit email fields' do
59
+ expect(results['html5_email']).to eq('person@email.com')
57
60
  end
58
61
 
59
- it "should serialise and submit url fields" do
60
- expect(@results['html5_url']).to eq('http://www.example.com')
62
+ it 'should serialise and submit url fields' do
63
+ expect(results['html5_url']).to eq('http://www.example.com')
61
64
  end
62
65
 
63
- it "should serialise and submit tel fields" do
64
- expect(@results['html5_tel']).to eq('911')
66
+ it 'should serialise and submit tel fields' do
67
+ expect(results['html5_tel']).to eq('911')
65
68
  end
66
69
 
67
- it "should serialise and submit color fields" do
68
- expect(@results['html5_color'].upcase).to eq('#FFFFFF')
70
+ it 'should serialise and submit color fields' do
71
+ expect(results['html5_color'].upcase).to eq('#FFFFFF')
69
72
  end
70
73
  end
71
74
 
72
- context "on an HTML4 form" do
75
+ context 'on an HTML4 form' do
76
+ let(:results) { extract_results(@session) }
77
+
73
78
  before do
74
79
  @session.click_button('awesome')
75
- @results = extract_results(@session)
76
80
  end
77
81
 
78
- it "should serialize and submit text fields" do
79
- expect(@results['first_name']).to eq('John')
82
+ it 'should serialize and submit text fields' do
83
+ expect(results['first_name']).to eq('John')
80
84
  end
81
85
 
82
- it "should escape fields when submitting" do
83
- expect(@results['phone']).to eq('+1 555 7021')
86
+ it 'should escape fields when submitting' do
87
+ expect(results['phone']).to eq('+1 555 7021')
84
88
  end
85
89
 
86
- it "should serialize and submit password fields" do
87
- expect(@results['password']).to eq('seeekrit')
90
+ it 'should serialize and submit password fields' do
91
+ expect(results['password']).to eq('seeekrit')
88
92
  end
89
93
 
90
- it "should serialize and submit hidden fields" do
91
- expect(@results['token']).to eq('12345')
94
+ it 'should serialize and submit hidden fields' do
95
+ expect(results['token']).to eq('12345')
92
96
  end
93
97
 
94
- it "should not serialize fields from other forms" do
95
- expect(@results['middle_name']).to be_nil
98
+ it 'should not serialize fields from other forms' do
99
+ expect(results['middle_name']).to be_nil
96
100
  end
97
101
 
98
- it "should submit the button that was clicked, but not other buttons" do
99
- expect(@results['awesome']).to eq('awesome')
100
- expect(@results['crappy']).to be_nil
102
+ it 'should submit the button that was clicked, but not other buttons' do
103
+ expect(results['awesome']).to eq('awesome')
104
+ expect(results['crappy']).to be_nil
101
105
  end
102
106
 
103
- it "should serialize radio buttons" do
104
- expect(@results['gender']).to eq('female')
107
+ it 'should serialize radio buttons' do
108
+ expect(results['gender']).to eq('female')
105
109
  end
106
110
 
107
111
  it "should default radio value to 'on' if none specified" do
108
- expect(@results['valueless_radio']).to eq('on')
112
+ expect(results['valueless_radio']).to eq('on')
109
113
  end
110
114
 
111
- it "should serialize check boxes" do
112
- expect(@results['pets']).to include('dog', 'hamster')
113
- expect(@results['pets']).not_to include('cat')
115
+ it 'should serialize check boxes' do
116
+ expect(results['pets']).to include('dog', 'hamster')
117
+ expect(results['pets']).not_to include('cat')
114
118
  end
115
119
 
116
120
  it "should default checkbox value to 'on' if none specififed" do
117
- expect(@results['valueless_checkbox']).to eq('on')
121
+ expect(results['valueless_checkbox']).to eq('on')
118
122
  end
119
123
 
120
- it "should serialize text areas" do
121
- expect(@results['description']).to eq('Descriptive text goes here')
124
+ it 'should serialize text areas' do
125
+ expect(results['description']).to eq('Descriptive text goes here')
122
126
  end
123
127
 
124
- it "should serialize select tag with values" do
125
- expect(@results['locale']).to eq('en')
128
+ it 'should serialize select tag with values' do
129
+ expect(results['locale']).to eq('en')
126
130
  end
127
131
 
128
- it "should serialize select tag without values" do
129
- expect(@results['region']).to eq('Norway')
132
+ it 'should serialize select tag without values' do
133
+ expect(results['region']).to eq('Norway')
130
134
  end
131
135
 
132
- it "should serialize first option for select tag with no selection" do
133
- expect(@results['city']).to eq('London')
136
+ it 'should serialize first option for select tag with no selection' do
137
+ expect(results['city']).to eq('London')
134
138
  end
135
139
 
136
- it "should not serialize a select tag without options" do
137
- expect(@results['tendency']).to be_nil
140
+ it 'should not serialize a select tag without options' do
141
+ expect(results['tendency']).to be_nil
138
142
  end
139
143
 
140
- it "should convert lf to cr/lf in submitted textareas" do
141
- expect(@results['newline']).to eq("\r\nNew line after and before textarea tag\r\n")
144
+ it 'should convert lf to cr/lf in submitted textareas' do
145
+ expect(results['newline']).to eq("\r\nNew line after and before textarea tag\r\n")
142
146
  end
143
147
 
144
- it "should not submit disabled fields" do
145
- expect(@results['disabled_text_field']).to be_nil
146
- expect(@results['disabled_textarea']).to be_nil
147
- expect(@results['disabled_checkbox']).to be_nil
148
- expect(@results['disabled_radio']).to be_nil
149
- expect(@results['disabled_select']).to be_nil
150
- expect(@results['disabled_file']).to be_nil
148
+ it 'should not submit disabled fields' do
149
+ expect(results['disabled_text_field']).to be_nil
150
+ expect(results['disabled_textarea']).to be_nil
151
+ expect(results['disabled_checkbox']).to be_nil
152
+ expect(results['disabled_radio']).to be_nil
153
+ expect(results['disabled_select']).to be_nil
154
+ expect(results['disabled_file']).to be_nil
151
155
  end
152
156
  end
153
157
  end
154
158
 
155
- context "input type=submit button" do
156
- it "should submit by button id" do
159
+ context 'input type=submit button' do
160
+ it 'should submit by button id' do
157
161
  @session.click_button('awe123')
158
162
  expect(extract_results(@session)['first_name']).to eq('John')
159
163
  end
160
164
 
161
- it "should submit by button title" do
165
+ it 'should submit by specific button id' do
166
+ @session.click_button(id: 'awe123')
167
+ expect(extract_results(@session)['first_name']).to eq('John')
168
+ end
169
+
170
+ it 'should submit by button title' do
162
171
  @session.click_button('What an Awesome Button')
163
172
  expect(extract_results(@session)['first_name']).to eq('John')
164
173
  end
165
174
 
166
- it "should submit by partial title", :exact_false do
175
+ it 'should submit by partial title', :exact_false do
167
176
  @session.click_button('What an Awesome')
168
177
  expect(extract_results(@session)['first_name']).to eq('John')
169
178
  end
179
+
180
+ it 'should submit by button name' do
181
+ @session.click_button('form[awesome]')
182
+ expect(extract_results(@session)['first_name']).to eq('John')
183
+ end
184
+
185
+ it 'should submit by specific button name' do
186
+ @session.click_button(name: 'form[awesome]')
187
+ expect(extract_results(@session)['first_name']).to eq('John')
188
+ end
189
+
190
+ it 'should submit by specific button name regex' do
191
+ @session.click_button(name: /form\[awes.*\]/)
192
+ expect(extract_results(@session)['first_name']).to eq('John')
193
+ end
170
194
  end
171
195
 
172
- context "with fields associated with the form using the form attribute", requires: [:form_attribute] do
196
+ context 'when Capybara.enable_aria_role = true' do
197
+ it 'should click on a button role', requires: [:js] do
198
+ Capybara.enable_aria_role = true
199
+ @session.using_wait_time(1.5) do
200
+ @session.visit('/with_js')
201
+ @session.click_button('ARIA button')
202
+ expect(@session).to have_button('ARIA button has been clicked')
203
+ end
204
+ end
205
+ end
206
+
207
+ context 'with fields associated with the form using the form attribute', requires: [:form_attribute] do
208
+ let(:results) { extract_results(@session) }
209
+
173
210
  before do
174
211
  @session.click_button('submit_form1')
175
- @results = extract_results(@session)
176
212
  end
177
213
 
178
- it "should serialize and submit text fields" do
179
- expect(@results['outside_input']).to eq('outside_input')
214
+ it 'should serialize and submit text fields' do
215
+ expect(results['outside_input']).to eq('outside_input')
180
216
  end
181
217
 
182
- it "should serialize text areas" do
183
- expect(@results['outside_textarea']).to eq('Some text here')
218
+ it 'should serialize text areas' do
219
+ expect(results['outside_textarea']).to eq('Some text here')
184
220
  end
185
221
 
186
- it "should serialize select tags" do
187
- expect(@results['outside_select']).to eq('Ruby')
222
+ it 'should serialize select tags' do
223
+ expect(results['outside_select']).to eq('Ruby')
188
224
  end
189
225
 
190
- it "should not serliaze fields associated with a different form" do
191
- expect(@results['for_form2']).to be_nil
226
+ it 'should not serliaze fields associated with a different form' do
227
+ expect(results['for_form2']).to be_nil
192
228
  end
193
229
  end
194
230
 
195
- context "with submit button outside the form defined by <button> tag", requires: [:form_attribute] do
231
+ context 'with submit button outside the form defined by <button> tag', requires: [:form_attribute] do
232
+ let(:results) { extract_results(@session) }
233
+
196
234
  before do
197
235
  @session.click_button('outside_button')
198
- @results = extract_results(@session)
199
236
  end
200
237
 
201
- it "should submit the associated form" do
202
- expect(@results['which_form']).to eq('form2')
238
+ it 'should submit the associated form' do
239
+ expect(results['which_form']).to eq('form2')
203
240
  end
204
241
 
205
- it "should submit the button that was clicked, but not other buttons" do
206
- expect(@results['outside_button']).to eq('outside_button')
207
- expect(@results['unused']).to be_nil
242
+ it 'should submit the button that was clicked, but not other buttons' do
243
+ expect(results['outside_button']).to eq('outside_button')
244
+ expect(results['unused']).to be_nil
208
245
  end
209
246
  end
210
247
 
211
248
  context "with submit button outside the form defined by <input type='submit'> tag", requires: [:form_attribute] do
249
+ let(:results) { extract_results(@session) }
250
+
212
251
  before do
213
252
  @session.click_button('outside_submit')
214
- @results = extract_results(@session)
215
253
  end
216
254
 
217
- it "should submit the associated form" do
218
- expect(@results['which_form']).to eq('form1')
255
+ it 'should submit the associated form' do
256
+ expect(results['which_form']).to eq('form1')
219
257
  end
220
258
 
221
- it "should submit the button that was clicked, but not other buttons" do
222
- expect(@results['outside_submit']).to eq('outside_submit')
223
- expect(@results['submit_form1']).to be_nil
259
+ it 'should submit the button that was clicked, but not other buttons' do
260
+ expect(results['outside_submit']).to eq('outside_submit')
261
+ expect(results['submit_form1']).to be_nil
224
262
  end
225
263
  end
226
264
 
227
- context "with submit button for form1 located within form2", requires: [:form_attribute] do
228
- it "should submit the form associated with the button" do
265
+ context 'with submit button for form1 located within form2', requires: [:form_attribute] do
266
+ it 'should submit the form associated with the button' do
229
267
  @session.click_button('other_form_button')
230
- expect(extract_results(@session)['which_form']).to eq("form1")
268
+ expect(extract_results(@session)['which_form']).to eq('form1')
231
269
  end
232
270
  end
233
271
 
234
- context "with submit button not associated with any form" do
235
- it "should not error when clicked" do
272
+ context 'with submit button not associated with any form' do
273
+ it 'should not error when clicked' do
236
274
  expect { @session.click_button('no_form_button') }.not_to raise_error
237
275
  end
238
276
  end
239
277
 
240
- context "with alt given on an image button" do
241
- it "should submit the associated form" do
278
+ context 'with alt given on an image button' do
279
+ it 'should submit the associated form' do
242
280
  @session.click_button('oh hai thar')
243
281
  expect(extract_results(@session)['first_name']).to eq('John')
244
282
  end
245
283
 
246
- it "should work with partial matches", :exact_false do
284
+ it 'should work with partial matches', :exact_false do
247
285
  @session.click_button('hai')
248
286
  expect(extract_results(@session)['first_name']).to eq('John')
249
287
  end
250
288
  end
251
289
 
252
- context "with value given on an image button" do
253
- it "should submit the associated form" do
290
+ context 'with value given on an image button' do
291
+ it 'should submit the associated form' do
254
292
  @session.click_button('okay')
255
293
  expect(extract_results(@session)['first_name']).to eq('John')
256
294
  end
257
295
 
258
- it "should work with partial matches", :exact_false do
296
+ it 'should work with partial matches', :exact_false do
259
297
  @session.click_button('kay')
260
298
  expect(extract_results(@session)['first_name']).to eq('John')
261
299
  end
262
300
  end
263
301
 
264
- context "with id given on an image button" do
265
- it "should submit the associated form" do
302
+ context 'with id given on an image button' do
303
+ it 'should submit the associated form' do
266
304
  @session.click_button('okay556')
267
305
  expect(extract_results(@session)['first_name']).to eq('John')
268
306
  end
269
307
  end
270
308
 
271
- context "with title given on an image button" do
272
- it "should submit the associated form" do
309
+ context 'with title given on an image button' do
310
+ it 'should submit the associated form' do
273
311
  @session.click_button('Okay 556 Image')
274
312
  expect(extract_results(@session)['first_name']).to eq('John')
275
313
  end
276
314
 
277
- it "should work with partial matches", :exact_false do
315
+ it 'should work with partial matches', :exact_false do
278
316
  @session.click_button('Okay 556')
279
317
  expect(extract_results(@session)['first_name']).to eq('John')
280
318
  end
281
319
  end
282
320
 
283
- context "with text given on a button defined by <button> tag" do
284
- it "should submit the associated form" do
321
+ context 'with text given on a button defined by <button> tag' do
322
+ it 'should submit the associated form' do
285
323
  @session.click_button('Click me!')
286
324
  expect(extract_results(@session)['first_name']).to eq('John')
287
325
  end
288
326
 
289
- it "should work with partial matches", :exact_false do
327
+ it 'should work with partial matches', :exact_false do
290
328
  @session.click_button('Click')
291
329
  expect(extract_results(@session)['first_name']).to eq('John')
292
330
  end
293
331
  end
294
332
 
295
- context "with id given on a button defined by <button> tag" do
296
- it "should submit the associated form" do
333
+ context 'with id given on a button defined by <button> tag' do
334
+ it 'should submit the associated form' do
297
335
  @session.click_button('click_me_123')
298
336
  expect(extract_results(@session)['first_name']).to eq('John')
299
337
  end
300
338
 
301
- it "should serialize and send GET forms" do
339
+ it 'should serialize and send GET forms' do
302
340
  @session.visit('/form')
303
341
  @session.click_button('med')
304
- @results = extract_results(@session)
305
- expect(@results['middle_name']).to eq('Darren')
306
- expect(@results['foo']).to be_nil
342
+ results = extract_results(@session)
343
+ expect(results['middle_name']).to eq('Darren')
344
+ expect(results['foo']).to be_nil
307
345
  end
308
346
  end
309
347
 
310
- context "with value given on a button defined by <button> tag" do
311
- it "should submit the associated form" do
348
+ context 'with name given on a button defined by <button> tag' do
349
+ it 'should submit the associated form when name is locator' do
350
+ @session.click_button('form[no_value]')
351
+ expect(extract_results(@session)['first_name']).to eq('John')
352
+ end
353
+
354
+ it 'should submit the associated form when name is specific' do
355
+ @session.click_button(name: 'form[no_value]')
356
+ expect(extract_results(@session)['first_name']).to eq('John')
357
+ end
358
+ end
359
+
360
+ context 'with value given on a button defined by <button> tag' do
361
+ it 'should submit the associated form' do
312
362
  @session.click_button('click_me')
313
363
  expect(extract_results(@session)['first_name']).to eq('John')
314
364
  end
315
365
 
316
- it "should work with partial matches", :exact_false do
366
+ it 'should work with partial matches', :exact_false do
317
367
  @session.click_button('ck_me')
318
368
  expect(extract_results(@session)['first_name']).to eq('John')
319
369
  end
320
370
  end
321
371
 
322
- context "with title given on a button defined by <button> tag" do
323
- it "should submit the associated form" do
372
+ context 'with title given on a button defined by <button> tag' do
373
+ it 'should submit the associated form' do
324
374
  @session.click_button('Click Title button')
325
375
  expect(extract_results(@session)['first_name']).to eq('John')
326
376
  end
327
377
 
328
- it "should work with partial matches", :exact_false do
378
+ it 'should work with partial matches', :exact_false do
329
379
  @session.click_button('Click Title')
330
380
  expect(extract_results(@session)['first_name']).to eq('John')
331
381
  end
332
382
  end
333
383
 
334
- context "with descendant image alt given on a button defined by <button> tag" do
335
- it "should submit the associated form" do
384
+ context 'with descendant image alt given on a button defined by <button> tag' do
385
+ it 'should submit the associated form' do
336
386
  @session.click_button('A horse eating hay')
337
387
  expect(extract_results(@session)['first_name']).to eq('John')
338
388
  end
339
389
 
340
- it "should work with partial matches", :exact_false do
390
+ it 'should work with partial matches', :exact_false do
341
391
  @session.click_button('se eating h')
342
392
  expect(extract_results(@session)['first_name']).to eq('John')
343
393
  end
344
394
  end
345
395
 
346
396
  context "with a locator that doesn't exist" do
347
- it "should raise an error" do
348
- msg = "Unable to find visible button \"does not exist\""
397
+ it 'should raise an error' do
398
+ msg = /Unable to find button "does not exist"/
349
399
  expect do
350
400
  @session.click_button('does not exist')
351
401
  end.to raise_error(Capybara::ElementNotFound, msg)
352
402
  end
353
403
  end
354
404
 
355
- context "with formaction attribute on button" do
356
- it "should submit to the formaction attribute" do
405
+ context 'with formaction attribute on button' do
406
+ it 'should submit to the formaction attribute' do
357
407
  @session.click_button('Formaction button')
358
- @results = extract_results(@session)
408
+ results = extract_results(@session)
359
409
  expect(@session.current_path).to eq '/form'
360
- expect(@results['which_form']).to eq 'formaction form'
410
+ expect(results['which_form']).to eq 'formaction form'
361
411
  end
362
412
  end
363
413
 
364
- context "with formmethod attribute on button" do
365
- it "should submit to the formethod attribute" do
414
+ context 'with formmethod attribute on button' do
415
+ it 'should submit to the formethod attribute' do
366
416
  @session.click_button('Formmethod button')
367
- @results = extract_results(@session)
417
+ results = extract_results(@session)
368
418
  expect(@session.current_path).to eq '/form/get'
369
- expect(@results['which_form']).to eq 'formaction form'
419
+ expect(results['which_form']).to eq 'formaction form'
370
420
  end
371
421
  end
372
422
 
373
- it "should serialize and send valueless buttons that were clicked" do
423
+ it 'should serialize and send valueless buttons that were clicked' do
374
424
  @session.click_button('No Value!')
375
- @results = extract_results(@session)
376
- expect(@results['no_value']).not_to be_nil
425
+ results = extract_results(@session)
426
+ expect(results['no_value']).not_to be_nil
427
+ end
428
+
429
+ it 'should send button in document order' do
430
+ @session.click_button('outside_button')
431
+ results = extract_results(@session)
432
+ expect(results.keys).to eq %w[for_form2 outside_button which_form post_count]
377
433
  end
378
434
 
379
- it "should not send image buttons that were not clicked" do
435
+ it 'should not send image buttons that were not clicked' do
380
436
  @session.click_button('Click me!')
381
- @results = extract_results(@session)
382
- expect(@results['okay']).to be_nil
437
+ results = extract_results(@session)
438
+ expect(results['okay']).to be_nil
383
439
  end
384
440
 
385
- it "should serialize and send GET forms" do
441
+ it 'should serialize and send GET forms' do
386
442
  @session.visit('/form')
387
443
  @session.click_button('med')
388
- @results = extract_results(@session)
389
- expect(@results['middle_name']).to eq('Darren')
390
- expect(@results['foo']).to be_nil
444
+ results = extract_results(@session)
445
+ expect(results['middle_name']).to eq('Darren')
446
+ expect(results['foo']).to be_nil
391
447
  end
392
448
 
393
- it "should follow redirects" do
449
+ it 'should follow redirects' do
394
450
  @session.click_button('Go FAR')
395
451
  expect(@session).to have_content('You landed')
396
452
  expect(@session.current_url).to match(%r{/landed$})
397
453
  end
398
454
 
399
- it "should follow temporary redirects that maintain method" do
455
+ it 'should follow temporary redirects that maintain method' do
400
456
  @session.click_button('Go 307')
401
457
  expect(@session).to have_content('You post landed: TWTW')
402
458
  end
403
459
 
404
- it "should follow permanent redirects that maintain method" do
460
+ it 'should follow permanent redirects that maintain method' do
405
461
  @session.click_button('Go 308')
406
462
  expect(@session).to have_content('You post landed: TWTW')
407
463
  end
408
464
 
409
- it "should post pack to the same URL when no action given" do
465
+ it 'should post pack to the same URL when no action given' do
410
466
  @session.visit('/postback')
411
467
  @session.click_button('With no action')
412
468
  expect(@session).to have_content('Postback')
413
469
  end
414
470
 
415
- it "should post pack to the same URL when blank action given" do
471
+ it 'should post pack to the same URL when blank action given' do
416
472
  @session.visit('/postback')
417
473
  @session.click_button('With blank action')
418
474
  expect(@session).to have_content('Postback')
419
475
  end
420
476
 
421
- it "ignores disabled buttons" do
477
+ it 'ignores disabled buttons' do
422
478
  expect do
423
479
  @session.click_button('Disabled button')
424
480
  end.to raise_error(Capybara::ElementNotFound)
425
481
  end
426
482
 
427
- it "should encode complex field names, like array[][value]" do
483
+ it 'should encode complex field names, like array[][value]' do
428
484
  @session.visit('/form')
429
485
  @session.fill_in('address1_city', with: 'Paris')
430
486
  @session.fill_in('address1_street', with: 'CDG')
@@ -432,27 +488,27 @@ Capybara::SpecHelper.spec '#click_button' do
432
488
  @session.fill_in('address2_city', with: 'Mikolaiv')
433
489
  @session.fill_in('address2_street', with: 'PGS')
434
490
 
435
- @session.click_button "awesome"
491
+ @session.click_button 'awesome'
436
492
 
437
- addresses = extract_results(@session)["addresses"]
493
+ addresses = extract_results(@session)['addresses']
438
494
  expect(addresses.size).to eq(2)
439
495
 
440
- expect(addresses[0]["street"]).to eq('CDG')
441
- expect(addresses[0]["city"]).to eq('Paris')
442
- expect(addresses[0]["country"]).to eq('France')
496
+ expect(addresses[0]['street']).to eq('CDG')
497
+ expect(addresses[0]['city']).to eq('Paris')
498
+ expect(addresses[0]['country']).to eq('France')
443
499
 
444
- expect(addresses[1]["street"]).to eq('PGS')
445
- expect(addresses[1]["city"]).to eq('Mikolaiv')
446
- expect(addresses[1]["country"]).to eq('Ukraine')
500
+ expect(addresses[1]['street']).to eq('PGS')
501
+ expect(addresses[1]['city']).to eq('Mikolaiv')
502
+ expect(addresses[1]['country']).to eq('Ukraine')
447
503
  end
448
504
 
449
- context "with :exact option" do
450
- it "should accept partial matches when false" do
505
+ context 'with :exact option' do
506
+ it 'should accept partial matches when false' do
451
507
  @session.click_button('What an Awesome', exact: false)
452
508
  expect(extract_results(@session)['first_name']).to eq('John')
453
509
  end
454
510
 
455
- it "should not accept partial matches when true" do
511
+ it 'should not accept partial matches when true' do
456
512
  expect do
457
513
  @session.click_button('What an Awesome', exact: true)
458
514
  end.to raise_error(Capybara::ElementNotFound)