capybara 3.35.0 → 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.
- checksums.yaml +4 -4
- data/History.md +168 -5
- data/README.md +199 -39
- data/lib/capybara/config.rb +16 -4
- data/lib/capybara/driver/base.rb +4 -0
- data/lib/capybara/driver/node.rb +5 -1
- data/lib/capybara/dsl.rb +4 -10
- data/lib/capybara/helpers.rb +9 -14
- data/lib/capybara/minitest/spec.rb +18 -6
- data/lib/capybara/minitest.rb +14 -1
- data/lib/capybara/node/actions.rb +14 -9
- data/lib/capybara/node/base.rb +2 -1
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/element.rb +13 -2
- data/lib/capybara/node/finders.rb +11 -2
- data/lib/capybara/node/matchers.rb +25 -0
- data/lib/capybara/node/simple.rb +5 -1
- data/lib/capybara/node/whitespace_normalizer.rb +81 -0
- data/lib/capybara/queries/active_element_query.rb +18 -0
- data/lib/capybara/queries/ancestor_query.rb +2 -1
- data/lib/capybara/queries/base_query.rb +2 -2
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +40 -11
- data/lib/capybara/queries/sibling_query.rb +2 -1
- data/lib/capybara/queries/text_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +64 -8
- data/lib/capybara/rack_test/driver.rb +4 -4
- data/lib/capybara/rack_test/form.rb +29 -7
- data/lib/capybara/rack_test/node.rb +32 -33
- data/lib/capybara/registration_container.rb +2 -5
- data/lib/capybara/registrations/drivers.rb +7 -7
- data/lib/capybara/registrations/servers.rb +37 -16
- data/lib/capybara/result.rb +2 -2
- data/lib/capybara/rspec/matcher_proxies.rb +6 -6
- data/lib/capybara/rspec/matchers/base.rb +8 -6
- data/lib/capybara/rspec/matchers/compound.rb +1 -1
- data/lib/capybara/rspec/matchers/have_selector.rb +9 -17
- data/lib/capybara/rspec/matchers.rb +21 -16
- data/lib/capybara/selector/builders/css_builder.rb +1 -1
- data/lib/capybara/selector/builders/xpath_builder.rb +1 -1
- data/lib/capybara/selector/css.rb +6 -6
- data/lib/capybara/selector/definition/button.rb +10 -5
- data/lib/capybara/selector/definition/checkbox.rb +1 -1
- data/lib/capybara/selector/definition/file_field.rb +1 -1
- data/lib/capybara/selector/definition/fillable_field.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +2 -1
- data/lib/capybara/selector/definition/radio_button.rb +1 -1
- data/lib/capybara/selector/definition/table.rb +1 -1
- data/lib/capybara/selector/definition/table_row.rb +2 -2
- data/lib/capybara/selector/definition.rb +4 -2
- data/lib/capybara/selector/filter_set.rb +4 -7
- data/lib/capybara/selector/regexp_disassembler.rb +2 -5
- data/lib/capybara/selector/selector.rb +5 -1
- data/lib/capybara/selector.rb +252 -0
- data/lib/capybara/selenium/driver.rb +31 -54
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +1 -1
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -5
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +2 -7
- data/lib/capybara/selenium/extensions/html5_drag.rb +5 -4
- data/lib/capybara/selenium/node.rb +60 -38
- data/lib/capybara/selenium/nodes/chrome_node.rb +4 -16
- data/lib/capybara/selenium/nodes/edge_node.rb +19 -13
- data/lib/capybara/selenium/nodes/firefox_node.rb +3 -3
- data/lib/capybara/selenium/nodes/safari_node.rb +4 -4
- data/lib/capybara/selenium/patches/atoms.rb +1 -1
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -1
- data/lib/capybara/server/animation_disabler.rb +40 -23
- data/lib/capybara/server/middleware.rb +1 -1
- data/lib/capybara/server.rb +1 -1
- data/lib/capybara/session/config.rb +4 -2
- data/lib/capybara/session.rb +34 -34
- data/lib/capybara/spec/public/test.js +4 -0
- data/lib/capybara/spec/session/active_element_spec.rb +31 -0
- data/lib/capybara/spec/session/all_spec.rb +11 -15
- data/lib/capybara/spec/session/assert_text_spec.rb +17 -17
- data/lib/capybara/spec/session/attach_file_spec.rb +6 -0
- data/lib/capybara/spec/session/check_spec.rb +10 -0
- data/lib/capybara/spec/session/choose_spec.rb +6 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
- data/lib/capybara/spec/session/click_link_spec.rb +12 -1
- data/lib/capybara/spec/session/current_scope_spec.rb +1 -1
- data/lib/capybara/spec/session/fill_in_spec.rb +6 -0
- data/lib/capybara/spec/session/find_link_spec.rb +10 -0
- data/lib/capybara/spec/session/find_spec.rb +15 -1
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +2 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +5 -5
- data/lib/capybara/spec/session/has_ancestor_spec.rb +2 -2
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +6 -2
- data/lib/capybara/spec/session/has_button_spec.rb +30 -0
- data/lib/capybara/spec/session/has_current_path_spec.rb +3 -3
- data/lib/capybara/spec/session/has_element_spec.rb +47 -0
- data/lib/capybara/spec/session/has_field_spec.rb +25 -1
- data/lib/capybara/spec/session/has_link_spec.rb +40 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
- data/lib/capybara/spec/session/has_select_spec.rb +10 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +15 -0
- data/lib/capybara/spec/session/has_table_spec.rb +13 -2
- data/lib/capybara/spec/session/has_text_spec.rb +6 -14
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -0
- data/lib/capybara/spec/session/node_spec.rb +88 -1
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/reset_session_spec.rb +13 -0
- data/lib/capybara/spec/session/scroll_spec.rb +7 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +1 -1
- data/lib/capybara/spec/session/visit_spec.rb +20 -0
- data/lib/capybara/spec/session/window/window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
- data/lib/capybara/spec/session/within_spec.rb +13 -0
- data/lib/capybara/spec/spec_helper.rb +12 -5
- data/lib/capybara/spec/test_app.rb +91 -14
- data/lib/capybara/spec/views/animated.erb +1 -1
- data/lib/capybara/spec/views/form.erb +34 -4
- data/lib/capybara/spec/views/frame_child.erb +1 -1
- data/lib/capybara/spec/views/frame_one.erb +1 -1
- data/lib/capybara/spec/views/frame_parent.erb +1 -1
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +2 -1
- data/lib/capybara/spec/views/layout.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +1 -1
- data/lib/capybara/spec/views/offset.erb +2 -1
- data/lib/capybara/spec/views/path.erb +2 -2
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/react.erb +2 -2
- data/lib/capybara/spec/views/scroll.erb +2 -1
- data/lib/capybara/spec/views/spatial.erb +1 -1
- data/lib/capybara/spec/views/with_animation.erb +2 -3
- data/lib/capybara/spec/views/with_base_tag.erb +2 -2
- data/lib/capybara/spec/views/with_dragula.erb +2 -2
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
- data/lib/capybara/spec/views/with_hover.erb +2 -2
- data/lib/capybara/spec/views/with_html.erb +5 -3
- data/lib/capybara/spec/views/with_jquery_animation.erb +1 -1
- data/lib/capybara/spec/views/with_js.erb +2 -3
- data/lib/capybara/spec/views/with_jstree.erb +1 -1
- data/lib/capybara/spec/views/with_namespace.erb +1 -0
- data/lib/capybara/spec/views/with_scope.erb +2 -2
- data/lib/capybara/spec/views/with_shadow.erb +31 -0
- data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +2 -2
- data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
- data/lib/capybara/spec/views/with_windows.erb +1 -1
- data/lib/capybara/spec/views/within_frames.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +1 -1
- data/lib/capybara.rb +30 -30
- data/spec/basic_node_spec.rb +16 -3
- data/spec/capybara_spec.rb +12 -0
- data/spec/counter_spec.rb +35 -0
- data/spec/css_builder_spec.rb +1 -1
- data/spec/css_splitter_spec.rb +1 -1
- data/spec/dsl_spec.rb +5 -3
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
- data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
- data/spec/minitest_spec.rb +12 -1
- data/spec/minitest_spec_spec.rb +4 -0
- data/spec/per_session_config_spec.rb +1 -1
- data/spec/rack_test_spec.rb +30 -12
- data/spec/result_spec.rb +41 -35
- data/spec/rspec/features_spec.rb +3 -3
- data/spec/rspec/scenarios_spec.rb +2 -2
- data/spec/rspec/shared_spec_matchers.rb +27 -3
- data/spec/rspec_matchers_spec.rb +25 -0
- data/spec/rspec_spec.rb +3 -3
- data/spec/sauce_spec_chrome.rb +5 -5
- data/spec/selector_spec.rb +4 -4
- data/spec/selenium_spec_chrome.rb +20 -18
- data/spec/selenium_spec_chrome_remote.rb +15 -19
- data/spec/selenium_spec_edge.rb +19 -6
- data/spec/selenium_spec_firefox.rb +26 -8
- data/spec/selenium_spec_firefox_remote.rb +18 -4
- data/spec/selenium_spec_ie.rb +7 -8
- data/spec/selenium_spec_safari.rb +34 -20
- data/spec/server_spec.rb +19 -7
- data/spec/shared_selenium_node.rb +0 -4
- data/spec/shared_selenium_session.rb +22 -14
- data/spec/spec_helper.rb +36 -3
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +1 -1
- metadata +49 -30
- data/lib/capybara/selenium/logger_suppressor.rb +0 -34
- data/lib/capybara/selenium/patches/action_pauser.rb +0 -26
- data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
2
3
|
<head>
|
3
4
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
4
5
|
<title>with_sortable_js</title>
|
@@ -18,4 +19,3 @@
|
|
18
19
|
</script>
|
19
20
|
</body>
|
20
21
|
</html>
|
21
|
-
|
data/lib/capybara/version.rb
CHANGED
data/lib/capybara/window.rb
CHANGED
data/lib/capybara.rb
CHANGED
@@ -39,7 +39,7 @@ module Capybara
|
|
39
39
|
# See {Capybara.configure}
|
40
40
|
# @!method javascript_driver
|
41
41
|
# See {Capybara.configure}
|
42
|
-
# @!method
|
42
|
+
# @!method use_html5_parsing
|
43
43
|
# See {Capybara.configure}
|
44
44
|
Config::OPTIONS.each do |method|
|
45
45
|
def_delegators :config, method, "#{method}="
|
@@ -69,7 +69,7 @@ module Capybara
|
|
69
69
|
#
|
70
70
|
# #### Configurable options
|
71
71
|
#
|
72
|
-
# - **
|
72
|
+
# - **use_html5_parsing** (Boolean = `false`) - When Nokogiri >= 1.12.0 or `nokogumbo` is installed, whether HTML5 parsing will be used for HTML strings.
|
73
73
|
# - **always_include_port** (Boolean = `false`) - Whether the Rack server's port should automatically be inserted into every visited URL
|
74
74
|
# unless another port is explicitly specified.
|
75
75
|
# - **app_host** (String, `nil`) - The default host to use when giving a relative URL to visit, must be a valid URL e.g. `http://www.example.com`.
|
@@ -79,6 +79,7 @@ module Capybara
|
|
79
79
|
# - **automatic_reload** (Boolean = `true`) - Whether to automatically reload elements as Capybara is waiting.
|
80
80
|
# - **default_max_wait_time** (Numeric = `2`) - The maximum number of seconds to wait for asynchronous processes to finish.
|
81
81
|
# - **default_normalize_ws** (Boolean = `false`) - Whether text predicates and matchers use normalize whitespace behavior.
|
82
|
+
# - **default_retry_interval** (Numeric = `0.01`) - The number of seconds to delay the next check in asynchronous processes.
|
82
83
|
# - **default_selector** (`:css`, `:xpath` = `:css`) - Methods which take a selector use the given type by default. See also {Capybara::Selector}.
|
83
84
|
# - **default_set_options** (Hash = `{}`) - The default options passed to {Capybara::Node::Element#set Element#set}.
|
84
85
|
# - **enable_aria_label** (Boolean = `false`) - Whether fields, links, and buttons will match against `aria-label` attribute.
|
@@ -96,11 +97,12 @@ module Capybara
|
|
96
97
|
# {Capybara::Session#save_and_open_page save_and_open_page}, or {Capybara::Session#save_and_open_screenshot save_and_open_screenshot}.
|
97
98
|
# - **server** (Symbol = `:default` (which uses puma)) - The name of the registered server to use when running the app under test.
|
98
99
|
# - **server_port** (Integer) - The port Capybara will run the application server on, if not specified a random port will be used.
|
100
|
+
# - **server_host** (String = "127.0.0.1") - The IP address Capybara will bind the application server to. If the test application is to be accessed from an external host, you will want to change this to "0.0.0.0" or to a more specific IP address that your test client can reach.
|
99
101
|
# - **server_errors** (Array\<Class> = `[Exception]`) - Error classes that should be raised in the tests if they are raised in the server
|
100
102
|
# and {configure raise_server_errors} is `true`.
|
101
103
|
# - **test_id** (Symbol, String, `nil` = `nil`) - Optional attribute to match locator against with built-in selectors along with id.
|
102
104
|
# - **threadsafe** (Boolean = `false`) - Whether sessions can be configured individually.
|
103
|
-
# - **w3c_click_offset** (Boolean = '
|
105
|
+
# - **w3c_click_offset** (Boolean = 'true') - Whether click offsets should be from element center (true) or top left (false)
|
104
106
|
#
|
105
107
|
# #### DSL Options
|
106
108
|
#
|
@@ -258,7 +260,7 @@ module Capybara
|
|
258
260
|
#
|
259
261
|
def current_driver
|
260
262
|
if threadsafe
|
261
|
-
Thread.current
|
263
|
+
Thread.current.thread_variable_get :capybara_current_driver
|
262
264
|
else
|
263
265
|
@current_driver
|
264
266
|
end || default_driver
|
@@ -267,7 +269,7 @@ module Capybara
|
|
267
269
|
|
268
270
|
def current_driver=(name)
|
269
271
|
if threadsafe
|
270
|
-
Thread.current
|
272
|
+
Thread.current.thread_variable_set :capybara_current_driver, name
|
271
273
|
else
|
272
274
|
@current_driver = name
|
273
275
|
end
|
@@ -334,7 +336,8 @@ module Capybara
|
|
334
336
|
#
|
335
337
|
def session_name
|
336
338
|
if threadsafe
|
337
|
-
Thread.current
|
339
|
+
Thread.current.thread_variable_get(:capybara_session_name) ||
|
340
|
+
Thread.current.thread_variable_set(:capybara_session_name, :default)
|
338
341
|
else
|
339
342
|
@session_name ||= :default
|
340
343
|
end
|
@@ -342,7 +345,7 @@ module Capybara
|
|
342
345
|
|
343
346
|
def session_name=(name)
|
344
347
|
if threadsafe
|
345
|
-
Thread.current
|
348
|
+
Thread.current.thread_variable_set :capybara_session_name, name
|
346
349
|
else
|
347
350
|
@session_name = name
|
348
351
|
end
|
@@ -385,26 +388,21 @@ module Capybara
|
|
385
388
|
# @return [Nokogiri::HTML::Document] HTML document
|
386
389
|
#
|
387
390
|
def HTML(html) # rubocop:disable Naming/MethodName
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
# template elements content is not part of the document
|
392
|
-
template.inner_html = ''
|
393
|
-
end
|
394
|
-
document.xpath('//textarea').each do |textarea|
|
395
|
-
# The Nokogumbo HTML5 parser already returns spec compliant contents
|
396
|
-
textarea['_capybara_raw_value'] = textarea.content
|
397
|
-
end
|
398
|
-
end
|
391
|
+
# Nokogiri >= 1.12.0 or Nokogumbo installed and allowed for use
|
392
|
+
html_parser, using_html5 = if defined?(Nokogiri::HTML5) && Capybara.use_html5_parsing
|
393
|
+
[Nokogiri::HTML5, true]
|
399
394
|
else
|
400
|
-
Nokogiri::
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
395
|
+
[defined?(Nokogiri::HTML4) ? Nokogiri::HTML4 : Nokogiri::HTML, false]
|
396
|
+
end
|
397
|
+
|
398
|
+
html_parser.parse(html).tap do |document|
|
399
|
+
document.xpath('//template').each do |template|
|
400
|
+
# template elements content is not part of the document
|
401
|
+
template.inner_html = ''
|
402
|
+
end
|
403
|
+
document.xpath('//textarea').each do |textarea|
|
404
|
+
# The Nokogiri HTML5 parser already returns spec compliant contents
|
405
|
+
textarea['_capybara_raw_value'] = using_html5 ? textarea.content : textarea.content.delete_prefix("\n")
|
408
406
|
end
|
409
407
|
end
|
410
408
|
end
|
@@ -427,7 +425,7 @@ module Capybara
|
|
427
425
|
|
428
426
|
def specified_session
|
429
427
|
if threadsafe
|
430
|
-
Thread.current
|
428
|
+
Thread.current.thread_variable_get :capybara_specified_session
|
431
429
|
else
|
432
430
|
@specified_session ||= nil
|
433
431
|
end
|
@@ -435,7 +433,7 @@ module Capybara
|
|
435
433
|
|
436
434
|
def specified_session=(session)
|
437
435
|
if threadsafe
|
438
|
-
Thread.current
|
436
|
+
Thread.current.thread_variable_set :capybara_specified_session, session
|
439
437
|
else
|
440
438
|
@specified_session = session
|
441
439
|
end
|
@@ -467,6 +465,7 @@ module Capybara
|
|
467
465
|
require 'capybara/queries/ancestor_query'
|
468
466
|
require 'capybara/queries/sibling_query'
|
469
467
|
require 'capybara/queries/style_query'
|
468
|
+
require 'capybara/queries/active_element_query'
|
470
469
|
|
471
470
|
require 'capybara/node/finders'
|
472
471
|
require 'capybara/node/matchers'
|
@@ -499,6 +498,7 @@ Capybara.configure do |config|
|
|
499
498
|
config.server = :default
|
500
499
|
config.default_selector = :css
|
501
500
|
config.default_max_wait_time = 2
|
501
|
+
config.default_retry_interval = 0.01
|
502
502
|
config.ignore_hidden_elements = true
|
503
503
|
config.default_host = 'http://www.example.com'
|
504
504
|
config.automatic_reload = true
|
@@ -516,6 +516,6 @@ Capybara.configure do |config|
|
|
516
516
|
config.test_id = nil
|
517
517
|
config.predicates_wait = true
|
518
518
|
config.default_normalize_ws = false
|
519
|
-
config.
|
520
|
-
config.w3c_click_offset =
|
519
|
+
config.use_html5_parsing = false
|
520
|
+
config.w3c_click_offset = true
|
521
521
|
end
|
data/spec/basic_node_spec.rb
CHANGED
@@ -111,14 +111,27 @@ RSpec.describe Capybara do
|
|
111
111
|
expect(string.find('//form/input[@name="meh"]')).not_to be_disabled
|
112
112
|
end
|
113
113
|
|
114
|
+
it 'allows finding siblings' do
|
115
|
+
h1 = string.find(:css, 'h1')
|
116
|
+
expect(h1).to have_sibling(:css, 'p', text: 'Yes it is')
|
117
|
+
expect(h1).not_to have_sibling(:css, 'p', text: 'Jonas Nicklas')
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'allows finding ancestor' do
|
121
|
+
h1 = string.find(:css, 'h1')
|
122
|
+
expect(h1).to have_ancestor(:css, '#content')
|
123
|
+
expect(h1).not_to have_ancestor(:css, '#footer')
|
124
|
+
end
|
125
|
+
|
114
126
|
it 'drops illegal fragments when using gumbo' do
|
115
127
|
skip 'libxml is less strict than Gumbo' unless Nokogiri.respond_to?(:HTML5)
|
128
|
+
described_class.use_html5_parsing = true
|
116
129
|
expect(described_class.string('<td>1</td>')).not_to have_css('td')
|
117
130
|
end
|
118
131
|
|
119
|
-
it 'can disable use of
|
120
|
-
skip "Test doesn't make sense unlesss
|
121
|
-
described_class.
|
132
|
+
it 'can disable use of HTML5 parsing' do
|
133
|
+
skip "Test doesn't make sense unlesss HTML5 parsing is loaded (Nokogumbo or Nokogiri >= 1.12.0)" unless Nokogiri.respond_to?(:HTML5)
|
134
|
+
described_class.use_html5_parsing = false
|
122
135
|
expect(described_class.string('<td>1</td>')).to have_css('td')
|
123
136
|
end
|
124
137
|
|
data/spec/capybara_spec.rb
CHANGED
@@ -15,6 +15,18 @@ RSpec.describe Capybara do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
describe 'default_retry_interval' do
|
19
|
+
before { @previous_default_interval = described_class.default_retry_interval }
|
20
|
+
|
21
|
+
after { described_class.default_retry_interval = @previous_default_interval } # rubocop:disable RSpec/InstanceVariable
|
22
|
+
|
23
|
+
it 'should be changeable' do
|
24
|
+
expect(described_class.default_retry_interval).not_to eq(0.1)
|
25
|
+
described_class.default_retry_interval = 0.1
|
26
|
+
expect(described_class.default_retry_interval).to eq(0.1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
18
30
|
describe '.register_driver' do
|
19
31
|
it 'should add a new driver' do
|
20
32
|
described_class.register_driver :schmoo do |app|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Capybara::Server::Middleware::Counter do
|
6
|
+
let(:counter) { described_class.new }
|
7
|
+
let(:uri) { '/example' }
|
8
|
+
|
9
|
+
describe '#increment' do
|
10
|
+
it 'successfully' do
|
11
|
+
counter.increment(uri)
|
12
|
+
expect(counter).to be_positive
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#decrement' do
|
17
|
+
before do
|
18
|
+
counter.increment(uri)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'successfully' do
|
22
|
+
it 'with same uri' do
|
23
|
+
expect(counter).to be_positive
|
24
|
+
counter.decrement(uri)
|
25
|
+
expect(counter).not_to be_positive
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'with changed uri' do
|
29
|
+
expect(counter).to be_positive
|
30
|
+
counter.decrement('/')
|
31
|
+
expect(counter).not_to be_positive
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/css_builder_spec.rb
CHANGED
data/spec/css_splitter_spec.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -8,13 +8,15 @@ class TestClass
|
|
8
8
|
end
|
9
9
|
|
10
10
|
Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
|
11
|
-
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation shadow_dom
|
11
|
+
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation shadow_dom active_element
|
12
12
|
] do |example|
|
13
13
|
case example.metadata[:full_description]
|
14
14
|
when /has_css\? should support case insensitive :class and :id options/
|
15
15
|
pending "Nokogiri doesn't support case insensitive CSS attribute matchers"
|
16
16
|
when /#click_button should follow permanent redirects that maintain method/
|
17
17
|
pending "Rack < 2 doesn't support 308" if Gem.loaded_specs['rack'].version < Gem::Version.new('2.0.0')
|
18
|
+
when /#attach_file with multipart form should send prior hidden field if no file submitted/
|
19
|
+
skip 'Rack-test < 2 needs an empty file to detect multipart form' if Gem.loaded_specs['rack-test'].version < Gem::Version.new('2.0.0')
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -115,7 +117,7 @@ RSpec.describe Capybara::DSL do
|
|
115
117
|
it 'should yield the passed block' do
|
116
118
|
called = false
|
117
119
|
Capybara.using_driver(:selenium) { called = true }
|
118
|
-
expect(called).to
|
120
|
+
expect(called).to be(true)
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
@@ -220,7 +222,7 @@ RSpec.describe Capybara::DSL do
|
|
220
222
|
it 'should yield the passed block' do
|
221
223
|
called = false
|
222
224
|
Capybara.using_session(:administrator) { called = true }
|
223
|
-
expect(called).to
|
225
|
+
expect(called).to be(true)
|
224
226
|
end
|
225
227
|
|
226
228
|
it 'should be nestable' do
|
@@ -5,9 +5,9 @@ require 'selenium-webdriver'
|
|
5
5
|
|
6
6
|
RSpec.describe Capybara::Selenium::Driver do
|
7
7
|
it 'should exit with a non-zero exit status' do
|
8
|
-
options = { browser: (
|
8
|
+
options = { browser: ENV.fetch('SELENIUM_BROWSER', :firefox).to_sym }
|
9
9
|
browser = described_class.new(TestApp, options).browser
|
10
10
|
expect(browser).to be_truthy
|
11
|
-
expect(true).to
|
11
|
+
expect(true).to be(false) # rubocop:disable RSpec/ExpectActual
|
12
12
|
end
|
13
13
|
end
|
@@ -5,9 +5,9 @@ require 'selenium-webdriver'
|
|
5
5
|
|
6
6
|
RSpec.describe Capybara::Selenium::Driver do
|
7
7
|
it 'should exit with a zero exit status' do
|
8
|
-
options = { browser: (
|
8
|
+
options = { browser: ENV.fetch('SELENIUM_BROWSER', :firefox).to_sym }
|
9
9
|
browser = described_class.new(TestApp, **options).browser
|
10
10
|
expect(browser).to be_truthy
|
11
|
-
expect(true).to
|
11
|
+
expect(true).to be(true) # rubocop:disable RSpec/ExpectActual,RSpec/IdenticalEqualityAssertion
|
12
12
|
end
|
13
13
|
end
|
data/spec/minitest_spec.rb
CHANGED
@@ -15,6 +15,10 @@ class MinitestTest < Minitest::Test
|
|
15
15
|
Capybara.reset_sessions!
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.test_order
|
19
|
+
:sorted
|
20
|
+
end
|
21
|
+
|
18
22
|
def test_assert_text
|
19
23
|
assert_text('Form', normalize_ws: false)
|
20
24
|
assert_no_text('Not on the page')
|
@@ -56,6 +60,13 @@ class MinitestTest < Minitest::Test
|
|
56
60
|
refute_selector(:css, 'select#not_form_title')
|
57
61
|
end
|
58
62
|
|
63
|
+
def test_assert_element
|
64
|
+
visit('/with_html')
|
65
|
+
assert_element('a', text: 'A link')
|
66
|
+
assert_element(count: 1) { |el| el.text == 'A link' }
|
67
|
+
assert_no_element(text: 'Not on page')
|
68
|
+
end
|
69
|
+
|
59
70
|
def test_assert_link
|
60
71
|
visit('/with_html')
|
61
72
|
assert_link('A link')
|
@@ -159,6 +170,6 @@ RSpec.describe 'capybara/minitest' do
|
|
159
170
|
reporter.start
|
160
171
|
MinitestTest.run reporter, {}
|
161
172
|
reporter.report
|
162
|
-
expect(output.string).to include('
|
173
|
+
expect(output.string).to include('23 runs, 56 assertions, 0 failures, 0 errors, 1 skips')
|
163
174
|
end
|
164
175
|
end
|
data/spec/minitest_spec_spec.rb
CHANGED
@@ -12,7 +12,7 @@ RSpec.describe Capybara::SessionConfig do
|
|
12
12
|
default_selector default_max_wait_time ignore_hidden_elements
|
13
13
|
automatic_reload match exact raise_server_errors visible_text_only
|
14
14
|
automatic_label_click enable_aria_label save_path
|
15
|
-
asset_host].each do |m|
|
15
|
+
asset_host default_retry_interval].each do |m|
|
16
16
|
expect(session.config.public_send(m)).to eq Capybara.public_send(m)
|
17
17
|
end
|
18
18
|
end
|
data/spec/rack_test_spec.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
nokogumbo_required = begin
|
5
|
-
require 'nokogumbo'
|
6
|
-
true
|
7
|
-
rescue LoadError
|
8
|
-
false
|
9
|
-
end
|
10
4
|
|
11
5
|
module TestSessions
|
12
6
|
RackTest = Capybara::Session.new(:rack_test, TestApp)
|
@@ -28,6 +22,7 @@ skipped_tests = %i[
|
|
28
22
|
spatial
|
29
23
|
html_validation
|
30
24
|
shadow_dom
|
25
|
+
active_element
|
31
26
|
]
|
32
27
|
Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
|
33
28
|
case example.metadata[:full_description]
|
@@ -35,6 +30,8 @@ Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip
|
|
35
30
|
skip "Nokogiri doesn't support case insensitive CSS attribute matchers"
|
36
31
|
when /#click_button should follow permanent redirects that maintain method/
|
37
32
|
skip "Rack < 2 doesn't support 308" if Gem.loaded_specs['rack'].version < Gem::Version.new('2.0.0')
|
33
|
+
when /#attach_file with multipart form should send prior hidden field if no file submitted/
|
34
|
+
skip 'Rack-test < 2 needs an empty file to detect multipart form' if Gem.loaded_specs['rack-test'].version < Gem::Version.new('2.0.0')
|
38
35
|
end
|
39
36
|
end
|
40
37
|
|
@@ -98,6 +95,12 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
|
|
98
95
|
session.click_button('Upload Empty')
|
99
96
|
expect(session.html).to include('Successfully ignored empty file field.')
|
100
97
|
end
|
98
|
+
|
99
|
+
it 'should submit multipart even if no file is submitted' do
|
100
|
+
session.visit('/form')
|
101
|
+
session.click_button('Upload Empty')
|
102
|
+
expect(session.html).to include('Content type was multipart/form-data;')
|
103
|
+
end
|
101
104
|
end
|
102
105
|
|
103
106
|
it 'should not submit an obsolete mime type' do
|
@@ -153,6 +156,14 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
|
|
153
156
|
end
|
154
157
|
end
|
155
158
|
|
159
|
+
describe '#active_element' do
|
160
|
+
it 'raises an UnsupportedMethodError' do
|
161
|
+
session.visit('/form')
|
162
|
+
|
163
|
+
expect { session.active_element }.to raise_error(Capybara::NotSupportedByDriverError)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
156
167
|
describe '#text' do
|
157
168
|
it 'should return original text content for textareas' do
|
158
169
|
session.visit('/with_html')
|
@@ -209,15 +220,21 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
209
220
|
driver = described_class.new(TestApp)
|
210
221
|
|
211
222
|
driver.visit('/redirect')
|
212
|
-
expect(driver.response.
|
223
|
+
expect(driver.response.headers['Location']).to be_nil
|
213
224
|
expect(driver.current_url).to match %r{/landed$}
|
214
225
|
end
|
215
226
|
|
227
|
+
it 'should not include fragments in the referer header' do
|
228
|
+
driver.visit('/header_links#an-anchor')
|
229
|
+
driver.find_xpath('.//input').first.click
|
230
|
+
expect(driver.request.get_header('HTTP_REFERER')).to eq('http://www.example.com/header_links')
|
231
|
+
end
|
232
|
+
|
216
233
|
it 'is possible to not follow redirects' do
|
217
234
|
driver = described_class.new(TestApp, follow_redirects: false)
|
218
235
|
|
219
236
|
driver.visit('/redirect')
|
220
|
-
expect(driver.response.
|
237
|
+
expect(driver.response.headers['Location']).to match %r{/redirect_again$}
|
221
238
|
expect(driver.current_url).to match %r{/redirect$}
|
222
239
|
end
|
223
240
|
end
|
@@ -256,11 +273,12 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
256
273
|
end
|
257
274
|
|
258
275
|
RSpec.describe 'Capybara::String' do
|
259
|
-
it 'should use
|
260
|
-
skip 'Only
|
261
|
-
|
276
|
+
it 'should use HTML5 parsing' do
|
277
|
+
skip 'Only valid if Nokogiri >= 1.12.0 or gumbo is included' unless defined? Nokogiri::HTML5
|
278
|
+
Capybara.use_html5_parsing = true
|
279
|
+
allow(Nokogiri::HTML5).to receive(:parse).and_call_original
|
262
280
|
Capybara.string('<div id=test_div></div>')
|
263
|
-
expect(Nokogiri).to have_received(:
|
281
|
+
expect(Nokogiri::HTML5).to have_received(:parse)
|
264
282
|
end
|
265
283
|
end
|
266
284
|
|