capybara 3.31.0 → 3.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +93 -13
  3. data/README.md +9 -4
  4. data/lib/capybara.rb +18 -8
  5. data/lib/capybara/config.rb +4 -6
  6. data/lib/capybara/cucumber.rb +1 -1
  7. data/lib/capybara/driver/base.rb +4 -0
  8. data/lib/capybara/helpers.rb +25 -1
  9. data/lib/capybara/minitest.rb +215 -141
  10. data/lib/capybara/minitest/spec.rb +156 -97
  11. data/lib/capybara/node/actions.rb +16 -21
  12. data/lib/capybara/node/element.rb +3 -5
  13. data/lib/capybara/node/finders.rb +7 -6
  14. data/lib/capybara/node/matchers.rb +11 -11
  15. data/lib/capybara/node/simple.rb +5 -1
  16. data/lib/capybara/queries/ancestor_query.rb +1 -1
  17. data/lib/capybara/queries/current_path_query.rb +14 -4
  18. data/lib/capybara/queries/selector_query.rb +16 -10
  19. data/lib/capybara/queries/sibling_query.rb +1 -1
  20. data/lib/capybara/queries/style_query.rb +1 -1
  21. data/lib/capybara/queries/text_query.rb +7 -1
  22. data/lib/capybara/rack_test/browser.rb +9 -3
  23. data/lib/capybara/rack_test/driver.rb +1 -0
  24. data/lib/capybara/rack_test/form.rb +1 -1
  25. data/lib/capybara/rack_test/node.rb +1 -1
  26. data/lib/capybara/registration_container.rb +44 -0
  27. data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
  28. data/lib/capybara/registrations/servers.rb +2 -1
  29. data/lib/capybara/result.rb +8 -8
  30. data/lib/capybara/rspec.rb +2 -0
  31. data/lib/capybara/rspec/matcher_proxies.rb +5 -5
  32. data/lib/capybara/rspec/matchers.rb +7 -6
  33. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  34. data/lib/capybara/rspec/matchers/have_text.rb +1 -1
  35. data/lib/capybara/rspec/matchers/match_style.rb +5 -0
  36. data/lib/capybara/selector.rb +10 -1
  37. data/lib/capybara/selector/definition.rb +11 -9
  38. data/lib/capybara/selector/definition/button.rb +8 -5
  39. data/lib/capybara/selector/definition/css.rb +1 -1
  40. data/lib/capybara/selector/definition/datalist_input.rb +1 -1
  41. data/lib/capybara/selector/definition/element.rb +2 -1
  42. data/lib/capybara/selector/definition/fillable_field.rb +1 -1
  43. data/lib/capybara/selector/definition/label.rb +1 -1
  44. data/lib/capybara/selector/definition/link.rb +8 -0
  45. data/lib/capybara/selector/definition/select.rb +1 -1
  46. data/lib/capybara/selector/definition/table.rb +1 -1
  47. data/lib/capybara/selector/definition/table_row.rb +1 -1
  48. data/lib/capybara/selector/filter_set.rb +2 -2
  49. data/lib/capybara/selector/selector.rb +9 -1
  50. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  51. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  52. data/lib/capybara/selenium/driver.rb +35 -6
  53. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +9 -11
  54. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -11
  55. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +3 -3
  56. data/lib/capybara/selenium/extensions/find.rb +3 -3
  57. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  58. data/lib/capybara/selenium/node.rb +75 -12
  59. data/lib/capybara/selenium/nodes/chrome_node.rb +20 -11
  60. data/lib/capybara/selenium/nodes/firefox_node.rb +2 -2
  61. data/lib/capybara/selenium/nodes/safari_node.rb +1 -1
  62. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  63. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  64. data/lib/capybara/selenium/patches/logs.rb +7 -9
  65. data/lib/capybara/server/animation_disabler.rb +3 -2
  66. data/lib/capybara/server/middleware.rb +4 -2
  67. data/lib/capybara/session.rb +23 -14
  68. data/lib/capybara/session/config.rb +3 -1
  69. data/lib/capybara/session/matchers.rb +11 -11
  70. data/lib/capybara/spec/public/test.js +24 -1
  71. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  72. data/lib/capybara/spec/session/check_spec.rb +6 -0
  73. data/lib/capybara/spec/session/click_button_spec.rb +11 -0
  74. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  75. data/lib/capybara/spec/session/fill_in_spec.rb +9 -0
  76. data/lib/capybara/spec/session/find_spec.rb +11 -8
  77. data/lib/capybara/spec/session/has_button_spec.rb +18 -0
  78. data/lib/capybara/spec/session/has_css_spec.rb +11 -7
  79. data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
  80. data/lib/capybara/spec/session/has_field_spec.rb +16 -0
  81. data/lib/capybara/spec/session/has_select_spec.rb +4 -4
  82. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  83. data/lib/capybara/spec/session/has_text_spec.rb +0 -11
  84. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  85. data/lib/capybara/spec/session/node_spec.rb +76 -29
  86. data/lib/capybara/spec/session/refresh_spec.rb +1 -0
  87. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  88. data/lib/capybara/spec/session/window/window_spec.rb +7 -7
  89. data/lib/capybara/spec/spec_helper.rb +13 -14
  90. data/lib/capybara/spec/test_app.rb +22 -21
  91. data/lib/capybara/spec/views/form.erb +25 -1
  92. data/lib/capybara/spec/views/with_animation.erb +8 -0
  93. data/lib/capybara/spec/views/with_dragula.erb +3 -1
  94. data/lib/capybara/spec/views/with_html.erb +2 -2
  95. data/lib/capybara/spec/views/with_js.erb +2 -0
  96. data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
  97. data/lib/capybara/version.rb +1 -1
  98. data/lib/capybara/window.rb +3 -7
  99. data/spec/basic_node_spec.rb +9 -8
  100. data/spec/capybara_spec.rb +1 -1
  101. data/spec/dsl_spec.rb +14 -1
  102. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  103. data/spec/minitest_spec.rb +3 -2
  104. data/spec/rack_test_spec.rb +28 -5
  105. data/spec/regexp_dissassembler_spec.rb +0 -4
  106. data/spec/result_spec.rb +38 -31
  107. data/spec/rspec/features_spec.rb +3 -1
  108. data/spec/rspec/scenarios_spec.rb +4 -0
  109. data/spec/rspec/shared_spec_matchers.rb +63 -51
  110. data/spec/rspec_spec.rb +4 -0
  111. data/spec/selector_spec.rb +2 -1
  112. data/spec/selenium_spec_chrome.rb +4 -2
  113. data/spec/selenium_spec_chrome_remote.rb +2 -0
  114. data/spec/server_spec.rb +56 -49
  115. data/spec/shared_selenium_node.rb +18 -0
  116. data/spec/shared_selenium_session.rb +84 -7
  117. data/spec/spec_helper.rb +1 -1
  118. metadata +25 -24
  119. data/lib/capybara/spec/session/source_spec.rb +0 -0
