capybara 3.16.1 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/History.md +321 -0
  4. data/README.md +51 -60
  5. data/lib/capybara.rb +71 -114
  6. data/lib/capybara/config.rb +8 -5
  7. data/lib/capybara/cucumber.rb +1 -1
  8. data/lib/capybara/driver/node.rb +15 -3
  9. data/lib/capybara/dsl.rb +10 -2
  10. data/lib/capybara/helpers.rb +5 -3
  11. data/lib/capybara/minitest.rb +242 -141
  12. data/lib/capybara/minitest/spec.rb +159 -90
  13. data/lib/capybara/node/actions.rb +85 -74
  14. data/lib/capybara/node/base.rb +4 -4
  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 +216 -117
  18. data/lib/capybara/node/finders.rb +65 -65
  19. data/lib/capybara/node/matchers.rb +228 -126
  20. data/lib/capybara/node/simple.rb +9 -4
  21. data/lib/capybara/queries/ancestor_query.rb +5 -7
  22. data/lib/capybara/queries/base_query.rb +2 -1
  23. data/lib/capybara/queries/current_path_query.rb +1 -1
  24. data/lib/capybara/queries/selector_query.rb +296 -30
  25. data/lib/capybara/queries/sibling_query.rb +5 -4
  26. data/lib/capybara/queries/style_query.rb +2 -2
  27. data/lib/capybara/queries/text_query.rb +13 -1
  28. data/lib/capybara/queries/title_query.rb +1 -1
  29. data/lib/capybara/rack_test/browser.rb +7 -2
  30. data/lib/capybara/rack_test/driver.rb +1 -1
  31. data/lib/capybara/rack_test/form.rb +1 -1
  32. data/lib/capybara/rack_test/node.rb +43 -7
  33. data/lib/capybara/registration_container.rb +44 -0
  34. data/lib/capybara/registrations/drivers.rb +36 -0
  35. data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
  36. data/lib/capybara/registrations/servers.rb +44 -0
  37. data/lib/capybara/result.rb +36 -8
  38. data/lib/capybara/rspec/matcher_proxies.rb +6 -4
  39. data/lib/capybara/rspec/matchers.rb +100 -63
  40. data/lib/capybara/rspec/matchers/base.rb +23 -10
  41. data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
  42. data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
  43. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  44. data/lib/capybara/rspec/matchers/have_selector.rb +16 -8
  45. data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
  46. data/lib/capybara/rspec/matchers/have_text.rb +4 -4
  47. data/lib/capybara/rspec/matchers/have_title.rb +2 -2
  48. data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
  49. data/lib/capybara/rspec/matchers/match_style.rb +2 -2
  50. data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  51. data/lib/capybara/selector.rb +219 -588
  52. data/lib/capybara/selector/builders/css_builder.rb +10 -6
  53. data/lib/capybara/selector/builders/xpath_builder.rb +1 -1
  54. data/lib/capybara/selector/css.rb +4 -2
  55. data/lib/capybara/selector/definition.rb +277 -0
  56. data/lib/capybara/selector/definition/button.rb +52 -0
  57. data/lib/capybara/selector/definition/checkbox.rb +26 -0
  58. data/lib/capybara/selector/definition/css.rb +10 -0
  59. data/lib/capybara/selector/definition/datalist_input.rb +35 -0
  60. data/lib/capybara/selector/definition/datalist_option.rb +25 -0
  61. data/lib/capybara/selector/definition/element.rb +27 -0
  62. data/lib/capybara/selector/definition/field.rb +40 -0
  63. data/lib/capybara/selector/definition/fieldset.rb +14 -0
  64. data/lib/capybara/selector/definition/file_field.rb +13 -0
  65. data/lib/capybara/selector/definition/fillable_field.rb +33 -0
  66. data/lib/capybara/selector/definition/frame.rb +17 -0
  67. data/lib/capybara/selector/definition/id.rb +6 -0
  68. data/lib/capybara/selector/definition/label.rb +62 -0
  69. data/lib/capybara/selector/definition/link.rb +54 -0
  70. data/lib/capybara/selector/definition/link_or_button.rb +16 -0
  71. data/lib/capybara/selector/definition/option.rb +27 -0
  72. data/lib/capybara/selector/definition/radio_button.rb +27 -0
  73. data/lib/capybara/selector/definition/select.rb +81 -0
  74. data/lib/capybara/selector/definition/table.rb +109 -0
  75. data/lib/capybara/selector/definition/table_row.rb +21 -0
  76. data/lib/capybara/selector/definition/xpath.rb +5 -0
  77. data/lib/capybara/selector/filter_set.rb +13 -9
  78. data/lib/capybara/selector/filters/base.rb +11 -2
  79. data/lib/capybara/selector/filters/locator_filter.rb +13 -3
  80. data/lib/capybara/selector/regexp_disassembler.rb +9 -2
  81. data/lib/capybara/selector/selector.rb +43 -448
  82. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
  83. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
  84. data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
  85. data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
  86. data/lib/capybara/selenium/driver.rb +125 -56
  87. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +73 -17
  88. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
  89. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +41 -2
  90. data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +14 -1
  91. data/lib/capybara/selenium/driver_specializations/safari_driver.rb +14 -5
  92. data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  93. data/lib/capybara/selenium/extensions/find.rb +67 -45
  94. data/lib/capybara/selenium/extensions/html5_drag.rb +152 -36
  95. data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  96. data/lib/capybara/selenium/logger_suppressor.rb +34 -0
  97. data/lib/capybara/selenium/node.rb +227 -56
  98. data/lib/capybara/selenium/nodes/chrome_node.rb +93 -8
  99. data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
  100. data/lib/capybara/selenium/nodes/firefox_node.rb +37 -59
  101. data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
  102. data/lib/capybara/selenium/nodes/safari_node.rb +27 -54
  103. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  104. data/lib/capybara/selenium/patches/atoms.rb +18 -0
  105. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  106. data/lib/capybara/selenium/patches/logs.rb +45 -0
  107. data/lib/capybara/server.rb +19 -3
  108. data/lib/capybara/server/animation_disabler.rb +2 -2
  109. data/lib/capybara/server/checker.rb +6 -2
  110. data/lib/capybara/server/middleware.rb +23 -13
  111. data/lib/capybara/session.rb +124 -106
  112. data/lib/capybara/session/config.rb +12 -10
  113. data/lib/capybara/session/matchers.rb +6 -6
  114. data/lib/capybara/spec/public/offset.js +6 -0
  115. data/lib/capybara/spec/public/test.js +94 -5
  116. data/lib/capybara/spec/session/all_spec.rb +84 -6
  117. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  118. data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
  119. data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
  120. data/lib/capybara/spec/session/attach_file_spec.rb +14 -6
  121. data/lib/capybara/spec/session/check_spec.rb +10 -4
  122. data/lib/capybara/spec/session/choose_spec.rb +8 -2
  123. data/lib/capybara/spec/session/click_button_spec.rb +44 -1
  124. data/lib/capybara/spec/session/click_link_spec.rb +11 -0
  125. data/lib/capybara/spec/session/evaluate_script_spec.rb +12 -0
  126. data/lib/capybara/spec/session/fill_in_spec.rb +37 -2
  127. data/lib/capybara/spec/session/find_spec.rb +60 -6
  128. data/lib/capybara/spec/session/first_spec.rb +1 -1
  129. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +14 -1
  130. data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
  131. data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
  132. data/lib/capybara/spec/session/has_button_spec.rb +16 -0
  133. data/lib/capybara/spec/session/has_css_spec.rb +35 -6
  134. data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
  135. data/lib/capybara/spec/session/has_field_spec.rb +34 -0
  136. data/lib/capybara/spec/session/has_select_spec.rb +32 -4
  137. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  138. data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
  139. data/lib/capybara/spec/session/has_table_spec.rb +51 -5
  140. data/lib/capybara/spec/session/has_text_spec.rb +47 -0
  141. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  142. data/lib/capybara/spec/session/node_spec.rb +574 -16
  143. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  144. data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
  145. data/lib/capybara/spec/session/scroll_spec.rb +1 -1
  146. data/lib/capybara/spec/session/select_spec.rb +5 -10
  147. data/lib/capybara/spec/session/selectors_spec.rb +24 -3
  148. data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
  149. data/lib/capybara/spec/session/unselect_spec.rb +1 -1
  150. data/lib/capybara/spec/session/window/window_spec.rb +10 -9
  151. data/lib/capybara/spec/spec_helper.rb +7 -2
  152. data/lib/capybara/spec/test_app.rb +26 -21
  153. data/lib/capybara/spec/views/animated.erb +49 -0
  154. data/lib/capybara/spec/views/form.erb +25 -4
  155. data/lib/capybara/spec/views/frame_child.erb +2 -1
  156. data/lib/capybara/spec/views/frame_one.erb +1 -0
  157. data/lib/capybara/spec/views/obscured.erb +9 -9
  158. data/lib/capybara/spec/views/offset.erb +32 -0
  159. data/lib/capybara/spec/views/react.erb +45 -0
  160. data/lib/capybara/spec/views/spatial.erb +31 -0
  161. data/lib/capybara/spec/views/with_animation.erb +29 -1
  162. data/lib/capybara/spec/views/with_dragula.erb +24 -0
  163. data/lib/capybara/spec/views/with_html.erb +28 -2
  164. data/lib/capybara/spec/views/with_js.erb +2 -1
  165. data/lib/capybara/spec/views/with_jstree.erb +26 -0
  166. data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
  167. data/lib/capybara/version.rb +1 -1
  168. data/lib/capybara/window.rb +10 -10
  169. data/spec/basic_node_spec.rb +6 -6
  170. data/spec/capybara_spec.rb +28 -28
  171. data/spec/dsl_spec.rb +16 -3
  172. data/spec/filter_set_spec.rb +5 -5
  173. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  174. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  175. data/spec/minitest_spec.rb +12 -2
  176. data/spec/minitest_spec_spec.rb +56 -45
  177. data/spec/rack_test_spec.rb +25 -12
  178. data/spec/regexp_dissassembler_spec.rb +53 -39
  179. data/spec/result_spec.rb +50 -54
  180. data/spec/rspec/features_spec.rb +1 -0
  181. data/spec/rspec/shared_spec_matchers.rb +78 -62
  182. data/spec/rspec_spec.rb +5 -5
  183. data/spec/sauce_spec_chrome.rb +1 -0
  184. data/spec/selector_spec.rb +26 -16
  185. data/spec/selenium_spec_chrome.rb +84 -5
  186. data/spec/selenium_spec_chrome_remote.rb +23 -8
  187. data/spec/selenium_spec_edge.rb +23 -8
  188. data/spec/selenium_spec_firefox.rb +16 -21
  189. data/spec/selenium_spec_firefox_remote.rb +4 -13
  190. data/spec/selenium_spec_ie.rb +23 -15
  191. data/spec/selenium_spec_safari.rb +17 -17
  192. data/spec/server_spec.rb +87 -42
  193. data/spec/session_spec.rb +11 -4
  194. data/spec/shared_selenium_node.rb +83 -0
  195. data/spec/shared_selenium_session.rb +62 -72
  196. data/spec/spec_helper.rb +43 -5
  197. metadata +114 -16
