capybara 3.13.2 → 3.40.0

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 (260) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/History.md +587 -16
  4. data/README.md +240 -90
  5. data/lib/capybara/config.rb +24 -11
  6. data/lib/capybara/cucumber.rb +1 -1
  7. data/lib/capybara/driver/base.rb +8 -0
  8. data/lib/capybara/driver/node.rb +20 -4
  9. data/lib/capybara/dsl.rb +5 -3
  10. data/lib/capybara/helpers.rb +25 -4
  11. data/lib/capybara/minitest/spec.rb +174 -90
  12. data/lib/capybara/minitest.rb +256 -142
  13. data/lib/capybara/node/actions.rb +123 -77
  14. data/lib/capybara/node/base.rb +20 -12
  15. data/lib/capybara/node/document.rb +2 -2
  16. data/lib/capybara/node/document_matchers.rb +3 -3
  17. data/lib/capybara/node/element.rb +223 -117
  18. data/lib/capybara/node/finders.rb +81 -71
  19. data/lib/capybara/node/matchers.rb +271 -134
  20. data/lib/capybara/node/simple.rb +18 -5
  21. data/lib/capybara/node/whitespace_normalizer.rb +81 -0
  22. data/lib/capybara/queries/active_element_query.rb +18 -0
  23. data/lib/capybara/queries/ancestor_query.rb +8 -9
  24. data/lib/capybara/queries/base_query.rb +3 -2
  25. data/lib/capybara/queries/current_path_query.rb +15 -5
  26. data/lib/capybara/queries/selector_query.rb +364 -54
  27. data/lib/capybara/queries/sibling_query.rb +8 -6
  28. data/lib/capybara/queries/style_query.rb +2 -2
  29. data/lib/capybara/queries/text_query.rb +13 -1
  30. data/lib/capybara/queries/title_query.rb +1 -1
  31. data/lib/capybara/rack_test/browser.rb +76 -11
  32. data/lib/capybara/rack_test/driver.rb +10 -5
  33. data/lib/capybara/rack_test/errors.rb +6 -0
  34. data/lib/capybara/rack_test/form.rb +31 -9
  35. data/lib/capybara/rack_test/node.rb +74 -23
  36. data/lib/capybara/registration_container.rb +41 -0
  37. data/lib/capybara/registrations/drivers.rb +42 -0
  38. data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
  39. data/lib/capybara/registrations/servers.rb +66 -0
  40. data/lib/capybara/result.rb +44 -20
  41. data/lib/capybara/rspec/matcher_proxies.rb +13 -11
  42. data/lib/capybara/rspec/matchers/base.rb +31 -16
  43. data/lib/capybara/rspec/matchers/compound.rb +1 -1
  44. data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
  45. data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
  46. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  47. data/lib/capybara/rspec/matchers/have_selector.rb +21 -21
  48. data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
  49. data/lib/capybara/rspec/matchers/have_text.rb +4 -4
  50. data/lib/capybara/rspec/matchers/have_title.rb +2 -2
  51. data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
  52. data/lib/capybara/rspec/matchers/match_style.rb +7 -2
  53. data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  54. data/lib/capybara/rspec/matchers.rb +111 -68
  55. data/lib/capybara/rspec.rb +2 -0
  56. data/lib/capybara/selector/builders/css_builder.rb +11 -7
  57. data/lib/capybara/selector/builders/xpath_builder.rb +5 -3
  58. data/lib/capybara/selector/css.rb +11 -9
  59. data/lib/capybara/selector/definition/button.rb +68 -0
  60. data/lib/capybara/selector/definition/checkbox.rb +26 -0
  61. data/lib/capybara/selector/definition/css.rb +10 -0
  62. data/lib/capybara/selector/definition/datalist_input.rb +35 -0
  63. data/lib/capybara/selector/definition/datalist_option.rb +25 -0
  64. data/lib/capybara/selector/definition/element.rb +28 -0
  65. data/lib/capybara/selector/definition/field.rb +40 -0
  66. data/lib/capybara/selector/definition/fieldset.rb +14 -0
  67. data/lib/capybara/selector/definition/file_field.rb +13 -0
  68. data/lib/capybara/selector/definition/fillable_field.rb +33 -0
  69. data/lib/capybara/selector/definition/frame.rb +17 -0
  70. data/lib/capybara/selector/definition/id.rb +6 -0
  71. data/lib/capybara/selector/definition/label.rb +62 -0
  72. data/lib/capybara/selector/definition/link.rb +55 -0
  73. data/lib/capybara/selector/definition/link_or_button.rb +16 -0
  74. data/lib/capybara/selector/definition/option.rb +27 -0
  75. data/lib/capybara/selector/definition/radio_button.rb +27 -0
  76. data/lib/capybara/selector/definition/select.rb +81 -0
  77. data/lib/capybara/selector/definition/table.rb +109 -0
  78. data/lib/capybara/selector/definition/table_row.rb +21 -0
  79. data/lib/capybara/selector/definition/xpath.rb +5 -0
  80. data/lib/capybara/selector/definition.rb +280 -0
  81. data/lib/capybara/selector/filter_set.rb +19 -18
  82. data/lib/capybara/selector/filters/base.rb +11 -2
  83. data/lib/capybara/selector/filters/locator_filter.rb +13 -3
  84. data/lib/capybara/selector/regexp_disassembler.rb +11 -7
  85. data/lib/capybara/selector/selector.rb +50 -440
  86. data/lib/capybara/selector/xpath_extensions.rb +17 -0
  87. data/lib/capybara/selector.rb +473 -482
  88. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
  89. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
  90. data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
  91. data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
  92. data/lib/capybara/selenium/driver.rb +174 -62
  93. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +74 -18
  94. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +128 -0
  95. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +37 -3
  96. data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +14 -1
  97. data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
  98. data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  99. data/lib/capybara/selenium/extensions/find.rb +68 -45
  100. data/lib/capybara/selenium/extensions/html5_drag.rb +192 -22
  101. data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  102. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  103. data/lib/capybara/selenium/node.rb +268 -72
  104. data/lib/capybara/selenium/nodes/chrome_node.rb +105 -9
  105. data/lib/capybara/selenium/nodes/edge_node.rb +110 -0
  106. data/lib/capybara/selenium/nodes/firefox_node.rb +51 -61
  107. data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
  108. data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
  109. data/lib/capybara/selenium/patches/atoms.rb +18 -0
  110. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  111. data/lib/capybara/selenium/patches/logs.rb +45 -0
  112. data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -1
  113. data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
  114. data/lib/capybara/server/animation_disabler.rb +43 -21
  115. data/lib/capybara/server/checker.rb +6 -2
  116. data/lib/capybara/server/middleware.rb +25 -13
  117. data/lib/capybara/server.rb +20 -4
  118. data/lib/capybara/session/config.rb +15 -11
  119. data/lib/capybara/session/matchers.rb +11 -11
  120. data/lib/capybara/session.rb +162 -131
  121. data/lib/capybara/spec/public/offset.js +6 -0
  122. data/lib/capybara/spec/public/test.js +105 -6
  123. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  124. data/lib/capybara/spec/session/active_element_spec.rb +31 -0
  125. data/lib/capybara/spec/session/all_spec.rb +89 -15
  126. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  127. data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
  128. data/lib/capybara/spec/session/assert_text_spec.rb +26 -22
  129. data/lib/capybara/spec/session/attach_file_spec.rb +64 -31
  130. data/lib/capybara/spec/session/check_spec.rb +26 -4
  131. data/lib/capybara/spec/session/choose_spec.rb +14 -2
  132. data/lib/capybara/spec/session/click_button_spec.rb +109 -61
  133. data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
  134. data/lib/capybara/spec/session/click_link_spec.rb +23 -1
  135. data/lib/capybara/spec/session/current_scope_spec.rb +1 -1
  136. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  137. data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
  138. data/lib/capybara/spec/session/evaluate_script_spec.rb +12 -0
  139. data/lib/capybara/spec/session/fill_in_spec.rb +46 -5
  140. data/lib/capybara/spec/session/find_link_spec.rb +10 -0
  141. data/lib/capybara/spec/session/find_spec.rb +80 -7
  142. data/lib/capybara/spec/session/first_spec.rb +2 -2
  143. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +14 -1
  144. data/lib/capybara/spec/session/frame/within_frame_spec.rb +14 -1
  145. data/lib/capybara/spec/session/has_all_selectors_spec.rb +5 -5
  146. data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
  147. data/lib/capybara/spec/session/has_any_selectors_spec.rb +6 -2
  148. data/lib/capybara/spec/session/has_button_spec.rb +81 -0
  149. data/lib/capybara/spec/session/has_css_spec.rb +45 -8
  150. data/lib/capybara/spec/session/has_current_path_spec.rb +22 -7
  151. data/lib/capybara/spec/session/has_element_spec.rb +47 -0
  152. data/lib/capybara/spec/session/has_field_spec.rb +59 -1
  153. data/lib/capybara/spec/session/has_link_spec.rb +40 -0
  154. data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
  155. data/lib/capybara/spec/session/has_select_spec.rb +42 -8
  156. data/lib/capybara/spec/session/has_selector_spec.rb +19 -4
  157. data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
  158. data/lib/capybara/spec/session/has_table_spec.rb +177 -0
  159. data/lib/capybara/spec/session/has_text_spec.rb +31 -3
  160. data/lib/capybara/spec/session/html_spec.rb +1 -1
  161. data/lib/capybara/spec/session/matches_style_spec.rb +6 -4
  162. data/lib/capybara/spec/session/node_spec.rb +697 -23
  163. data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
  164. data/lib/capybara/spec/session/refresh_spec.rb +2 -1
  165. data/lib/capybara/spec/session/reset_session_spec.rb +21 -7
  166. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  167. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  168. data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
  169. data/lib/capybara/spec/session/scroll_spec.rb +9 -7
  170. data/lib/capybara/spec/session/select_spec.rb +5 -10
  171. data/lib/capybara/spec/session/selectors_spec.rb +24 -3
  172. data/lib/capybara/spec/session/uncheck_spec.rb +3 -3
  173. data/lib/capybara/spec/session/unselect_spec.rb +1 -1
  174. data/lib/capybara/spec/session/visit_spec.rb +20 -0
  175. data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
  176. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
  177. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  178. data/lib/capybara/spec/session/window/window_spec.rb +54 -57
  179. data/lib/capybara/spec/session/window/windows_spec.rb +2 -2
  180. data/lib/capybara/spec/session/within_spec.rb +36 -0
  181. data/lib/capybara/spec/spec_helper.rb +30 -19
  182. data/lib/capybara/spec/test_app.rb +122 -34
  183. data/lib/capybara/spec/views/animated.erb +49 -0
  184. data/lib/capybara/spec/views/form.erb +86 -8
  185. data/lib/capybara/spec/views/frame_child.erb +3 -2
  186. data/lib/capybara/spec/views/frame_one.erb +2 -1
  187. data/lib/capybara/spec/views/frame_parent.erb +1 -1
  188. data/lib/capybara/spec/views/frame_two.erb +1 -1
  189. data/lib/capybara/spec/views/initial_alert.erb +2 -1
  190. data/lib/capybara/spec/views/layout.erb +10 -0
  191. data/lib/capybara/spec/views/obscured.erb +10 -10
  192. data/lib/capybara/spec/views/offset.erb +33 -0
  193. data/lib/capybara/spec/views/path.erb +2 -2
  194. data/lib/capybara/spec/views/popup_one.erb +1 -1
  195. data/lib/capybara/spec/views/popup_two.erb +1 -1
  196. data/lib/capybara/spec/views/react.erb +45 -0
  197. data/lib/capybara/spec/views/scroll.erb +2 -1
  198. data/lib/capybara/spec/views/spatial.erb +31 -0
  199. data/lib/capybara/spec/views/tables.erb +67 -0
  200. data/lib/capybara/spec/views/with_animation.erb +39 -4
  201. data/lib/capybara/spec/views/with_base_tag.erb +2 -2
  202. data/lib/capybara/spec/views/with_dragula.erb +24 -0
  203. data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
  204. data/lib/capybara/spec/views/with_hover.erb +3 -2
  205. data/lib/capybara/spec/views/with_hover1.erb +10 -0
  206. data/lib/capybara/spec/views/with_html.erb +34 -6
  207. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  208. data/lib/capybara/spec/views/with_js.erb +7 -4
  209. data/lib/capybara/spec/views/with_jstree.erb +26 -0
  210. data/lib/capybara/spec/views/with_namespace.erb +1 -0
  211. data/lib/capybara/spec/views/with_scope.erb +2 -2
  212. data/lib/capybara/spec/views/with_scope_other.erb +6 -0
  213. data/lib/capybara/spec/views/with_shadow.erb +31 -0
  214. data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
  215. data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
  216. data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
  217. data/lib/capybara/spec/views/with_windows.erb +1 -1
  218. data/lib/capybara/spec/views/within_frames.erb +1 -1
  219. data/lib/capybara/version.rb +1 -1
  220. data/lib/capybara/window.rb +14 -18
  221. data/lib/capybara.rb +91 -126
  222. data/spec/basic_node_spec.rb +30 -16
  223. data/spec/capybara_spec.rb +40 -28
  224. data/spec/counter_spec.rb +35 -0
  225. data/spec/css_builder_spec.rb +3 -1
  226. data/spec/css_splitter_spec.rb +1 -1
  227. data/spec/dsl_spec.rb +33 -22
  228. data/spec/filter_set_spec.rb +5 -5
  229. data/spec/fixtures/selenium_driver_rspec_failure.rb +3 -3
  230. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -3
  231. data/spec/minitest_spec.rb +24 -2
  232. data/spec/minitest_spec_spec.rb +60 -45
  233. data/spec/per_session_config_spec.rb +1 -1
  234. data/spec/rack_test_spec.rb +131 -98
  235. data/spec/regexp_dissassembler_spec.rb +53 -39
  236. data/spec/result_spec.rb +68 -66
  237. data/spec/rspec/features_spec.rb +9 -4
  238. data/spec/rspec/scenarios_spec.rb +6 -2
  239. data/spec/rspec/shared_spec_matchers.rb +137 -98
  240. data/spec/rspec_matchers_spec.rb +25 -0
  241. data/spec/rspec_spec.rb +23 -21
  242. data/spec/sauce_spec_chrome.rb +43 -0
  243. data/spec/selector_spec.rb +77 -21
  244. data/spec/selenium_spec_chrome.rb +141 -39
  245. data/spec/selenium_spec_chrome_remote.rb +32 -17
  246. data/spec/selenium_spec_edge.rb +36 -8
  247. data/spec/selenium_spec_firefox.rb +110 -68
  248. data/spec/selenium_spec_firefox_remote.rb +22 -15
  249. data/spec/selenium_spec_ie.rb +29 -22
  250. data/spec/selenium_spec_safari.rb +162 -0
  251. data/spec/server_spec.rb +153 -81
  252. data/spec/session_spec.rb +11 -4
  253. data/spec/shared_selenium_node.rb +79 -0
  254. data/spec/shared_selenium_session.rb +179 -74
  255. data/spec/spec_helper.rb +80 -5
  256. data/spec/whitespace_normalizer_spec.rb +54 -0
  257. data/spec/xpath_builder_spec.rb +3 -1
  258. metadata +218 -30
  259. data/lib/capybara/spec/session/source_spec.rb +0 -0
  260. data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -0,0 +1,6 @@