@@ -9,6 +9,8 @@ require 'capybara/rspec/matcher_proxies'
9
9
  RSpec.configure do |config|
10
10
  config.include Capybara::DSL, type: :feature
11
11
  config.include Capybara::RSpecMatchers, type: :feature
12
+ config.include Capybara::DSL, type: :system
13
+ config.include Capybara::RSpecMatchers, type: :system
12
14
  config.include Capybara::RSpecMatchers, type: :view
13
15
 
14
16
  # The before and after blocks must run instantaneously, because Capybara
@@ -2,17 +2,17 @@
2
2
 
3
3
  module Capybara
4
4
  module RSpecMatcherProxies
5
- def all(*args, &block)
5
+ def all(*args, **kwargs, &block)
6
6
  if defined?(::RSpec::Matchers::BuiltIn::All) && args.first.respond_to?(:matches?)
7
7
  ::RSpec::Matchers::BuiltIn::All.new(*args)
8
8
  else
9
- find_all(*args, &block)
9
+ find_all(*args, **kwargs, &block)
10
10
  end
11
11
  end
12
12
 
13
- def within(*args, &block)
14
- if block_given?
15
- within_element(*args, &block)
13
+ def within(*args, **kwargs, &block)
14
+ if block
15
+ within_element(*args, **kwargs, &block)
16
16
  else
17
17
  be_within(*args)
18
18
  end
@@ -94,7 +94,7 @@ module Capybara
94
94
  # @see Capybara::Node::Matchers#has_button?
95
95
 
96
96
  # @!method have_field(locator = nil, **options, &optional_filter_block)
97
- # RSpec matcher for links.
97
+ # RSpec matcher for form fields.
98
98
  #
99
99
  # @see Capybara::Node::Matchers#has_field?
100
100
 
@@ -139,22 +139,23 @@ module Capybara
139
139
  # RSpec matcher for the current path.
140
140
  #
141
141
  # @see Capybara::SessionMatchers#assert_current_path
142
- def have_current_path(path, **options)
143
- Matchers::HaveCurrentPath.new(path, **options)
142
+ def have_current_path(path, **options, &optional_filter_block)
143
+ Matchers::HaveCurrentPath.new(path, **options, &optional_filter_block)
144
144
  end