@@ -8,7 +8,7 @@ module Capybara
8
8
  automatic_reload match exact exact_text raise_server_errors visible_text_only
9
9
  automatic_label_click enable_aria_label save_path asset_host default_host app_host
10
10
  server_host server_port server_errors default_set_options disable_animation test_id
11
- predicates_wait default_normalize_ws].freeze
11
+ predicates_wait default_normalize_ws w3c_click_offset enable_aria_role].freeze
12
12
 
13
13
  attr_accessor(*OPTIONS)
14
14
 
@@ -37,6 +37,8 @@ module Capybara
37
37
  # See {Capybara.configure}
38
38
  # @!method enable_aria_label
39
39
  # See {Capybara.configure}
40
+ # @!method enable_aria_role
41
+ # See {Capybara.configure}
40
42
  # @!method save_path
41
43
  # See {Capybara.configure}
42
44
  # @!method asset_host
@@ -59,6 +61,8 @@ module Capybara
59
61
  # See {Capybara.configure}
60
62
  # @!method default_normalize_ws
61
63
  # See {Capybara.configure}
64
+ # @!method w3c_click_offset
65
+ # See {Capybara.configure}
62
66
 
63
67
  remove_method :server_host
64
68
 
@@ -77,24 +81,22 @@ module Capybara
77
81
 