1
+ $(function() {
2
+ $(document).on('click dblclick contextmenu', function(e){
3
+ e.preventDefault();
4
+ $(document.body).append('<div id="has-been-clicked">Has been clicked at ' + e.clientX + ',' + e.clientY + '</div>');
5
+ })
6
+ })
@@ -1,23 +1,99 @@
1
1
  var activeRequests = 0;
2
2
  $(function() {
3
3
  $('#change').text('I changed it');
4
- $('#drag, #drag_scroll, #drag_link').draggable();
4
+ $('#drag, #drag_scroll, #drag_link').draggable({
5
+ start: function(event, ui){
6
+ $(document.body).append(
7
+ "<div class='drag_start'>Dragged!" +
8
+ (event.altKey ? "-alt" : "") +
9
+ (event.ctrlKey ? "-ctrl" : "") +
10
+ (event.metaKey ? "-meta" : "") +
11
+ (event.shiftKey ? "-shift" : "") +
12
+ "</div>"
13
+ );
14
+ }
15
+ });
5
16
  $('#drop, #drop_scroll').droppable({
6
17
  tolerance: 'touch',
7
18
  drop: function(event, ui) {
8
19
  ui.draggable.remove();
9
- $(this).html('Dropped!');
20
+ $(this).html(
21
+ "Dropped!" +
22
+ (event.altKey ? "-alt" : "") +
23
+ (event.ctrlKey ? "-ctrl" : "") +
24
+ (event.metaKey ? "-meta" : "") +
25
+ (event.shiftKey ? "-shift" : "")
26
+ );
10
27
  }
11
28
  });
12
29
  $('#drag_html5, #drag_html5_scroll').on('dragstart', function(ev){
30
+ $(document.body).append(
31
+ "<div class='drag_start'>HTML5 Dragged!" +
32
+ (event.altKey ? "-alt" : "") +
33
+ (event.ctrlKey ? "-ctrl" : "") +
34
+ (event.metaKey ? "-meta" : "") +
35
+ (event.shiftKey ? "-shift" : "") +
36
+ "</div>"
37
+ );
13
38
  ev.originalEvent.dataTransfer.setData("text", ev.target.id);
14
39
  });
40
+ $('#drag_html5, #drag_html5_scroll').on('dragend', function(ev){
41
+ $(this).after('<div class="log">DragEnd with client position: ' + ev.clientX + ',' + ev.clientY)
42
+ });
15
43
  $('#drop_html5, #drop_html5_scroll').on('dragover', function(ev){
44
+ $(this).after('<div class="log">DragOver with client position: ' + ev.clientX + ',' + ev.clientY)
45
+ if ($(this).hasClass('drop')) { ev.preventDefault(); }
46
+ });
47
+ $('#drop_html5, #drop_html5_scroll').on('dragenter', function(ev){
48
+ $(this).after('<div class="log">DragEnter')
49
+ if ($(this).hasClass('drop')) { ev.preventDefault(); }
50
+ });
51
+ $('#drop_html5, #drop_html5_scroll').on('dragleave', function(ev){
52
+ $(this).after('<div class="log">DragLeave with client position: ' + ev.clientX + ',' + ev.clientY)
53
+ if ($(this).hasClass('drop')) { ev.preventDefault(); }
54
+ });
55
+ $('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
56
+ $(this).after('<div class="log">Drop with client position: ' + ev.clientX + ',' + ev.clientY)
16
57
  if ($(this).hasClass('drop')) { ev.preventDefault(); }
17
58
  });
18
59
  $('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
19
60
  ev.preventDefault();
20
- $(this).html('HTML5 Dropped ' + ev.originalEvent.dataTransfer.getData("text"));
61
+ var oev = ev.originalEvent;
62
+ if (oev.dataTransfer.items) {
63
+ for (var i = 0; i < oev.dataTransfer.items.length; i++){
64
+ var item = oev.dataTransfer.items[i];
65
+ if (item.kind === 'file'){
66
+ var file = item.getAsFile();
67
+ $(this).append('HTML5 Dropped file: ' + file.name);
68
+ } else {
69
+ var _this = this;
70
+ var callback = (function(type) {
71
+ return function(s) {
72
+ $(_this).append(
73
+ "HTML5 Dropped string: " +
74
+ type +
75
+ " " +
76
+ s +
77
+ (ev.altKey ? "-alt" : "") +
78
+ (ev.ctrlKey ? "-ctrl" : "") +
79
+ (ev.metaKey ? "-meta" : "") +
80
+ (ev.shiftKey ? "-shift" : "")
81
+ );
82
+ };
83
+ })(item.type);
84
+ item.getAsString(callback);
85
+ }
86
+ }
87
+ } else {
88
+ $(this).html('HTML5 Dropped ' + oev.dataTransfer.getData("text"));
89
+ for (var i = 0; i < oev.dataTransfer.files.length; i++) {
90
+ $(this).append('HTML5 Dropped file: ' + oev.dataTransfer.files[i].name);
91
+ }
92
+ for (var i = 0; i < oev.dataTransfer.types.length; i++) {
93
+ var type = oev.dataTransfer.types[i];
94
+ $(this).append('HTML5 Dropped string: ' + type + ' ' + oev.dataTransfer.getData(type));
95
+ }
96
+ }
21
97
  });