145
145
 
146
146
  # RSpec matcher for element style.
147
147
  #
148
148
  # @see Capybara::Node::Matchers#matches_style?
149
- def match_style(styles, **options)
149
+ def match_style(styles = nil, **options)
150
+ styles, options = options, {} if styles.nil?
150
151
  Matchers::MatchStyle.new(styles, **options)
151
152
  end
152
153
 
153
154
  ##
154
155
  # @deprecated
155
156
  #
156
- def have_style(styles, **options)
157
- warn 'DEPRECATED: have_style is deprecated, please use match_style'
157
+ def have_style(styles = nil, **options)
158
+ Capybara::Helpers.warn "DEPRECATED: have_style is deprecated, please use match_style : #{Capybara::Helpers.filter_backtrace(caller)}"
158
159
  match_style(styles, **options)
159
160
  end
160
161
 
@@ -7,11 +7,11 @@ module Capybara
7
7
  module Matchers
8
8
  class HaveCurrentPath < WrappedElementMatcher
9
9
  def element_matches?(el)
10
- el.assert_current_path(current_path, **@kw_args)
10
+ el.assert_current_path(current_path, **@kw_args, &@filter_block)
11
11
  end
12
12
 
13
13
  def element_does_not_match?(el)
14
- el.assert_no_current_path(current_path, **@kw_args)
14
+ el.assert_no_current_path(current_path, **@kw_args, &@filter_block)
15
15
  end
16
16
 
17
17
  def description
@@ -15,7 +15,7 @@ module Capybara
15
15
  end
16
16
 
17
17
  def description
18
- "text #{format(text)}"
18
+ "have text #{format(text)}"
19
19
  end
20
20
 
21
21
  def format(content)
@@ -6,6 +6,11 @@ module Capybara
6
6
  module RSpecMatchers
7
7
  module Matchers
8
8
  class MatchStyle < WrappedElementMatcher
9
+ def initialize(styles = nil, **kw_args, &filter_block)
10
+ styles, kw_args = kw_args, {} if styles.nil?
11
+ super(styles, **kw_args, &filter_block)
12
+ end
13
+
9
14
  def element_matches?(el)
10
15
  el.assert_matches_style(*@args, **@kw_args)
11
16
  end
@@ -40,6 +40,7 @@ require 'capybara/selector/definition'
40
40
  # * :disabled (Boolean, :all) - Match disabled field? (Default: false)
41
41
  # * :multiple (Boolean) - Match fields that accept multiple values
42
42
  # * :valid (Boolean) - Match fields that are valid/invalid according to HTML5 form validation
43
+ # * :validation_message (String, Regexp) - Matches the elements current validationMessage
43
44
  #
44
45
  # * **:fieldset** - Select fieldset elements
45
46
  # * Locator: Matches id, {Capybara.configure test_id}, or contents of wrapped legend
@@ -79,6 +80,7 @@ require 'capybara/selector/definition'
79
80
  # * :disabled (Boolean, :all) - Match disabled field? (Default: false)
80
81
  # * :multiple (Boolean) - Match fields that accept multiple values
81
82
  # * :valid (Boolean) - Match fields that are valid/invalid according to HTML5 form validation
83
+ # * :validation_message (String, Regexp) - Matches the elements current validationMessage
82
84
  #
83
85
  # * **:radio_button** - Find radio buttons
84
86
  # * Locator: Match id, {Capybara.configure test_id} attribute, name, or associated label text
@@ -178,6 +180,12 @@ Capybara::Selector::FilterSet.add(:_field) do
178
180
  node_filter(:valid, :boolean) { |node, value| node.evaluate_script('this.validity.valid') == value }
179
181
  node_filter(:name) { |node, value| !value.is_a?(Regexp) || value.match?(node[:name]) }
180
182
  node_filter(:placeholder) { |node, value| !value.is_a?(Regexp) || value.match?(node[:placeholder]) }
183
+ node_filter(:validation_message) do |node, msg|
184
+ vm = node[:validationMessage]
185
+ (msg.is_a?(Regexp) ? msg.match?(vm) : vm == msg.to_s).tap do |res|
186
+ add_error("Expected validation message to be #{msg.inspect} but was #{vm}") unless res
187
+ end
188
+ end
181
189
 
182
190
  expression_filter(:name) do |xpath, val|
183
191
  builder(xpath).add_attribute_conditions(name: val)
@@ -198,7 +206,7 @@ Capybara::Selector::FilterSet.add(:_field) do
198
206
  desc