78
82
  remove_method :app_host=
79
83
  def app_host=(url)
80
- raise ArgumentError, "Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." if url && url !~ URI::DEFAULT_PARSER.make_regexp
84
+ unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
85
+ raise ArgumentError, "Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}."
86
+ end
81
87
 
82
88
  @app_host = url
83
89
  end
84
90
 
85
91
  remove_method :default_host=
86
92
  def default_host=(url)
87
- raise ArgumentError, "Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}." if url && url !~ URI::DEFAULT_PARSER.make_regexp
93
+ unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
94
+ raise ArgumentError, "Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}."
95
+ end
88
96
 
89
97
  @default_host = url
90
98
  end
91
99
 
92
- remove_method :disable_animation=
93
- def disable_animation=(bool_or_allowlist)
94
- warn 'Capybara.disable_animation is a beta feature - it may change/disappear in a future point version' if bool_or_allowlist
95
- @disable_animation = bool_or_allowlist
96
- end
97
-
98
100
  remove_method :test_id=
99
101
  ##
100
102
  #
@@ -102,7 +104,7 @@ module Capybara
102
104
  # This attribute will be checked by builtin selector types whenever id would normally be checked.
103
105
  # If `nil` then it will be ignored.
104
106
  #
105
- # @params [String, Symbol, nil] id Name of the attribute to use as the test id
107
+ # @param [String, Symbol, nil] id Name of the attribute to use as the test id
106
108
  #
