capybara 3.8.1 → 3.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/History.md +465 -0
- data/License.txt +1 -1
- data/README.md +58 -57
- data/lib/capybara/config.rb +10 -4
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +2 -2
- data/lib/capybara/driver/node.rb +26 -5
- data/lib/capybara/dsl.rb +12 -4
- data/lib/capybara/helpers.rb +8 -4
- data/lib/capybara/minitest/spec.rb +162 -85
- data/lib/capybara/minitest.rb +248 -148
- data/lib/capybara/node/actions.rb +149 -96
- data/lib/capybara/node/base.rb +27 -10
- data/lib/capybara/node/document.rb +12 -0
- data/lib/capybara/node/document_matchers.rb +9 -5
- data/lib/capybara/node/element.rb +254 -109
- data/lib/capybara/node/finders.rb +83 -76
- data/lib/capybara/node/matchers.rb +279 -141
- data/lib/capybara/node/simple.rb +25 -6
- data/lib/capybara/queries/ancestor_query.rb +5 -7
- data/lib/capybara/queries/base_query.rb +11 -5
- data/lib/capybara/queries/current_path_query.rb +3 -3
- data/lib/capybara/queries/match_query.rb +1 -0
- data/lib/capybara/queries/selector_query.rb +467 -103
- data/lib/capybara/queries/sibling_query.rb +5 -4
- data/lib/capybara/queries/style_query.rb +6 -2
- data/lib/capybara/queries/text_query.rb +17 -3
- data/lib/capybara/queries/title_query.rb +2 -2
- data/lib/capybara/rack_test/browser.rb +22 -15
- data/lib/capybara/rack_test/driver.rb +10 -1
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +33 -28
- data/lib/capybara/rack_test/node.rb +74 -6
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +36 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
- data/lib/capybara/registrations/servers.rb +44 -0
- data/lib/capybara/result.rb +55 -23
- data/lib/capybara/rspec/features.rb +4 -4
- data/lib/capybara/rspec/matcher_proxies.rb +36 -15
- data/lib/capybara/rspec/matchers/base.rb +111 -0
- data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
- data/lib/capybara/rspec/matchers/compound.rb +88 -0
- data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
- data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
- data/lib/capybara/rspec/matchers/have_selector.rb +77 -0
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +33 -0
- data/lib/capybara/rspec/matchers/have_title.rb +29 -0
- data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
- data/lib/capybara/rspec/matchers/match_style.rb +38 -0
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +117 -311
- data/lib/capybara/selector/builders/css_builder.rb +84 -0
- data/lib/capybara/selector/builders/xpath_builder.rb +69 -0
- data/lib/capybara/selector/css.rb +17 -15
- data/lib/capybara/selector/definition/button.rb +52 -0
- data/lib/capybara/selector/definition/checkbox.rb +26 -0
- data/lib/capybara/selector/definition/css.rb +10 -0
- data/lib/capybara/selector/definition/datalist_input.rb +35 -0
- data/lib/capybara/selector/definition/datalist_option.rb +25 -0
- data/lib/capybara/selector/definition/element.rb +27 -0
- data/lib/capybara/selector/definition/field.rb +40 -0
- data/lib/capybara/selector/definition/fieldset.rb +14 -0
- data/lib/capybara/selector/definition/file_field.rb +13 -0
- data/lib/capybara/selector/definition/fillable_field.rb +33 -0
- data/lib/capybara/selector/definition/frame.rb +17 -0
- data/lib/capybara/selector/definition/id.rb +6 -0
- data/lib/capybara/selector/definition/label.rb +62 -0
- data/lib/capybara/selector/definition/link.rb +54 -0
- data/lib/capybara/selector/definition/link_or_button.rb +16 -0
- data/lib/capybara/selector/definition/option.rb +27 -0
- data/lib/capybara/selector/definition/radio_button.rb +27 -0
- data/lib/capybara/selector/definition/select.rb +81 -0
- data/lib/capybara/selector/definition/table.rb +109 -0
- data/lib/capybara/selector/definition/table_row.rb +21 -0
- data/lib/capybara/selector/definition/xpath.rb +5 -0
- data/lib/capybara/selector/definition.rb +277 -0
- data/lib/capybara/selector/filter.rb +1 -0
- data/lib/capybara/selector/filter_set.rb +26 -19
- data/lib/capybara/selector/filters/base.rb +24 -5
- data/lib/capybara/selector/filters/expression_filter.rb +3 -3
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +16 -2
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +73 -367
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +221 -480
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
- data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
- data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
- data/lib/capybara/selenium/driver.rb +203 -86
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +88 -14
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +89 -0
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +110 -0
- data/lib/capybara/selenium/extensions/html5_drag.rb +191 -22
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +78 -0
- data/lib/capybara/selenium/logger_suppressor.rb +34 -0
- data/lib/capybara/selenium/node.rb +298 -93
- data/lib/capybara/selenium/nodes/chrome_node.rb +100 -8
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +131 -0
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +18 -0
- data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
- data/lib/capybara/selenium/patches/logs.rb +45 -0
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -3
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +4 -3
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +23 -13
- data/lib/capybara/server.rb +30 -7
- data/lib/capybara/session/config.rb +14 -10
- data/lib/capybara/session/matchers.rb +11 -7
- data/lib/capybara/session.rb +152 -111
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +101 -10
- data/lib/capybara/spec/session/all_spec.rb +96 -6
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +29 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_selector_spec.rb +0 -10
- data/lib/capybara/spec/session/assert_style_spec.rb +4 -4
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/attach_file_spec.rb +63 -36
- data/lib/capybara/spec/session/check_spec.rb +10 -4
- data/lib/capybara/spec/session/choose_spec.rb +8 -2
- data/lib/capybara/spec/session/click_button_spec.rb +117 -61
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +16 -0
- data/lib/capybara/spec/session/click_link_spec.rb +17 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
- data/lib/capybara/spec/session/evaluate_script_spec.rb +13 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +47 -6
- data/lib/capybara/spec/session/find_field_spec.rb +1 -1
- data/lib/capybara/spec/session/find_spec.rb +74 -4
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +13 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +1 -1
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +25 -0
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +122 -12
- data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
- data/lib/capybara/spec/session/has_field_spec.rb +55 -0
- data/lib/capybara/spec/session/has_select_spec.rb +34 -6
- data/lib/capybara/spec/session/has_selector_spec.rb +11 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +166 -0
- data/lib/capybara/spec/session/has_text_spec.rb +48 -1
- data/lib/capybara/spec/session/has_xpath_spec.rb +17 -0
- data/lib/capybara/spec/session/html_spec.rb +7 -0
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +643 -18
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/refresh_spec.rb +4 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +23 -8
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +117 -0
- data/lib/capybara/spec/session/select_spec.rb +10 -10
- data/lib/capybara/spec/session/selectors_spec.rb +36 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_spec.rb +59 -58
- data/lib/capybara/spec/session/window/windows_spec.rb +4 -0
- data/lib/capybara/spec/session/within_spec.rb +23 -0
- data/lib/capybara/spec/spec_helper.rb +16 -6
- data/lib/capybara/spec/test_app.rb +28 -23
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +48 -7
- data/lib/capybara/spec/views/frame_child.erb +3 -2
- data/lib/capybara/spec/views/frame_one.erb +1 -0
- data/lib/capybara/spec/views/obscured.erb +47 -0
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/scroll.erb +20 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/tables.erb +67 -0
- data/lib/capybara/spec/views/with_animation.erb +29 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_hover.erb +1 -0
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +32 -6
- data/lib/capybara/spec/views/with_js.erb +3 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +11 -11
- data/lib/capybara.rb +118 -111
- data/spec/basic_node_spec.rb +14 -3
- data/spec/capybara_spec.rb +29 -29
- data/spec/css_builder_spec.rb +101 -0
- data/spec/dsl_spec.rb +46 -21
- data/spec/filter_set_spec.rb +5 -5
- data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +18 -4
- data/spec/minitest_spec_spec.rb +59 -44
- data/spec/rack_test_spec.rb +117 -89
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +51 -49
- data/spec/rspec/features_spec.rb +3 -0
- data/spec/rspec/shared_spec_matchers.rb +112 -97
- data/spec/rspec_spec.rb +35 -17
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +244 -28
- data/spec/selenium_spec_chrome.rb +125 -54
- data/spec/selenium_spec_chrome_remote.rb +26 -12
- data/spec/selenium_spec_edge.rb +23 -8
- data/spec/selenium_spec_firefox.rb +208 -0
- data/spec/selenium_spec_firefox_remote.rb +15 -18
- data/spec/selenium_spec_ie.rb +82 -13
- data/spec/selenium_spec_safari.rb +148 -0
- data/spec/server_spec.rb +118 -77
- data/spec/session_spec.rb +19 -3
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +110 -65
- data/spec/spec_helper.rb +57 -9
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +257 -17
- data/lib/capybara/rspec/compound.rb +0 -94
- data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -49
- data/lib/capybara/selenium/nodes/marionette_node.rb +0 -121
- data/lib/capybara/spec/session/has_style_spec.rb +0 -25
- data/spec/selenium_spec_marionette.rb +0 -172
data/lib/capybara.rb
CHANGED
@@ -5,6 +5,7 @@ require 'nokogiri'
|
|
5
5
|
require 'xpath'
|
6
6
|
require 'forwardable'
|
7
7
|
require 'capybara/config'
|
8
|
+
require 'capybara/registration_container'
|
8
9
|
|
9
10
|
module Capybara
|
10
11
|
class CapybaraError < StandardError; end
|
@@ -38,6 +39,8 @@ module Capybara
|
|
38
39
|
# See {Capybara.configure}
|
39
40
|
# @!method javascript_driver
|
40
41
|
# See {Capybara.configure}
|
42
|
+
# @!method allow_gumbo
|
43
|
+
# See {Capybara.configure}
|
41
44
|
Config::OPTIONS.each do |method|
|
42
45
|
def_delegators :config, method, "#{method}="
|
43
46
|
end
|
@@ -64,35 +67,47 @@ module Capybara
|
|
64
67
|
# config.app_host = 'http://www.google.com'
|
65
68
|
# end
|
66
69
|
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
70
|
+
# #### Configurable options
|
71
|
+
#
|
72
|
+
# - **allow_gumbo** (Boolean = `false`) - When `nokogumbo` is available, whether it will be used to parse HTML strings.
|
73
|
+
# - **always_include_port** (Boolean = `false`) - Whether the Rack server's port should automatically be inserted into every visited URL
|
74
|
+
# unless another port is explicitly specified.
|
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`.
|
76
|
+
# - **asset_host** (String = `nil`) - Where dynamic assets are hosted - will be prepended to relative asset locations if present.
|
77
|
+
# - **automatic_label_click** (Boolean = `false`) - Whether {Capybara::Node::Element#choose Element#choose}, {Capybara::Node::Element#check Element#check},
|
78
|
+
# {Capybara::Node::Element#uncheck Element#uncheck} will attempt to click the associated `<label>` element if the checkbox/radio button are non-visible.
|
79
|
+
# - **automatic_reload** (Boolean = `true`) - Whether to automatically reload elements as Capybara is waiting.
|
80
|
+
# - **default_max_wait_time** (Numeric = `2`) - The maximum number of seconds to wait for asynchronous processes to finish.
|
81
|
+
# - **default_normalize_ws** (Boolean = `false`) - Whether text predicates and matchers use normalize whitespace behavior.
|
82
|
+
# - **default_selector** (`:css`, `:xpath` = `:css`) - Methods which take a selector use the given type by default. See also {Capybara::Selector}.
|
83
|
+
# - **default_set_options** (Hash = `{}`) - The default options passed to {Capybara::Node::Element#set Element#set}.
|
84
|
+
# - **enable_aria_label** (Boolean = `false`) - Whether fields, links, and buttons will match against `aria-label` attribute.
|
85
|
+
# - **enable_aria_role** (Boolean = `false`) - Selectors will check for relevant aria role (currently only `button`).
|
86
|
+
# - **exact** (Boolean = `false`) - Whether locators are matched exactly or with substrings. Only affects selector conditions
|
87
|
+
# written using the `XPath#is` method.
|
88
|
+
# - **exact_text** (Boolean = `false`) - Whether the text matchers and `:text` filter match exactly or on substrings.
|
89
|
+
# - **ignore_hidden_elements** (Boolean = `true`) - Whether to ignore hidden elements on the page.
|
90
|
+
# - **match** (`:one`, `:first`, `:prefer_exact`, `:smart` = `:smart`) - The matching strategy to find nodes.
|
91
|
+
# - **predicates_wait** (Boolean = `true`) - Whether Capybara's predicate matchers use waiting behavior by default.
|
92
|
+
# - **raise_server_errors** (Boolean = `true`) - Should errors raised in the server be raised in the tests?
|
93
|
+
# - **reuse_server** (Boolean = `true`) - Whether to reuse the server thread between multiple sessions using the same app object.
|
94
|
+
# - **run_server** (Boolean = `true`) - Whether to start a Rack server for the given Rack app.
|
95
|
+
# - **save_path** (String = `Dir.pwd`) - Where to put pages saved through {Capybara::Session#save_page save_page}, {Capybara::Session#save_screenshot save_screenshot},
|
96
|
+
# {Capybara::Session#save_and_open_page save_and_open_page}, or {Capybara::Session#save_and_open_screenshot save_and_open_screenshot}.
|
97
|
+
# - **server** (Symbol = `:default` (which uses puma)) - The name of the registered server to use when running the app under test.
|
98
|
+
# - **server_port** (Integer) - The port Capybara will run the application server on, if not specified a random port will be used.
|
99
|
+
# - **server_errors** (Array\<Class> = `[Exception]`) - Error classes that should be raised in the tests if they are raised in the server
|
100
|
+
# and {configure raise_server_errors} is `true`.
|
101
|
+
# - **test_id** (Symbol, String, `nil` = `nil`) - Optional attribute to match locator against with built-in selectors along with id.
|
102
|
+
# - **threadsafe** (Boolean = `false`) - Whether sessions can be configured individually.
|
103
|
+
# - **w3c_click_offset** (Boolean = 'false') - Whether click offsets should be from element center (true) or top left (false)
|
104
|
+
#
|
105
|
+
# #### DSL Options
|
106
|
+
#
|
107
|
+
# When using `capybara/dsl`, the following options are also available:
|
108
|
+
#
|
109
|
+
# - **default_driver** (Symbol = `:rack_test`) - The name of the driver to use by default.
|
110
|
+
# - **javascript_driver** (Symbol = `:selenium`) - The name of a driver to use for JavaScript enabled tests.
|
96
111
|
#
|
97
112
|
def configure
|
98
113
|
yield config
|
@@ -112,7 +127,7 @@ module Capybara
|
|
112
127
|
# @yieldreturn [Capybara::Driver::Base] A Capybara driver instance
|
113
128
|
#
|
114
129
|
def register_driver(name, &block)
|
115
|
-
drivers
|
130
|
+
drivers.send(:register, name, block)
|
116
131
|
end
|
117
132
|
|
118
133
|
##
|
@@ -131,7 +146,7 @@ module Capybara
|
|
131
146
|
# @yieldparam host The host/ip to bind to
|
132
147
|
#
|
133
148
|
def register_server(name, &block)
|
134
|
-
servers
|
149
|
+
servers.send(:register, name.to_sym, block)
|
135
150
|
end
|
136
151
|
|
137
152
|
##
|
@@ -162,8 +177,8 @@ module Capybara
|
|
162
177
|
# @param [Symbol] name The name of the selector to add
|
163
178
|
# @yield A block executed in the context of the new {Capybara::Selector}
|
164
179
|
#
|
165
|
-
def add_selector(name, &block)
|
166
|
-
Capybara::Selector.add(name, &block)
|
180
|
+
def add_selector(name, **options, &block)
|
181
|
+
Capybara::Selector.add(name, **options, &block)
|
167
182
|
end
|
168
183
|
|
169
184
|
##
|
@@ -173,7 +188,7 @@ module Capybara
|
|
173
188
|
# button style (a class) might look like this
|
174
189
|
#
|
175
190
|
# Capybara.modify_selector(:button) do
|
176
|
-
# filter (:
|
191
|
+
# filter (:btn_style, valid_values: [:primary, :secondary]) { |node, style| node[:class].split.include? "btn-#{style}" }
|
177
192
|
# end
|
178
193
|
#
|
179
194
|
#
|
@@ -185,11 +200,11 @@ module Capybara
|
|
185
200
|
end
|
186
201
|
|
187
202
|
def drivers
|
188
|
-
@drivers ||=
|
203
|
+
@drivers ||= RegistrationContainer.new
|
189
204
|
end
|
190
205
|
|
191
206
|
def servers
|
192
|
-
@servers ||=
|
207
|
+
@servers ||= RegistrationContainer.new
|
193
208
|
end
|
194
209
|
|
195
210
|
# Wraps the given string, which should contain an HTML document or fragment
|
@@ -198,15 +213,13 @@ module Capybara
|
|
198
213
|
# any string containing HTML in the exact same way you would query the current document in a Capybara
|
199
214
|
# session.
|
200
215
|
#
|
201
|
-
#
|
202
|
-
#
|
216
|
+
# @example A single element
|
203
217
|
# node = Capybara.string('<a href="foo">bar</a>')
|
204
218
|
# anchor = node.first('a')
|
205
219
|
# anchor[:href] #=> 'foo'
|
206
220
|
# anchor.text #=> 'bar'
|
207
221
|
#
|
208
|
-
#
|
209
|
-
#
|
222
|
+
# @example Multiple elements
|
210
223
|
# node = Capybara.string <<-HTML
|
211
224
|
# <ul>
|
212
225
|
# <li id="home">Home</li>
|
@@ -294,12 +307,12 @@ module Capybara
|
|
294
307
|
|
295
308
|
##
|
296
309
|
#
|
297
|
-
# The current Capybara::Session based on what is set as
|
310
|
+
# The current {Capybara::Session} based on what is set as {app} and {current_driver}.
|
298
311
|
#
|
299
312
|
# @return [Capybara::Session] The currently used session
|
300
313
|
#
|
301
314
|
def current_session
|
302
|
-
session_pool["#{current_driver}:#{session_name}:#{app.object_id}"]
|
315
|
+
specified_session || session_pool["#{current_driver}:#{session_name}:#{app.object_id}"]
|
303
316
|
end
|
304
317
|
|
305
318
|
##
|
@@ -337,22 +350,31 @@ module Capybara
|
|
337
350
|
|
338
351
|
##
|
339
352
|
#
|
340
|
-
# Yield a block using a specific session name.
|
353
|
+
# Yield a block using a specific session name or {Capybara::Session} instance.
|
341
354
|
#
|
342
|
-
def using_session(
|
355
|
+
def using_session(name_or_session, &block)
|
356
|
+
previous_session = current_session
|
343
357
|
previous_session_info = {
|
358
|
+
specified_session: specified_session,
|
344
359
|
session_name: session_name,
|
345
360
|
current_driver: current_driver,
|
346
361
|
app: app
|
347
362
|
}
|
348
|
-
self.session_name =
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
self.current_driver = previous_session_info[:current_driver]
|
354
|
-
self.app = previous_session_info[:app]
|
363
|
+
self.specified_session = self.session_name = nil
|
364
|
+
if name_or_session.is_a? Capybara::Session
|
365
|
+
self.specified_session = name_or_session
|
366
|
+
else
|
367
|
+
self.session_name = name_or_session
|
355
368
|
end
|
369
|
+
|
370
|
+
if block.arity.zero?
|
371
|
+
yield
|
372
|
+
else
|
373
|
+
yield current_session, previous_session
|
374
|
+
end
|
375
|
+
ensure
|
376
|
+
self.session_name, self.specified_session = previous_session_info.values_at(:session_name, :specified_session)
|
377
|
+
self.current_driver, self.app = previous_session_info.values_at(:current_driver, :app) if threadsafe
|
356
378
|
end
|
357
379
|
|
358
380
|
##
|
@@ -363,9 +385,26 @@ module Capybara
|
|
363
385
|
# @return [Nokogiri::HTML::Document] HTML document
|
364
386
|
#
|
365
387
|
def HTML(html) # rubocop:disable Naming/MethodName
|
366
|
-
Nokogiri
|
367
|
-
|
368
|
-
|
388
|
+
if Nokogiri.respond_to?(:HTML5) && Capybara.allow_gumbo # Nokogumbo installed and allowed for use
|
389
|
+
Nokogiri::HTML5(html).tap do |document|
|
390
|
+
document.xpath('//template').each do |template|
|
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
|
399
|
+
else
|
400
|
+
Nokogiri::HTML(html).tap do |document|
|
401
|
+
document.xpath('//template').each do |template|
|
402
|
+
# template elements content is not part of the document
|
403
|
+
template.inner_html = ''
|
404
|
+
end
|
405
|
+
document.xpath('//textarea').each do |textarea|
|
406
|
+
textarea['_capybara_raw_value'] = textarea.content.delete_prefix("\n")
|
407
|
+
end
|
369
408
|
end
|
370
409
|
end
|
371
410
|
end
|
@@ -381,7 +420,25 @@ module Capybara
|
|
381
420
|
end
|
382
421
|
|
383
422
|
def session_pool
|
384
|
-
@session_pool ||=
|
423
|
+
@session_pool ||= Hash.new do |hash, name|
|
424
|
+
hash[name] = Capybara::Session.new(current_driver, app)
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
def specified_session
|
429
|
+
if threadsafe
|
430
|
+
Thread.current['capybara_specified_session']
|
431
|
+
else
|
432
|
+
@specified_session ||= nil
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
def specified_session=(session)
|
437
|
+
if threadsafe
|
438
|
+
Thread.current['capybara_specified_session'] = session
|
439
|
+
else
|
440
|
+
@specified_session = session
|
441
|
+
end
|
385
442
|
end
|
386
443
|
end
|
387
444
|
|
@@ -433,41 +490,8 @@ module Capybara
|
|
433
490
|
require 'capybara/selenium/driver'
|
434
491
|
end
|
435
492
|
|
436
|
-
|
437
|
-
|
438
|
-
end
|
439
|
-
|
440
|
-
Capybara.register_server :webrick do |app, port, host, **options|
|
441
|
-
require 'rack/handler/webrick'
|
442
|
-
Rack::Handler::WEBrick.run(app, { Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log.new(nil, 0) }.merge(options))
|
443
|
-
end
|
444
|
-
|
445
|
-
Capybara.register_server :puma do |app, port, host, **options|
|
446
|
-
begin
|
447
|
-
require 'rack/handler/puma'
|
448
|
-
rescue LoadError
|
449
|
-
raise LoadError, 'Capybara is unable to load `puma` for its server, please add `puma` to your project or specify a different server via something like `Capybara.server = :webrick`.'
|
450
|
-
else
|
451
|
-
unless Rack::Handler::Puma.respond_to?(:config)
|
452
|
-
raise LoadError, 'Capybara requires `puma` version 3.8.0 or higher, please upgrade `puma` or register and specify your own server block'
|
453
|
-
end
|
454
|
-
end
|
455
|
-
# If we just run the Puma Rack handler it installs signal handlers which prevent us from being able to interrupt tests.
|
456
|
-
# Therefore construct and run the Server instance ourselves.
|
457
|
-
# Rack::Handler::Puma.run(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))
|
458
|
-
|
459
|
-
conf = Rack::Handler::Puma.config(app, { Host: host, Port: port, Threads: '0:4', workers: 0, daemon: false }.merge(options))
|
460
|
-
events = conf.options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
|
461
|
-
|
462
|
-
events.log 'Capybara starting Puma...'
|
463
|
-
events.log "* Version #{Puma::Const::PUMA_VERSION} , codename: #{Puma::Const::CODE_NAME}"
|
464
|
-
events.log "* Min threads: #{conf.options[:min_threads]}, max threads: #{conf.options[:max_threads]}"
|
465
|
-
|
466
|
-
Puma::Server.new(conf.app, events, conf.options).tap do |s|
|
467
|
-
s.binder.parse conf.options[:binds], s.events
|
468
|
-
s.min_threads, s.max_threads = conf.options[:min_threads], conf.options[:max_threads]
|
469
|
-
end.run.join
|
470
|
-
end
|
493
|
+
require 'capybara/registrations/servers'
|
494
|
+
require 'capybara/registrations/drivers'
|
471
495
|
|
472
496
|
Capybara.configure do |config|
|
473
497
|
config.always_include_port = false
|
@@ -482,33 +506,16 @@ Capybara.configure do |config|
|
|
482
506
|
config.exact = false
|
483
507
|
config.exact_text = false
|
484
508
|
config.raise_server_errors = true
|
485
|
-
config.server_errors = [
|
509
|
+
config.server_errors = [Exception]
|
486
510
|
config.visible_text_only = false
|
487
511
|
config.automatic_label_click = false
|
488
512
|
config.enable_aria_label = false
|
513
|
+
config.enable_aria_role = false
|
489
514
|
config.reuse_server = true
|
490
515
|
config.default_set_options = {}
|
491
516
|
config.test_id = nil
|
492
517
|
config.predicates_wait = true
|
493
518
|
config.default_normalize_ws = false
|
494
|
-
|
495
|
-
|
496
|
-
Capybara.register_driver :rack_test do |app|
|
497
|
-
Capybara::RackTest::Driver.new(app)
|
498
|
-
end
|
499
|
-
|
500
|
-
Capybara.register_driver :selenium do |app|
|
501
|
-
Capybara::Selenium::Driver.new(app)
|
502
|
-
end
|
503
|
-
|
504
|
-
Capybara.register_driver :selenium_chrome do |app|
|
505
|
-
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
506
|
-
end
|
507
|
-
|
508
|
-
Capybara.register_driver :selenium_chrome_headless do |app|
|
509
|
-
Capybara::Selenium::Driver.load_selenium
|
510
|
-
browser_options = ::Selenium::WebDriver::Chrome::Options.new
|
511
|
-
browser_options.args << '--headless'
|
512
|
-
browser_options.args << '--disable-gpu' if Gem.win_platform?
|
513
|
-
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
|
519
|
+
config.allow_gumbo = false
|
520
|
+
config.w3c_click_offset = false
|
514
521
|
end
|
data/spec/basic_node_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe Capybara do
|
6
6
|
describe '.string' do
|
7
7
|
let :string do
|
8
|
-
|
8
|
+
described_class.string <<-STRING
|
9
9
|
<html>
|
10
10
|
<head>
|
11
11
|
<title>simple_node</title>
|
@@ -52,7 +52,7 @@ RSpec.describe Capybara do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'allows using custom matchers' do
|
55
|
-
|
55
|
+
described_class.add_selector :lifeform do
|
56
56
|
xpath { |name| ".//option[contains(.,'#{name}')]" }
|
57
57
|
end
|
58
58
|
expect(string).to have_selector(:id, 'page')
|
@@ -62,7 +62,7 @@ RSpec.describe Capybara do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'allows custom matcher using css' do
|
65
|
-
|
65
|
+
described_class.add_selector :section do
|
66
66
|
css { |css_class| "section .#{css_class}" }
|
67
67
|
end
|
68
68
|
expect(string).to have_selector(:section, 'subsection')
|
@@ -110,6 +110,17 @@ RSpec.describe Capybara do
|
|
110
110
|
expect(string.find('//form/input[@name="meh"]')).not_to be_disabled
|
111
111
|
end
|
112
112
|
|
113
|
+
it 'drops illegal fragments when using gumbo' do
|
114
|
+
skip 'libxml is less strict than Gumbo' unless Nokogiri.respond_to?(:HTML5)
|
115
|
+
expect(described_class.string('<td>1</td>')).not_to have_css('td')
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'can disable use of gumbo' do
|
119
|
+
skip "Test doesn't make sense unlesss nokogumbo is loaded" unless Nokogiri.respond_to?(:HTML5)
|
120
|
+
described_class.allow_gumbo = false
|
121
|
+
expect(described_class.string('<td>1</td>')).to have_css('td')
|
122
|
+
end
|
123
|
+
|
113
124
|
describe '#title' do
|
114
125
|
it 'returns the page title' do
|
115
126
|
expect(string.title).to eq('simple_node')
|
data/spec/capybara_spec.rb
CHANGED
@@ -4,20 +4,20 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe Capybara do
|
6
6
|
describe 'default_max_wait_time' do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
before { @previous_default_time = described_class.default_max_wait_time }
|
8
|
+
|
9
|
+
after { described_class.default_max_wait_time = @previous_default_time } # rubocop:disable RSpec/InstanceVariable
|
10
10
|
|
11
11
|
it 'should be changeable' do
|
12
|
-
|
13
|
-
|
14
|
-
expect(
|
12
|
+
expect(described_class.default_max_wait_time).not_to eq(5)
|
13
|
+
described_class.default_max_wait_time = 5
|
14
|
+
expect(described_class.default_max_wait_time).to eq(5)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '.register_driver' do
|
19
19
|
it 'should add a new driver' do
|
20
|
-
|
20
|
+
described_class.register_driver :schmoo do |app|
|
21
21
|
Capybara::RackTest::Driver.new(app)
|
22
22
|
end
|
23
23
|
session = Capybara::Session.new(:schmoo, TestApp)
|
@@ -28,85 +28,85 @@ RSpec.describe Capybara do
|
|
28
28
|
|
29
29
|
describe '.register_server' do
|
30
30
|
it 'should add a new server' do
|
31
|
-
|
31
|
+
described_class.register_server :blob do |_app, _port, _host|
|
32
32
|
# do nothing
|
33
33
|
end
|
34
34
|
|
35
|
-
expect(
|
35
|
+
expect(described_class.servers[:blob]).to be_truthy
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '.server' do
|
40
40
|
after do
|
41
|
-
|
41
|
+
described_class.server = :default
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should default to a proc that calls run_default_server' do
|
45
45
|
mock_app = Object.new
|
46
|
-
allow(
|
47
|
-
|
48
|
-
expect(
|
46
|
+
allow(described_class).to receive(:run_default_server).and_return(true)
|
47
|
+
described_class.server.call(mock_app, 8000)
|
48
|
+
expect(described_class).to have_received(:run_default_server).with(mock_app, 8000)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should return a custom server proc' do
|
52
52
|
server = ->(_app, _port) {}
|
53
|
-
|
54
|
-
|
55
|
-
expect(
|
53
|
+
described_class.register_server :custom, &server
|
54
|
+
described_class.server = :custom
|
55
|
+
expect(described_class.server).to eq(server)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should have :webrick registered' do
|
59
|
-
expect(
|
59
|
+
expect(described_class.servers[:webrick]).not_to be_nil
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should have :puma registered' do
|
63
|
-
expect(
|
63
|
+
expect(described_class.servers[:puma]).not_to be_nil
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe 'server=' do
|
68
68
|
after do
|
69
|
-
|
69
|
+
described_class.server = :default
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'accepts a proc' do
|
73
73
|
server = ->(_app, _port) {}
|
74
|
-
|
75
|
-
expect(
|
74
|
+
described_class.server = server
|
75
|
+
expect(described_class.server).to eq server
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe 'app_host' do
|
80
80
|
after do
|
81
|
-
|
81
|
+
described_class.app_host = nil
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'should warn if not a valid URL' do
|
85
|
-
expect {
|
85
|
+
expect { described_class.app_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.app_host should be set to a url/)
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should not warn if a valid URL' do
|
89
|
-
expect {
|
89
|
+
expect { described_class.app_host = 'http://www.example.com' }.not_to raise_error
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should not warn if nil' do
|
93
|
-
expect {
|
93
|
+
expect { described_class.app_host = nil }.not_to raise_error
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe 'default_host' do
|
98
98
|
around do |test|
|
99
|
-
old_default =
|
99
|
+
old_default = described_class.default_host
|
100
100
|
test.run
|
101
|
-
|
101
|
+
described_class.default_host = old_default
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should raise if not a valid URL' do
|
105
|
-
expect {
|
105
|
+
expect { described_class.default_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/)
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should not warn if a valid URL' do
|
109
|
-
expect {
|
109
|
+
expect { described_class.default_host = 'http://www.example.com' }.not_to raise_error
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# rubocop:disable RSpec/InstanceVariable
|
6
|
+
RSpec.describe Capybara::Selector::CSSBuilder do
|
7
|
+
let :builder do
|
8
|
+
::Capybara::Selector::CSSBuilder.new(@css)
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'add_attribute_conditions' do
|
12
|
+
it 'adds a single string condition to a single selector' do
|
13
|
+
@css = 'div'
|
14
|
+
selector = builder.add_attribute_conditions(random: 'abc')
|
15
|
+
expect(selector).to eq %(div[random='abc'])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'adds multiple string conditions to a single selector' do
|
19
|
+
@css = 'div'
|
20
|
+
selector = builder.add_attribute_conditions(random: 'abc', other: 'def')
|
21
|
+
expect(selector).to eq %(div[random='abc'][other='def'])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'adds a single string condition to a multiple selector' do
|
25
|
+
@css = 'div, ul'
|
26
|
+
selector = builder.add_attribute_conditions(random: 'abc')
|
27
|
+
expect(selector).to eq %(div[random='abc'], ul[random='abc'])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'adds multiple string conditions to a multiple selector' do
|
31
|
+
@css = 'div, ul'
|
32
|
+
selector = builder.add_attribute_conditions(random: 'abc', other: 'def')
|
33
|
+
expect(selector).to eq %(div[random='abc'][other='def'], ul[random='abc'][other='def'])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'adds simple regexp conditions to a single selector' do
|
37
|
+
@css = 'div'
|
38
|
+
selector = builder.add_attribute_conditions(random: /abc/, other: /def/)
|
39
|
+
expect(selector).to eq %(div[random*='abc'][other*='def'])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'adds wildcard regexp conditions to a single selector' do
|
43
|
+
@css = 'div'
|
44
|
+
selector = builder.add_attribute_conditions(random: /abc.*def/, other: /def.*ghi/)
|
45
|
+
expect(selector).to eq %(div[random*='abc'][random*='def'][other*='def'][other*='ghi'])
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'adds alternated regexp conditions to a single selector' do
|
49
|
+
@css = 'div'
|
50
|
+
selector = builder.add_attribute_conditions(random: /abc|def/, other: /def|ghi/)
|
51
|
+
expect(selector).to eq %(div[random*='abc'][other*='def'], div[random*='abc'][other*='ghi'], div[random*='def'][other*='def'], div[random*='def'][other*='ghi'])
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'adds alternated regexp conditions to a multiple selector' do
|
55
|
+
@css = 'div,ul'
|
56
|
+
selector = builder.add_attribute_conditions(other: /def.*ghi|jkl/)
|
57
|
+
expect(selector).to eq %(div[other*='def'][other*='ghi'], div[other*='jkl'], ul[other*='def'][other*='ghi'], ul[other*='jkl'])
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns original selector when regexp can't be substringed" do
|
61
|
+
@css = 'div'
|
62
|
+
selector = builder.add_attribute_conditions(other: /.+/)
|
63
|
+
expect(selector).to eq 'div'
|
64
|
+
end
|
65
|
+
|
66
|
+
context ':class' do
|
67
|
+
it 'handles string with CSS .' do
|
68
|
+
@css = 'a'
|
69
|
+
selector = builder.add_attribute_conditions(class: 'my_class')
|
70
|
+
expect(selector).to eq 'a.my_class'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'handles negated string with CSS .' do
|
74
|
+
@css = 'a'
|
75
|
+
selector = builder.add_attribute_conditions(class: '!my_class')
|
76
|
+
expect(selector).to eq 'a:not(.my_class)'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'handles array of string with CSS .' do
|
80
|
+
@css = 'a'
|
81
|
+
selector = builder.add_attribute_conditions(class: %w[my_class my_other_class])
|
82
|
+
expect(selector).to eq 'a.my_class.my_other_class'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'handles array of string with CSS . when negated included' do
|
86
|
+
@css = 'a'
|
87
|
+
selector = builder.add_attribute_conditions(class: %w[my_class !my_other_class])
|
88
|
+
expect(selector).to eq 'a.my_class:not(.my_other_class)'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context ':id' do
|
93
|
+
it 'handles string with CSS #' do
|
94
|
+
@css = 'ul'
|
95
|
+
selector = builder.add_attribute_conditions(id: 'my_id')
|
96
|
+
expect(selector).to eq 'ul#my_id'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
# rubocop:enable RSpec/InstanceVariable
|