199
207
  end
200
208
 
201
- describe(:node_filters) do |checked: nil, unchecked: nil, disabled: nil, valid: nil, **|
209
+ describe(:node_filters) do |checked: nil, unchecked: nil, disabled: nil, valid: nil, validation_message: nil, **|
202
210
  desc, states = +'', []
203
211
  states << 'checked' if checked || (unchecked == false)
204
212
  states << 'not checked' if unchecked || (checked == false)
@@ -206,6 +214,7 @@ Capybara::Selector::FilterSet.add(:_field) do
206
214
  desc << " that is #{states.join(' and ')}" unless states.empty?
207
215
  desc << ' that is valid' if valid == true
208
216
  desc << ' that is invalid' if valid == false
217
+ desc << " with validation message #{validation_message.to_s.inspect}" if validation_message
209
218
  desc
210
219
  end
211
220
  end
@@ -10,11 +10,12 @@ module Capybara
10
10
  class Selector
11
11
  class Definition
12
12
  attr_reader :name, :expressions
13
+
13
14
  extend Forwardable
14
15
 
15
16
  def initialize(name, locator_type: nil, raw_locator: false, supports_exact: nil, &block)
16
17
  @name = name
17
- @filter_set = Capybara::Selector::FilterSet.add(name) {}
18
+ @filter_set = Capybara::Selector::FilterSet.add(name)
18
19
  @match = nil
19
20
  @label = nil
20
21
  @failure_message = nil
@@ -82,7 +83,7 @@ module Capybara
82
83
  # Automatic selector detection
83
84
  #
84
85
  # @yield [locator] This block takes the passed in locator string and returns whether or not it matches the selector
85
- # @yieldparam [String], locator The locator string used to determin if it matches the selector
86
+ # @yieldparam [String], locator The locator string used to determine if it matches the selector
86
87
  # @yieldreturn [Boolean] Whether this selector matches the locator string
87
88
  # @return [#call] The block that will be used to detect selector match
88
89
  #
@@ -177,7 +178,7 @@ module Capybara
177
178
  def_delegator :@filter_set, :describe
178
179
 
179
180
  def describe_expression_filters(&block)
180
- if block_given?
181
+ if block
181
182
  describe(:expression_filters, &block)
182
183
  else
183
184
  describe(:expression_filters) do |**options|
@@ -189,7 +190,7 @@ module Capybara
189
190
  def describe_all_expression_filters(**opts)
190
191
  expression_filters.map do |ef_name, ef|
191
192
  if ef.matcher?
192
- handled_custom_keys(ef, opts.keys).map { |key| " with #{ef_name}[#{key} => #{opts[key]}]" }.join
193
+ handled_custom_options(ef, opts).map { |option, value| " with #{ef_name}[#{option} => #{value}]" }.join
193
194
  elsif opts.key?(ef_name)
194
195
  " with #{ef_name} #{opts[ef_name]}"
195
196
  end
@@ -214,7 +215,7 @@ module Capybara
214
215
  end
215
216
 
216
217
  def default_visibility(fallback = Capybara.ignore_hidden_elements, options = {})
217
- vis = if @default_visibility&.respond_to?(:call)
218
+ vis = if @default_visibility.respond_to?(:call)
218
219
  @default_visibility.call(options)
219
220
  else
220
221
  @default_visibility
@@ -251,14 +252,15 @@ module Capybara
251
252
 
252
253
  private
253
254
 
254
- def handled_custom_keys(filter, keys)
255
- keys.select do |key|
256
- filter.handles_option?(key) && !::Capybara::Queries::SelectorQuery::VALID_KEYS.include?(key)
255
+ def handled_custom_options(filter, options)
256
+ options.select do |option, _|
257
+ filter.handles_option?(option) && !::Capybara::Queries::SelectorQuery::VALID_KEYS.include?(option)
257
258
  end
258
259
  end
259
260
 
260
261
  def parameter_names(block)
261
- block.parameters.select { |(type, _name)| %i[key keyreq].include? type }.map { |(_type, name)| name }
262
+ key_types = %i[key keyreq]
263
+ block.parameters.select { |(type, _name)| key_types.include? type }.map { |(_type, name)| name }
262
264
  end
263
265
 
264
266
  def expression(type, allowed_filters, &block)
@@ -4,6 +4,7 @@ Capybara.add_selector(:button, locator_type: [String, Symbol]) do
4
4
  xpath(:value, :title, :type, :name) do |locator, **options|
5
5
  input_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')]
6
6
  btn_xpath = XPath.descendant(:button)