107
109
  def test_id=(id)
108
110
  @test_id = id&.to_sym
@@ -20,7 +20,7 @@ module Capybara
20
20
  # @return [true]
21
21
  #
22
22
  def assert_current_path(path, **options)
23
- _verify_current_path(path, options) do |query|
23
+ _verify_current_path(path, **options) do |query|
24
24
  raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self)
25
25
  end
26
26
  end
@@ -36,7 +36,7 @@ module Capybara
36
36
  # @return [true]
37
37
  #
38
38
  def assert_no_current_path(path, **options)
39
- _verify_current_path(path, options) do |query|
39
+ _verify_current_path(path, **options) do |query|
40
40
  raise Capybara::ExpectationNotMet, query.negative_failure_message if query.resolves_for?(self)
41
41
  end
42
42
  end
@@ -51,7 +51,7 @@ module Capybara
51
51
  # @return [Boolean]
52
52
  #
53
53
  def has_current_path?(path, **options)
54
- make_predicate(options) { assert_current_path(path, options) }
54
+ make_predicate(options) { assert_current_path(path, **options) }
55
55
  end
56
56
 
57
57
  ##
@@ -64,13 +64,13 @@ module Capybara
64
64
  # @return [Boolean]
65
65
  #
66
66
  def has_no_current_path?(path, **options)
67
- make_predicate(options) { assert_no_current_path(path, options) }
67
+ make_predicate(options) { assert_no_current_path(path, **options) }
68
68
  end
69
69
 
70
70
  private
71
71
 
72
- def _verify_current_path(path, options)
73
- query = Capybara::Queries::CurrentPathQuery.new(path, options)
72
+ def _verify_current_path(path, **options)
73
+ query = Capybara::Queries::CurrentPathQuery.new(path, **options)
74
74
  document.synchronize(query.wait) do
75
75
  yield(query)
76
76
  end
@@ -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,24 +1,95 @@
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){
16
44
  $(this).after('<div class="log">DragOver with client position: ' + ev.clientX + ',' + ev.clientY)
17
45
  if ($(this).hasClass('drop')) { ev.preventDefault(); }
18
46
  });
47
+ $('#drop_html5, #drop_html5_scroll').on('dragleave', function(ev){
48
+ $(this).after('<div class="log">DragLeave with client position: ' + ev.clientX + ',' + ev.clientY)
49
+ if ($(this).hasClass('drop')) { ev.preventDefault(); }
50
+ });
51
+ $('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
52
+ $(this).after('<div class="log">Drop with client position: ' + ev.clientX + ',' + ev.clientY)
53
+ if ($(this).hasClass('drop')) { ev.preventDefault(); }
54
+ });
19
55
  $('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
20
56
  ev.preventDefault();
21
- $(this).html('HTML5 Dropped ' + ev.originalEvent.dataTransfer.getData("text"));
57
+ var oev = ev.originalEvent;
58
+ if (oev.dataTransfer.items) {
59
+ for (var i = 0; i < oev.dataTransfer.items.length; i++){
60
+ var item = oev.dataTransfer.items[i];
61
+ if (item.kind === 'file'){
62
+ var file = item.getAsFile();
63
+ $(this).append('HTML5 Dropped file: ' + file.name);
64
+ } else {
65
+ var _this = this;
66
+ var callback = (function(type) {
67
+ return function(s) {
68
+ $(_this).append(
69
+ "HTML5 Dropped string: " +
70
+ type +
71
+ " " +
72
+ s +
73
+ (ev.altKey ? "-alt" : "") +
74
+ (ev.ctrlKey ? "-ctrl" : "") +
75
+ (ev.metaKey ? "-meta" : "") +
76
+ (ev.shiftKey ? "-shift" : "")
77
+ );
78
+ };
79
+ })(item.type);
80
+ item.getAsString(callback);
81
+ }
82
+ }
83
+ } else {
84
+ $(this).html('HTML5 Dropped ' + oev.dataTransfer.getData("text"));
85
+ for (var i = 0; i < oev.dataTransfer.files.length; i++) {
86
+ $(this).append('HTML5 Dropped file: ' + oev.dataTransfer.files[i].name);
87
+ }
88
+ for (var i = 0; i < oev.dataTransfer.types.length; i++) {
89
+ var type = oev.dataTransfer.types[i];
90
+ $(this).append('HTML5 Dropped string: ' + type + ' ' + oev.dataTransfer.getData(type));
91
+ }
92
+ }
22
93
  });