22
98
  $('#clickable').click(function(e) {
23
99
  var link = $(this);
@@ -36,6 +112,13 @@ $(function() {
36
112
  }, 4000);
37
113
  return false;
38
114
  });
115
+ $('#aria-button').click(function() {
116
+ var span = $(this);
117
+ setTimeout(function() {
118
+ $(span).after('<span role="button">ARIA button has been clicked</span>')
119
+ }, 1000);
120
+ return false;
121
+ });
39
122
  $('#waiter').change(function() {
40
123
  activeRequests = 1;
41
124
  setTimeout(function() {
@@ -81,6 +164,7 @@ $(function() {
81
164
  });
82
165
  $('#click-test').on({
83
166
  click: function(e) {
167
+ window.click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
84
168
  var desc = "";
85
169
  if (e.altKey) desc += 'alt ';
86
170
  if (e.ctrlKey) desc += 'control ';
@@ -107,6 +191,16 @@ $(function() {
107
191
  if (e.shiftKey) desc += 'shift ';
108
192
  var pos = this.getBoundingClientRect();
109
193
  $(this).after('<a id="has-been-right-clicked" href="#">Has been ' + desc + 'right clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
194
+ },
195
+ mousedown: function(e) {
196
+ window.click_delay = undefined;
197
+ window.right_click_delay = undefined;
198
+ window.mouse_down_time = new Date().getTime();
199
+ },
200
+ mouseup: function(e) {
201
+ if (e.button == 2){
202
+ window.right_click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
203
+ }
110
204
  }
111
205
  });
112
206
  $('#open-alert').click(function() {
@@ -179,7 +273,12 @@ $(function() {
179
273
  sessionStorage.setItem('session', 'session_value');
180
274
  localStorage.setItem('local', 'local value');
181
275
  });
182
- $('#multiple-file').change(function(e){
183
- $('body').append($('<p class="file_change"input_event_triggered">File input changed</p>'));
184
- })
276
+ $('#multiple-file, #hidden_file').change(function(e){
277
+ $('body').append($('<p class="file_change">File input changed</p>'));
278
+ });
279
+
280
+ var shadow = document.querySelector('#shadow').attachShadow({mode: 'open'});
281
+ var span = document.createElement('span');
282
+ span.textContent = 'The things we do in the shadows';
283
+ shadow.appendChild(span);
185
284
  });
@@ -53,7 +53,7 @@ Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
53
53
  @session.click_link('Alert page change')
54
54
  sleep 1 # ensure page change occurs before the accept_alert block exits
55
55
  end
56
- expect(@session).to have_current_path('/with_html')
56
+ expect(@session).to have_current_path('/with_html', wait: 5)
57
57
  end
58
58
 
59
59
  context 'with an asynchronous alert' do
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ Capybara::SpecHelper.spec '#active_element', requires: [:active_element] do
4
+ it 'should return the active element' do
5
+ @session.visit('/form')
6
+ @session.send_keys(:tab)
7
+
8
+ expect(@session.active_element).to match_selector(:css, '[tabindex="1"]')
9
+
10
+ @session.send_keys(:tab)
11
+
12
+ expect(@session.active_element).to match_selector(:css, '[tabindex="2"]')
13
+ end
14
+
15
+ it 'should support reloading' do
16
+ @session.visit('/form')
17
+ expect(@session.active_element).to match_selector(:css, 'body')
18
+ @session.execute_script <<-JS
19
+ window.setTimeout(() => {
20
+ document.querySelector('#form_title').focus();
21
+ }, 1000)
22
+ JS
23
+ expect(@session.active_element).to match_selector(:css, 'body', wait: false)
24
+ expect(@session.active_element).to match_selector(:css, '#form_title', wait: 2)
25
+ end
26
+
27
+ it 'should return a Capybara::Element' do
28
+ @session.visit('/form')
29
+ expect(@session.active_element).to be_a Capybara::Node::Element
30
+ end
31
+ end
@@ -30,16 +30,56 @@ Capybara::SpecHelper.spec '#all' do
30
30
 
31
31
  it 'should accept an XPath instance', :exact_false do
32
32
  @session.visit('/form')
33
- @xpath = Capybara::Selector[:fillable_field].call('Name')
34
- expect(@xpath).to be_a(::XPath::Union)
33
+ @xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('Name')
34
+ expect(@xpath).to be_a(XPath::Union)
35
35
  @result = @session.all(@xpath).map(&:value)
36
36
  expect(@result).to include('Smith', 'John', 'John Smith')
37
37
  end
38
38
 
39
+ it 'should allow reversing the order' do
40
+ @session.visit('/form')
41
+ fields = @session.all(:fillable_field, 'Name', exact: false).to_a
42
+ reverse_fields = @session.all(:fillable_field, 'Name', order: :reverse, exact: false).to_a
43
+ expect(fields).to eq(reverse_fields.reverse)
44
+ end
45
+
39
46
  it 'should raise an error when given invalid options' do
40
47
  expect { @session.all('//p', schmoo: 'foo') }.to raise_error(ArgumentError)
41
48
  end
42
49
 
50
+ it 'should not reload by default', requires: [:driver] do
51
+ paras = @session.all(:css, 'p', minimum: 3)
52
+ expect { paras[0].text }.not_to raise_error
53
+ @session.refresh
54
+ expect { paras[0].text }.to raise_error do |err|
55
+ expect(err).to be_an_invalid_element_error(@session)
56
+ end
57
+ end
58
+
59
+ context 'with allow_reload' do
60
+ it 'should reload if true' do
61
+ paras = @session.all(:css, 'p', allow_reload: true, minimum: 3)
62
+ expect { paras[0].text }.not_to raise_error
63
+ @session.refresh
64
+ sleep 1 # Ensure page has started to reload
65
+ expect(paras[0]).to have_text('Lorem ipsum dolor')
66
+ expect(paras[1]).to have_text('Duis aute irure dolor')
67
+ end
68
+
69
+ it 'should not reload if false', requires: [:driver] do
70
+ paras = @session.all(:css, 'p', allow_reload: false, minimum: 3)
71
+ expect { paras[0].text }.not_to raise_error
72
+ @session.refresh
73
+ sleep 1 # Ensure page has started to reload
74
+ expect { paras[0].text }.to raise_error do |err|
75
+ expect(err).to be_an_invalid_element_error(@session)
76
+ end
77
+ expect { paras[2].text }.to raise_error do |err|
78
+ expect(err).to be_an_invalid_element_error(@session)
79
+ end
80
+ end
81
+ end
82
+
43
83
  context 'with css selectors' do
44
84
  it 'should find all elements using the given selector' do
45
85
  expect(@session.all(:css, 'h1').first.text).to eq('This is a test')
@@ -89,10 +129,10 @@ Capybara::SpecHelper.spec '#all' do
89
129
  end
90
130
 
91
131
  context 'with per session config', requires: [:psc] do
92
- it 'should use the sessions ignore_hidden_elements', psc: true do
132
+ it 'should use the sessions ignore_hidden_elements', :psc do
93
133
  Capybara.ignore_hidden_elements = true
94
134
  @session.config.ignore_hidden_elements = false
95
- expect(Capybara.ignore_hidden_elements).to eq(true)
135
+ expect(Capybara.ignore_hidden_elements).to be(true)
96
136
  expect(@session.all(:css, 'a.simple').size).to eq(2)
97
137
  @session.config.ignore_hidden_elements = true
98
138
  expect(@session.all(:css, 'a.simple').size).to eq(1)
@@ -100,11 +140,35 @@ Capybara::SpecHelper.spec '#all' do
100
140
  end
101
141
  end
102
142
 
143
+ context 'with obscured filter', requires: [:css] do
144
+ it 'should only find nodes on top in the viewport when false' do
145
+ expect(@session.all(:css, 'a.simple', obscured: false).size).to eq(1)
146
+ end
147
+
148
+ it 'should not find nodes on top outside the viewport when false' do
149
+ expect(@session.all(:link, 'Download Me', obscured: false).size).to eq(0)
150
+ @session.scroll_to(@session.find_link('Download Me'))
151
+ expect(@session.all(:link, 'Download Me', obscured: false).size).to eq(1)
152
+ end
153
+
154
+ it 'should find top nodes outside the viewport when true' do
155
+ expect(@session.all(:link, 'Download Me', obscured: true).size).to eq(1)
156
+ @session.scroll_to(@session.find_link('Download Me'))
157
+ expect(@session.all(:link, 'Download Me', obscured: true).size).to eq(0)
158
+ end
159
+
160
+ it 'should only find non-top nodes when true' do
161
+ # Also need visible: false so visibility is ignored
162
+ expect(@session.all(:css, 'a.simple', visible: false, obscured: true).size).to eq(1)
163
+ end
164
+ end
165
+
103
166
  context 'with element count filters' do
104
167
  context ':count' do
105
168
  it 'should succeed when the number of elements founds matches the expectation' do
106
169
  expect { @session.all(:css, 'h1, p', count: 4) }.not_to raise_error
107
170
  end
171
+
108
172
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
109
173
  expect { @session.all(:css, 'h1, p', count: 5) }.to raise_error(Capybara::ExpectationNotMet)
110
174
  end
@@ -114,6 +178,7 @@ Capybara::SpecHelper.spec '#all' do
114
178
  it 'should succeed when the number of elements founds matches the expectation' do
115
179
  expect { @session.all(:css, 'h1, p', minimum: 0) }.not_to raise_error
116
180
  end
181
+
117
182
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
118
183
  expect { @session.all(:css, 'h1, p', minimum: 5) }.to raise_error(Capybara::ExpectationNotMet)
119
184
  end
@@ -123,6 +188,7 @@ Capybara::SpecHelper.spec '#all' do
123
188
  it 'should succeed when the number of elements founds matches the expectation' do
124
189
  expect { @session.all(:css, 'h1, p', maximum: 4) }.not_to raise_error
125
190
  end
191
+
126
192
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
127
193
  expect { @session.all(:css, 'h1, p', maximum: 0) }.to raise_error(Capybara::ExpectationNotMet)
128
194
  end
@@ -132,16 +198,20 @@ Capybara::SpecHelper.spec '#all' do
132
198
  it 'should succeed when the number of elements founds matches the expectation' do
133
199
  expect { @session.all(:css, 'h1, p', between: 2..7) }.not_to raise_error
134
200
  end
201
+
135
202
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
136
203
  expect { @session.all(:css, 'h1, p', between: 0..3) }.to raise_error(Capybara::ExpectationNotMet)
137
204
  end
138
205
 
139
- eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.5
140
- it'treats an endless range as minimum' do
141
- expect { @session.all(:css, 'h1, p', between: 2..) }.not_to raise_error
142
- expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
143
- end
144
- TEST
206
+ it 'treats an endless range as minimum' do
207
+ expect { @session.all(:css, 'h1, p', between: 2..) }.not_to raise_error
208
+ expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
209
+ end
210
+
211
+ it 'treats a beginless range as maximum' do
212
+ expect { @session.all(:css, 'h1, p', between: ..7) }.not_to raise_error
213
+ expect { @session.all(:css, 'h1, p', between: ..3) }.to raise_error(Capybara::ExpectationNotMet)
214
+ end
145
215
  end
146
216
 
147
217
  context 'with multiple count filters' do
@@ -150,32 +220,36 @@ Capybara::SpecHelper.spec '#all' do
150
220
  minimum: 5,
151
221
  maximum: 0,
152
222
  between: 0..3 }
153
- expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
223
+ expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
154
224
  end
225
+
155
226
  context 'with no :count expectation' do
156
227
  it 'fails if :minimum is not met' do
157
228
  o = { minimum: 5,
158
229
  maximum: 4,
159
230
  between: 2..7 }
160
- expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
231
+ expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
161
232
  end
233
+
162
234
  it 'fails if :maximum is not met' do
163
235
  o = { minimum: 0,
164
236
  maximum: 0,
165
237
  between: 2..7 }
166
- expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
238
+ expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
167
239
  end
240
+
168
241
  it 'fails if :between is not met' do
169
242
  o = { minimum: 0,
170
243
  maximum: 4,
171
244
  between: 0..3 }
172
- expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
245
+ expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
173
246
  end
247
+
174
248
  it 'succeeds if all combineable expectations are met' do
175
249
  o = { minimum: 0,
176
250
  maximum: 4,
177
251
  between: 2..7 }
178
- expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
252
+ expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
179
253
  end
180
254
  end
181
255
  end
@@ -20,6 +20,11 @@ Capybara::SpecHelper.spec '#ancestor' do
20
20
  expect(el.ancestor('//div', text: "Ancestor\nAncestor\nAncestor")[:id]).to eq('ancestor3')
21
21
  end
22
22
 
23
+ it 'should find the closest ancestor' do
24
+ el = @session.find(:css, '#child')
25
+ expect(el.ancestor('.//div', order: :reverse, match: :first)[:id]).to eq('ancestor1')
26
+ end
27
+
23
28
  it 'should raise an error if there are multiple matches' do
24
29
  el = @session.find(:css, '#child')
25
30
  expect { el.ancestor('//div') }.to raise_error(Capybara::Ambiguous)
@@ -37,7 +37,9 @@ Capybara::SpecHelper.spec '#assert_current_path' do
37
37
  end
38
38
 
39
39
  it 'should not cause an exception when current_url is nil' do
40
- allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil)
40
+ allow(@session).to receive(:current_url).and_return(nil)
41
+ allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page
42
+
41
43
  expect { @session.assert_current_path(nil) }.not_to raise_error
42
44
  end
43
45
  end
@@ -65,7 +67,8 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do
65
67
  end
66
68
 
67
69
  it 'should not cause an exception when current_url is nil' do
68
- allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil)
70
+ allow(@session).to receive(:current_url).and_return(nil)
71
+ allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page
69
72
 
70
73
  expect { @session.assert_no_current_path('/with_html') }.not_to raise_error
71
74
  end
@@ -3,16 +3,16 @@
3
3
  Capybara::SpecHelper.spec '#assert_text' do
4
4
  it 'should be true if the given text is on the page' do
5
5
  @session.visit('/with_html')
6
- expect(@session.assert_text('est')).to eq(true)
7
- expect(@session.assert_text('Lorem')).to eq(true)
8
- expect(@session.assert_text('Redirect')).to eq(true)
9
- expect(@session.assert_text(:Redirect)).to eq(true)
10
- expect(@session.assert_text('text with whitespace')).to eq(true)
6
+ expect(@session.assert_text('est')).to be(true)
7
+ expect(@session.assert_text('Lorem')).to be(true)
8
+ expect(@session.assert_text('Redirect')).to be(true)
9
+ expect(@session.assert_text(:Redirect)).to be(true)
10
+ expect(@session.assert_text('text with whitespace')).to be(true)
11
11
  end
12
12
 
13
13
  it 'should support collapsing whitespace' do
14
14
  @session.visit('/with_html')
15
- expect(@session.assert_text('text with whitespace', normalize_ws: true)).to eq(true)
15
+ expect(@session.assert_text('text with whitespace', normalize_ws: true)).to be(true)
16
16
  end
17
17
 
18
18
  context 'with enabled default collapsing whitespace' do
@@ -20,19 +20,19 @@ Capybara::SpecHelper.spec '#assert_text' do
20
20
 
21
21
  it 'should be true if the given unnormalized text is on the page' do
22
22
  @session.visit('/with_html')
23
- expect(@session.assert_text('text with whitespace', normalize_ws: false)).to eq(true)
23
+ expect(@session.assert_text('text with whitespace', normalize_ws: false)).to be(true)
24
24
  end
25
25
 
26
26
  it 'should support collapsing whitespace' do
27
27
  @session.visit('/with_html')
28
- expect(@session.assert_text('text with whitespace')).to eq(true)
28
+ expect(@session.assert_text('text with whitespace')).to be(true)
29
29
  end
30
30
  end
31
31
 
32
32
  it 'should take scopes into account' do
33
33
  @session.visit('/with_html')
34
34
  @session.within("//a[@title='awesome title']") do
35
- expect(@session.assert_text('labore')).to eq(true)
35
+ expect(@session.assert_text('labore')).to be(true)
36
36
  end
37
37
  end
38
38
 
@@ -47,13 +47,13 @@ Capybara::SpecHelper.spec '#assert_text' do
47
47
 
48
48
  it 'should be true if :all given and text is invisible.' do
49
49
  @session.visit('/with_html')
50
- expect(@session.assert_text(:all, 'Some of this text is hidden!')).to eq(true)
50
+ expect(@session.assert_text(:all, 'Some of this text is hidden!')).to be(true)
51
51
  end
52
52
 
53
53
  it 'should be true if `Capybara.ignore_hidden_elements = true` and text is invisible.' do
54
54
  Capybara.ignore_hidden_elements = false
55
55
  @session.visit('/with_html')
56
- expect(@session.assert_text('Some of this text is hidden!')).to eq(true)
56
+ expect(@session.assert_text('Some of this text is hidden!')).to be(true)
57
57
  end
58
58
 
59
59
  it 'should raise error with a helpful message if the requested text is present but invisible' do
@@ -88,7 +88,7 @@ Capybara::SpecHelper.spec '#assert_text' do
88
88
 
89
89
  it 'should be true if the text in the page matches given regexp' do
90
90
  @session.visit('/with_html')
91
- expect(@session.assert_text(/Lorem/)).to eq(true)
91
+ expect(@session.assert_text(/Lorem/)).to be(true)
92
92
  end
93
93
 
94
94
  it "should raise error if the text in the page doesn't match given regexp" do
@@ -109,13 +109,13 @@ Capybara::SpecHelper.spec '#assert_text' do
109
109
  Capybara.default_max_wait_time = 2
110
110
  @session.visit('/with_js')
111
111
  @session.click_link('Click me')
112
- expect(@session.assert_text('Has been clicked')).to eq(true)
112
+ expect(@session.assert_text('Has been clicked')).to be(true)
113
113
  end
114
114
 
115
115
  context 'with between' do
116
116
  it 'should be true if the text occurs within the range given' do
117
117
  @session.visit('/with_count')
118
- expect(@session.assert_text('count', between: 1..3)).to eq(true)
118
+ expect(@session.assert_text('count', between: 1..3)).to be(true)
119
119
  end
120
120
 
121
121
  it 'should be false if the text occurs more or fewer times than range' do
@@ -157,32 +157,36 @@ Capybara::SpecHelper.spec '#assert_text' do
157
157
  minimum: 6,
158
158
  maximum: 0,
159
159
  between: 0..4 }
160
- expect { @session.assert_text('Header', o) }.not_to raise_error
160
+ expect { @session.assert_text('Header', **o) }.not_to raise_error
161
161
  end
162
+
162
163
  context 'with no :count expectation' do
163
164
  it 'fails if :minimum is not met' do
164
165
  o = { minimum: 6,
165
166
  maximum: 5,
166
167
  between: 2..7 }
167
- expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
168
+ expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
168
169
  end
170
+
169
171
  it 'fails if :maximum is not met' do
170
172
  o = { minimum: 0,
171
173
  maximum: 0,
172
174
  between: 2..7 }
173
- expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
175
+ expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
174
176
  end
177
+
175
178
  it 'fails if :between is not met' do
176
179
  o = { minimum: 0,
177
180
  maximum: 5,
178
181
  between: 0..4 }
179
- expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
182
+ expect { @session.assert_text('Header', **o) }.to raise_error(Capybara::ExpectationNotMet)
180
183
  end
184
+
181
185
  it 'succeeds if all combineable expectations are met' do
182
186
  o = { minimum: 0,
183
187
  maximum: 5,
184
188
  between: 2..7 }
185
- expect { @session.assert_text('Header', o) }.not_to raise_error
189
+ expect { @session.assert_text('Header', **o) }.not_to raise_error
186
190
  end
187
191
  end
188
192
  end
@@ -199,13 +203,13 @@ Capybara::SpecHelper.spec '#assert_no_text' do
199
203
  it 'should be true if scoped to an element which does not have the text' do
200
204
  @session.visit('/with_html')
201
205
  @session.within("//a[@title='awesome title']") do
202
- expect(@session.assert_no_text('monkey')).to eq(true)
206
+ expect(@session.assert_no_text('monkey')).to be(true)
203
207
  end
204
208
  end
205
209
 
206
210
  it 'should be true if the given text is on the page but not visible' do
207
211
  @session.visit('/with_html')
208
- expect(@session.assert_no_text('Inside element with hidden ancestor')).to eq(true)
212
+ expect(@session.assert_no_text('Inside element with hidden ancestor')).to be(true)
209
213
  end
210
214
 
211
215
  it 'should raise error if :all given and text is invisible.' do
@@ -232,7 +236,7 @@ Capybara::SpecHelper.spec '#assert_no_text' do
232
236
  context 'with count' do
233
237
  it 'should be true if the text occurs within the range given' do
234
238
  @session.visit('/with_count')
235
- expect(@session.assert_text('count', count: 2)).to eq(true)
239
+ expect(@session.assert_text('count', count: 2)).to be(true)
236
240
  end
237
241
 
238
242
  it 'should be false if the text occurs more or fewer times than range' do