7
+ btn_xpath += XPath.descendant[XPath.attr(:role).equals('button')] if enable_aria_role
7
8
  image_btn_xpath = XPath.descendant(:input)[XPath.attr(:type) == 'image']
8
9
 
9
10
  unless locator.nil?
@@ -11,23 +12,25 @@ Capybara.add_selector(:button, locator_type: [String, Symbol]) do
11
12
  locator_matchers = XPath.attr(:id).equals(locator) |
12
13
  XPath.attr(:name).equals(locator) |
13
14
  XPath.attr(:value).is(locator) |
14
- XPath.attr(:title).is(locator)
15
+ XPath.attr(:title).is(locator) |
16
+ (XPath.attr(:id) == XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for))
15
17
  locator_matchers |= XPath.attr(:'aria-label').is(locator) if enable_aria_label
16
18
  locator_matchers |= XPath.attr(test_id) == locator if test_id
17
19
 
18
- input_btn_xpath = input_btn_xpath[locator_matchers]
20
+ input_btn_xpath = input_btn_xpath[locator_matchers] + locate_label(locator).descendant(input_btn_xpath)
19
21
 
20
22
  btn_xpath = btn_xpath[locator_matchers |
21
23
  XPath.string.n.is(locator) |
22
- XPath.descendant(:img)[XPath.attr(:alt).is(locator)]]
24
+ XPath.descendant(:img)[XPath.attr(:alt).is(locator)]
25
+ ] + locate_label(locator).descendant(btn_xpath)
23
26
 
24
27
  alt_matches = XPath.attr(:alt).is(locator)
25
28
  alt_matches |= XPath.attr(:'aria-label').is(locator) if enable_aria_label
26
- image_btn_xpath = image_btn_xpath[alt_matches]
29
+ image_btn_xpath = image_btn_xpath[alt_matches] + locate_label(locator).descendant(image_btn_xpath)
27
30
  end
28
31
 
29
32
  %i[value title type].inject(input_btn_xpath.union(btn_xpath).union(image_btn_xpath)) do |memo, ef|
30
- memo[find_by_attr(ef, options[ef])]
33
+ memo.where(find_by_attr(ef, options[ef]))
31
34
  end
32
35
  end
33
36
 
@@ -3,7 +3,7 @@
3
3
  Capybara.add_selector(:css, locator_type: [String, Symbol], raw_locator: true) do
4
4
  css do |css|
5
5
  if css.is_a? Symbol
6
- warn "DEPRECATED: Passing a symbol (#{css.inspect}) as the CSS locator is deprecated - please pass a string instead."
6
+ Capybara::Helpers.warn "DEPRECATED: Passing a symbol (#{css.inspect}) as the CSS locator is deprecated - please pass a string instead : #{Capybara::Helpers.filter_backtrace(caller)}"
7
7
  end
8
8
  css
9
9
  end
@@ -19,7 +19,7 @@ Capybara.add_selector(:datalist_input, locator_type: [String, Symbol]) do
19
19
 
20
20
  expression_filter(:with_options) do |expr, options|
21
21
  options.inject(expr) do |xpath, option|
22
- xpath[XPath.attr(:list) == XPath.anywhere(:datalist)[expression_for(:datalist_option, option)].attr(:id)]
22
+ xpath.where(XPath.attr(:list) == XPath.anywhere(:datalist)[expression_for(:datalist_option, option)].attr(:id))
23
23
  end
24
24
  end
25
25
 
@@ -18,7 +18,8 @@ Capybara.add_selector(:element, locator_type: [String, Symbol]) do
18
18
  end
19
19
 
20
20
  describe_expression_filters do |**options|
21
- booleans, values = options.partition { |_k, v| [true, false].include? v }.map(&:to_h)
21
+ boolean_values = [true, false]
22
+ booleans, values = options.partition { |_k, v| boolean_values.include? v }.map(&:to_h)
22
23
  desc = describe_all_expression_filters(**values)
23
24
  desc + booleans.map do |k, v|
24
25
  v ? " with #{k} attribute" : "without #{k} attribute"
@@ -18,7 +18,7 @@ Capybara.add_selector(:fillable_field, locator_type: [String, Symbol]) do
18
18
  end
19
19
  end
20
20
 
21
- filter_set(:_field, %i[disabled multiple name placeholder valid])
21
+ filter_set(:_field, %i[disabled multiple name placeholder valid validation_message])
22
22
 
23
23
  node_filter(:with) do |node, with|
24
24
  val = node.value
@@ -53,7 +53,7 @@ Capybara.add_selector(:label, locator_type: [String, Symbol]) do
53
53
  end