23
94
  $('#clickable').click(function(e) {
24
95
  var link = $(this);
@@ -37,6 +108,13 @@ $(function() {
37
108
  }, 4000);
38
109
  return false;
39
110
  });
111
+ $('#aria-button').click(function() {
112
+ var span = $(this);
113
+ setTimeout(function() {
114
+ $(span).after('<span role="button">ARIA button has been clicked</span>')
115
+ }, 1000);
116
+ return false;
117
+ });
40
118
  $('#waiter').change(function() {
41
119
  activeRequests = 1;
42
120
  setTimeout(function() {
@@ -82,6 +160,7 @@ $(function() {
82
160
  });
83
161
  $('#click-test').on({
84
162
  click: function(e) {
163
+ window.click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
85
164
  var desc = "";
86
165
  if (e.altKey) desc += 'alt ';
87
166
  if (e.ctrlKey) desc += 'control ';
@@ -108,6 +187,16 @@ $(function() {
108
187
  if (e.shiftKey) desc += 'shift ';
109
188
  var pos = this.getBoundingClientRect();
110
189
  $(this).after('<a id="has-been-right-clicked" href="#">Has been ' + desc + 'right clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '</a>');
190
+ },
191
+ mousedown: function(e) {
192
+ window.click_delay = undefined;
193
+ window.right_click_delay = undefined;
194
+ window.mouse_down_time = new Date().getTime();
195
+ },
196
+ mouseup: function(e) {
197
+ if (e.button == 2){
198
+ window.right_click_delay = ((new Date().getTime()) - window.mouse_down_time)/1000.0;
199
+ }
111
200
  }
112
201
  });
113
202
  $('#open-alert').click(function() {
@@ -180,7 +269,7 @@ $(function() {
180
269
  sessionStorage.setItem('session', 'session_value');
181
270
  localStorage.setItem('local', 'local value');
182
271
  });
183
- $('#multiple-file').change(function(e){
184
- $('body').append($('<p class="file_change"input_event_triggered">File input changed</p>'));
272
+ $('#multiple-file, #hidden_file').change(function(e){
273
+ $('body').append($('<p class="file_change">File input changed</p>'));
185
274
  })
186
275
  });
@@ -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')
33
+ @xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('Name')
34
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')
@@ -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,6 +198,7 @@ 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
@@ -142,6 +209,13 @@ Capybara::SpecHelper.spec '#all' do
142
209
  expect { @session.all(:css, 'h1, p', between: 5..) }.to raise_error(Capybara::ExpectationNotMet)
143
210
  end
144
211
  TEST
212
+
213
+ eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.6
214
+ it'treats a beginless range as maximum' do
215
+ expect { @session.all(:css, 'h1, p', between: ..7) }.not_to raise_error
216
+ expect { @session.all(:css, 'h1, p', between: ..3) }.to raise_error(Capybara::ExpectationNotMet)
217
+ end
218
+ TEST
145
219
  end
146
220
 
147
221
  context 'with multiple count filters' do
@@ -150,32 +224,36 @@ Capybara::SpecHelper.spec '#all' do
150
224
  minimum: 5,
151
225
  maximum: 0,
152
226
  between: 0..3 }
153
- expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
227
+ expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
154
228
  end
229
+
155
230
  context 'with no :count expectation' do
156
231
  it 'fails if :minimum is not met' do
157
232
  o = { minimum: 5,
158
233
  maximum: 4,
159
234
  between: 2..7 }
160
- expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
235
+ expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
161
236
  end
237
+
162
238
  it 'fails if :maximum is not met' do
163
239
  o = { minimum: 0,
164
240
  maximum: 0,
165
241
  between: 2..7 }
166
- expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
242
+ expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
167
243
  end
244
+
168
245
  it 'fails if :between is not met' do
169
246
  o = { minimum: 0,
170
247
  maximum: 4,
171
248
  between: 0..3 }
172
- expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
249
+ expect { @session.all(:css, 'h1, p', **o) }.to raise_error(Capybara::ExpectationNotMet)
173
250
  end
251
+
174
252
  it 'succeeds if all combineable expectations are met' do
175
253
  o = { minimum: 0,
176
254
  maximum: 4,
177
255
  between: 2..7 }
178
- expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
256
+ expect { @session.all(:css, 'h1, p', **o) }.not_to raise_error
179
257
  end
180
258
  end
181
259
  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