54
54
  end
55
55
  describe_node_filters do |**options|
56
- " for element #{options[:for]}" if options[:for]&.is_a?(Capybara::Node::Element)
56
+ " for element #{options[:for]}" if options[:for].is_a?(Capybara::Node::Element)
57
57
  end
58
58
 
59
59
  def labelable_elements
@@ -5,6 +5,13 @@ Capybara.add_selector(:link, locator_type: [String, Symbol]) do
5
5
  xpath = XPath.descendant(:a)
6
6
  xpath = builder(xpath).add_attribute_conditions(href: href) unless href == false
7
7
 
8
+ if enable_aria_role
9
+ role_path = XPath.descendant[XPath.attr(:role).equals('link')]
10
+ role_path = builder(role_path).add_attribute_conditions(href: href) unless [true, false].include? href
11
+
12
+ xpath += role_path
13
+ end
14
+
8
15
  unless locator.nil?
9
16
  locator = locator.to_s
10
17
  matchers = [XPath.attr(:id) == locator,
@@ -18,6 +25,7 @@ Capybara.add_selector(:link, locator_type: [String, Symbol]) do
18
25
 
19
26
  xpath = xpath[find_by_attr(:title, title)]
20
27
  xpath = xpath[XPath.descendant(:img)[XPath.attr(:alt) == alt]] if alt
28
+
21
29
  xpath
22
30
  end
23
31
 
@@ -33,7 +33,7 @@ Capybara.add_selector(:select, locator_type: [String, Symbol]) do
33
33
 
34
34
  expression_filter(:with_options) do |expr, options|
35
35
  options.inject(expr) do |xpath, option|
36
- xpath[expression_for(:option, option)]
36
+ xpath.where(expression_for(:option, option))
37
37
  end
38
38
  end
39
39
 
@@ -43,7 +43,7 @@ Capybara.add_selector(:table, locator_type: [String, Symbol]) do
43
43
  end
44
44
 
45
45
  expression_filter(:cols, valid_values: [Array]) do |xpath, cols|
46
- raise ArgumentError, ':cols must be an Array of Arrays' unless cols.all? { |col| col.is_a? Array }
46
+ raise ArgumentError, ':cols must be an Array of Arrays' unless cols.all?(Array)
47
47
 
48
48
  rows = cols.transpose
49
49
  col_conditions = rows.map { |row| match_row(row, match_size: true) }.reduce(:&)
@@ -14,7 +14,7 @@ Capybara.add_selector(:table_row, locator_type: [Array, Hash]) do
14
14
  else
15
15
  initial_td = XPath.descendant(:td)[XPath.string.n.is(locator.shift)]
16
16
  tds = locator.reverse.map { |cell| XPath.following_sibling(:td)[XPath.string.n.is(cell)] }
17
- .reduce { |xp, cell| xp[cell] }
17
+ .reduce { |xp, cell| xp.where(cell) }
18
18
  xpath[initial_td[tds]]
19
19
  end
20
20
  end
@@ -12,7 +12,7 @@ module Capybara
12
12
  @node_filters = {}
13
13
  @expression_filters = {}
14
14
  @descriptions = Hash.new { |hsh, key| hsh[key] = [] }
15
- instance_eval(&block)
15
+ instance_eval(&block) if block
16
16
  end
17
17
 
18
18
  def node_filter(names, *types, **options, &block)
@@ -49,7 +49,7 @@ module Capybara
49
49
  end
50
50
 
51
51
  def descriptions
52
- warn 'DEPRECATED: FilterSet#descriptions is deprecated without replacement'
52
+ Capybara::Helpers.warn 'DEPRECATED: FilterSet#descriptions is deprecated without replacement'
53
53
  [undeclared_descriptions, node_filter_descriptions, expression_filter_descriptions].flatten
54
54
  end
55
55
 
@@ -48,6 +48,10 @@ module Capybara
48
48
  @config[:enable_aria_label]
49
49
  end
50
50
 
51
+ def enable_aria_role
52
+ @config[:enable_aria_role]
53
+ end
54
+
51
55
  def test_id
52
56
  @config[:test_id]
53
57
  end
@@ -128,7 +132,11 @@ module Capybara
128
132
  attr_matchers |= XPath.attr(test_id) == locator if test_id
129
133
 
130
134
  locate_xpath = locate_xpath[attr_matchers]
131
- locate_xpath + XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(xpath)
135
+ locate_xpath + locate_label(locator).descendant(xpath)
136
+ end
137
+
138
+ def locate_label(locator)
139
+ XPath.descendant(:label)[XPath.string.n.is(locator)]
132
140
  end
133
141
 
134
142
  def find_by_attr(attribute, value)
@@ -1 +1 @@
1
- (function(){function u(e){var t=e.tagName.toUpperCase();if("OPTION"==t)return!0;if("INPUT"!=t)return!1;var r=e.type.toLowerCase();return"checkbox"==r||"radio"==r}function s(e){var t="selected",r=e.type&&e.type.toLowerCase();return"checkbox"!=r&&"radio"!=r||(t="checked"),!!e[t]}function c(e,t){var r=e.getAttributeNode(t);return r&&r.specified?r.value:null}var i=["allowfullscreen","allowpaymentrequest","allowusermedia","async","autofocus","autoplay","checked","compact","complete","controls","declare","default","defaultchecked","defaultselected","defer","disabled","ended","formnovalidate","hidden","indeterminate","iscontenteditable","ismap","itemscope","loop","multiple","muted","nohref","nomodule","noresize","noshade","novalidate","nowrap","open","paused","playsinline","pubdate","readonly","required","reversed","scoped","seamless","seeking","selected","truespeed","typemustmatch","willvalidate"],d={"class":"className",readonly:"readOnly"};return function f(e,t){var r=null,a=t.toLowerCase();if("style"==a)return(r=e.style)&&"string"!=typeof r&&(r=r.cssText),r;if(("selected"==a||"checked"==a)&&u(e))return s(e)?"true":null;if(tagName=e.tagName.toUpperCase(),"IMG"==tagName&&"src"==a||"A"==tagName&&"href"==a)return(r=c(e,a))&&(r=e[a]),r;if("spellcheck"==a){if(null===!(r=c(e,a))){if("false"==r.toLowerCase())return"false";if("true"==r.toLowerCase())return"true"}return e[a]+""}var l,n=d[t]||t;if(i.some(function(e){e==a}))return(r=!(null===(r=c(e,a)))||e[n])?"true":null;try{l=e[n]}catch(o){}return null!=(r=null==l||"object"==typeof l||"function"==typeof l?c(e,t):l)?r.toString():null}})()
1
+ (function(){function u(e){var t=e.tagName.toUpperCase();if("OPTION"==t)return!0;if("INPUT"!=t)return!1;var r=e.type.toLowerCase();return"checkbox"==r||"radio"==r}function s(e){var t="selected",r=e.type&&e.type.toLowerCase();return"checkbox"!=r&&"radio"!=r||(t="checked"),!!e[t]}function c(e,t){var r=e.getAttributeNode(t);return r&&r.specified?r.value:null}var i=["allowfullscreen","allowpaymentrequest","allowusermedia","async","autofocus","autoplay","checked","compact","complete","controls","declare","default","defaultchecked","defaultselected","defer","disabled","ended","formnovalidate","hidden","indeterminate","iscontenteditable","ismap","itemscope","loop","multiple","muted","nohref","nomodule","noresize","noshade","novalidate","nowrap","open","paused","playsinline","pubdate","readonly","required","reversed","scoped","seamless","seeking","selected","truespeed","typemustmatch","willvalidate"],d={"class":"className",readonly:"readOnly"};return function f(e,t){var r=null,a=t.toLowerCase();if("style"==a)return(r=e.style)&&"string"!=typeof r&&(r=r.cssText),r;if(("selected"==a||"checked"==a)&&u(e))return s(e)?"true":null;if(tagName=e.tagName.toUpperCase(),"IMG"==tagName&&"src"==a||"A"==tagName&&"href"==a)return(r=c(e,a))&&(r=e[a]),r;if("spellcheck"==a){if(null!==(r=c(e,a))){if("false"==r.toLowerCase())return"false";if("true"==r.toLowerCase())return"true"}return e[a]+""}var l,n=d[t]||t;if(i.some(function(e){e==a}))return(r=!(null===(r=c(e,a)))||e[n])?"true":null;try{l=e[n]}catch(o){}return null!=(r=null==l||"object"==typeof l||"function"==typeof l?c(e,t):l)?r.toString():null}})()
@@ -117,7 +117,7 @@
117
117
 
118
118
  if ("spellcheck" == name) {
119
119
  value = getAttributeValue(element, name);
120
- if (!value === null) {
120
+ if (!(value === null)) {
121
121
  if (value.toLowerCase() == "false") {
122
122
  return "false";
123
123
  } else if (value.toLowerCase() == "true") {
@@ -20,11 +20,29 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
20
20
  require 'capybara/selenium/logger_suppressor'
21
21
  require 'capybara/selenium/patches/atoms'
22
22
  require 'capybara/selenium/patches/is_displayed'
23
- if Gem.loaded_specs['selenium-webdriver'].version < Gem::Version.new('3.5.0')
23
+ require 'capybara/selenium/patches/action_pauser'
24
+
25
+ # Look up the version of `selenium-webdriver` to
26
+ # see if it's a version we support.
27
+ #
28
+ # By default, we use Gem.loaded_specs to determine
29
+ # the version number. However, in some cases, such
30
+ # as when loading `selenium-webdriver` outside of
31
+ # Rubygems, we fall back to referencing
32
+ # Selenium::WebDriver::VERSION. Ideally we'd
33
+ # use the constant in all cases, but earlier versions
34
+ # of `selenium-webdriver` didn't provide the constant.
35
+ selenium_webdriver_version =
36
+ if Gem.loaded_specs['selenium-webdriver']
37
+ Gem.loaded_specs['selenium-webdriver'].version
38
+ else
39
+ Gem::Version.new(Selenium::WebDriver::VERSION)
40
+ end
41
+ if selenium_webdriver_version < Gem::Version.new('3.5.0')
24
42
  warn "Warning: You're using an unsupported version of selenium-webdriver, please upgrade."
25
43
  end
26
44
  rescue LoadError => e
27
- raise e unless e.message.match?(/selenium-webdriver/)
45
+ raise e unless e.message.include?('selenium-webdriver')
28
46
 
29
47
  raise LoadError, "Capybara's selenium driver is unable to load `selenium-webdriver`, please install the gem and add `gem 'selenium-webdriver'` to your Gemfile if you are using bundler."
30
48
  end
@@ -57,6 +75,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
57
75
  end
58
76
 
59
77
  def initialize(app, **options)
78
+ super()
60
79
  self.class.load_selenium
61
80
  @app = app
62
81
  @browser = nil
@@ -84,6 +103,8 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
84
103
 
85
104
  def html
86
105
  browser.page_source
106
+ rescue Selenium::WebDriver::Error::JavascriptError => e
107
+ raise unless e.message.include?('documentElement is null')
87
108
  end
88
109
 
89
110
  def title
@@ -112,6 +133,10 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
112
133
  unwrap_script_result(result)
113
134
  end
114
135
 
136
+ def send_keys(*args)
137
+ active_element.send_keys(*args)
138
+ end
139
+
115
140
  def save_screenshot(path, **_options)
116
141
  browser.save_screenshot(path)
117
142
  end
@@ -240,7 +265,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
240
265
 
241
266
  def quit
242
267
  @browser&.quit
243
- rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED # rubocop:disable Lint/SuppressedException
268
+ rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED
244
269
  # Browser must have already gone
245
270
  rescue Selenium::WebDriver::Error::UnknownError => e
246
271
  unless silenced_unknown_error_message?(e.message) # Most likely already gone
@@ -292,7 +317,7 @@ private
292
317
  def clear_browser_state
293
318
  delete_all_cookies
294
319
  clear_storage
295
- rescue *clear_browser_state_errors # rubocop:disable Lint/SuppressedException
320
+ rescue *clear_browser_state_errors
296
321
  # delete_all_cookies fails when we've previously gone
297
322
  # to about:blank, so we rescue this error and do nothing
298
323
  # instead.
@@ -316,7 +341,7 @@ private
316
341
  def clear_storage
317
342
  clear_session_storage unless options[:clear_session_storage] == false
318
343
  clear_local_storage unless options[:clear_local_storage] == false
319
- rescue Selenium::WebDriver::Error::JavascriptError # rubocop:disable Lint/SuppressedException
344
+ rescue Selenium::WebDriver::Error::JavascriptError
320
345
  # session/local storage may not be available if on non-http pages (e.g. about:blank)
321
346
  end
322
347
 
@@ -352,7 +377,7 @@ private
352
377
  @browser.navigate.to(url)
353
378
  sleep 0.1 # slight wait for alert
354
379
  @browser.switch_to.alert.accept
355
- rescue modal_error # rubocop:disable Lint/SuppressedException
380
+ rescue modal_error
356
381
  # alert now gone, should mean navigation happened
357
382
  end
358
383
 
@@ -434,6 +459,10 @@ private
434
459
  browser
435
460
  end
436
461
 
462
+ def active_element
463
+ browser.switch_to.active_element
464
+ end
465
+
437
466
  def build_node(native_node, initial_cache = {})
438
467
  ::Capybara::Selenium::Node.new(self, native_node, initial_cache)
439
468
  end