capybara 2.15.1 → 3.35.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.yardopts +1 -1
- data/History.md +871 -9
- data/License.txt +1 -1
- data/README.md +99 -75
- data/lib/capybara/config.rb +20 -59
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +35 -18
- data/lib/capybara/driver/node.rb +35 -9
- data/lib/capybara/dsl.rb +15 -6
- data/lib/capybara/helpers.rb +72 -28
- data/lib/capybara/minitest/spec.rb +173 -81
- data/lib/capybara/minitest.rb +220 -111
- data/lib/capybara/node/actions.rb +270 -172
- data/lib/capybara/node/base.rb +41 -34
- data/lib/capybara/node/document.rb +15 -3
- data/lib/capybara/node/document_matchers.rb +19 -21
- data/lib/capybara/node/element.rb +353 -137
- data/lib/capybara/node/finders.rb +144 -138
- data/lib/capybara/node/matchers.rb +369 -209
- data/lib/capybara/node/simple.rb +55 -26
- data/lib/capybara/queries/ancestor_query.rb +11 -9
- data/lib/capybara/queries/base_query.rb +39 -28
- data/lib/capybara/queries/current_path_query.rb +22 -25
- data/lib/capybara/queries/match_query.rb +14 -7
- data/lib/capybara/queries/selector_query.rb +633 -145
- data/lib/capybara/queries/sibling_query.rb +10 -9
- data/lib/capybara/queries/style_query.rb +45 -0
- data/lib/capybara/queries/text_query.rb +56 -38
- data/lib/capybara/queries/title_query.rb +8 -11
- data/lib/capybara/rack_test/browser.rb +57 -41
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +18 -13
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +73 -58
- data/lib/capybara/rack_test/node.rb +182 -78
- data/lib/capybara/rails.rb +3 -7
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +42 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
- data/lib/capybara/registrations/servers.rb +45 -0
- data/lib/capybara/result.rb +96 -62
- data/lib/capybara/rspec/features.rb +17 -50
- data/lib/capybara/rspec/matcher_proxies.rb +51 -14
- 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 +43 -0
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +144 -264
- data/lib/capybara/rspec.rb +7 -11
- data/lib/capybara/selector/builders/css_builder.rb +84 -0
- data/lib/capybara/selector/builders/xpath_builder.rb +71 -0
- data/lib/capybara/selector/css.rb +89 -17
- data/lib/capybara/selector/definition/button.rb +63 -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 +28 -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 +278 -0
- data/lib/capybara/selector/filter.rb +2 -17
- data/lib/capybara/selector/filter_set.rb +83 -33
- data/lib/capybara/selector/filters/base.rb +50 -6
- data/lib/capybara/selector/filters/expression_filter.rb +8 -26
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +16 -12
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +89 -210
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +226 -526
- 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 +334 -277
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +117 -0
- 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 +228 -0
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +76 -0
- data/lib/capybara/selenium/logger_suppressor.rb +40 -0
- data/lib/capybara/selenium/node.rb +506 -124
- data/lib/capybara/selenium/nodes/chrome_node.rb +137 -0
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +136 -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 +9 -0
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +63 -0
- data/lib/capybara/server/checker.rb +44 -0
- data/lib/capybara/server/middleware.rb +71 -0
- data/lib/capybara/server.rb +59 -67
- data/lib/capybara/session/config.rb +79 -59
- data/lib/capybara/session/matchers.rb +41 -25
- data/lib/capybara/session.rb +360 -356
- data/lib/capybara/spec/public/jquery.js +5 -5
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +159 -13
- data/lib/capybara/spec/session/accept_alert_spec.rb +12 -11
- data/lib/capybara/spec/session/accept_confirm_spec.rb +6 -5
- data/lib/capybara/spec/session/accept_prompt_spec.rb +34 -6
- data/lib/capybara/spec/session/all_spec.rb +163 -55
- data/lib/capybara/spec/session/ancestor_spec.rb +27 -24
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +68 -38
- data/lib/capybara/spec/session/assert_current_path_spec.rb +75 -0
- data/lib/capybara/spec/session/assert_selector_spec.rb +143 -0
- data/lib/capybara/spec/session/assert_style_spec.rb +26 -0
- data/lib/capybara/spec/session/{assert_text.rb → assert_text_spec.rb} +91 -59
- data/lib/capybara/spec/session/{assert_title.rb → assert_title_spec.rb} +22 -12
- data/lib/capybara/spec/session/attach_file_spec.rb +138 -69
- data/lib/capybara/spec/session/body_spec.rb +12 -13
- data/lib/capybara/spec/session/check_spec.rb +107 -55
- data/lib/capybara/spec/session/choose_spec.rb +58 -31
- data/lib/capybara/spec/session/click_button_spec.rb +231 -173
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +55 -35
- data/lib/capybara/spec/session/click_link_spec.rb +82 -58
- data/lib/capybara/spec/session/current_scope_spec.rb +11 -10
- data/lib/capybara/spec/session/current_url_spec.rb +57 -39
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +4 -4
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +3 -2
- data/lib/capybara/spec/session/element/{assert_match_selector.rb → assert_match_selector_spec.rb} +11 -9
- data/lib/capybara/spec/session/element/match_css_spec.rb +18 -10
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +9 -7
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +71 -57
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +30 -9
- data/lib/capybara/spec/session/execute_script_spec.rb +10 -8
- data/lib/capybara/spec/session/fill_in_spec.rb +128 -43
- data/lib/capybara/spec/session/find_button_spec.rb +25 -24
- data/lib/capybara/spec/session/find_by_id_spec.rb +10 -9
- data/lib/capybara/spec/session/find_field_spec.rb +37 -41
- data/lib/capybara/spec/session/find_link_spec.rb +36 -17
- data/lib/capybara/spec/session/find_spec.rb +245 -144
- data/lib/capybara/spec/session/first_spec.rb +79 -51
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +33 -20
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +50 -32
- data/lib/capybara/spec/session/go_back_spec.rb +2 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +2 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
- 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 +70 -13
- data/lib/capybara/spec/session/has_css_spec.rb +272 -137
- data/lib/capybara/spec/session/has_current_path_spec.rb +87 -45
- data/lib/capybara/spec/session/has_field_spec.rb +115 -59
- data/lib/capybara/spec/session/has_link_spec.rb +10 -9
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +78 -0
- data/lib/capybara/spec/session/has_select_spec.rb +103 -74
- data/lib/capybara/spec/session/has_selector_spec.rb +105 -71
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +172 -5
- data/lib/capybara/spec/session/has_text_spec.rb +113 -61
- data/lib/capybara/spec/session/has_title_spec.rb +20 -14
- data/lib/capybara/spec/session/has_xpath_spec.rb +57 -38
- data/lib/capybara/spec/session/{headers.rb → headers_spec.rb} +3 -2
- data/lib/capybara/spec/session/html_spec.rb +14 -6
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +950 -152
- data/lib/capybara/spec/session/node_wrapper_spec.rb +39 -0
- data/lib/capybara/spec/session/refresh_spec.rb +12 -6
- data/lib/capybara/spec/session/reset_session_spec.rb +69 -35
- data/lib/capybara/spec/session/{response_code.rb → response_code_spec.rb} +2 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +3 -2
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +8 -12
- data/lib/capybara/spec/session/save_page_spec.rb +42 -55
- data/lib/capybara/spec/session/save_screenshot_spec.rb +16 -14
- data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/scroll_spec.rb +117 -0
- data/lib/capybara/spec/session/select_spec.rb +107 -80
- data/lib/capybara/spec/session/selectors_spec.rb +52 -19
- data/lib/capybara/spec/session/sibling_spec.rb +10 -10
- data/lib/capybara/spec/session/text_spec.rb +37 -21
- data/lib/capybara/spec/session/title_spec.rb +17 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +42 -22
- data/lib/capybara/spec/session/unselect_spec.rb +39 -38
- data/lib/capybara/spec/session/visit_spec.rb +99 -32
- data/lib/capybara/spec/session/window/become_closed_spec.rb +24 -20
- data/lib/capybara/spec/session/window/current_window_spec.rb +5 -3
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +5 -3
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +27 -22
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +12 -6
- data/lib/capybara/spec/session/window/window_spec.rb +97 -63
- data/lib/capybara/spec/session/window/windows_spec.rb +12 -10
- data/lib/capybara/spec/session/window/within_window_spec.rb +31 -86
- data/lib/capybara/spec/session/within_spec.rb +70 -44
- data/lib/capybara/spec/spec_helper.rb +48 -43
- data/lib/capybara/spec/test_app.rb +78 -40
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +130 -39
- 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/initial_alert.erb +10 -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 +68 -1
- data/lib/capybara/spec/views/with_animation.erb +82 -0
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
- data/lib/capybara/spec/views/with_hover.erb +6 -0
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +69 -10
- data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +37 -0
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_namespace.erb +20 -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/spec/views/within_frames.erb +4 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +35 -33
- data/lib/capybara.rb +131 -104
- data/spec/basic_node_spec.rb +47 -34
- data/spec/capybara_spec.rb +53 -104
- data/spec/css_builder_spec.rb +101 -0
- data/spec/css_splitter_spec.rb +38 -0
- data/spec/dsl_spec.rb +81 -62
- data/spec/filter_set_spec.rb +27 -9
- data/spec/fixtures/certificate.pem +25 -0
- data/spec/fixtures/key.pem +27 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +5 -4
- data/spec/fixtures/selenium_driver_rspec_success.rb +5 -4
- data/spec/minitest_spec.rb +49 -7
- data/spec/minitest_spec_spec.rb +94 -59
- data/spec/per_session_config_spec.rb +14 -13
- data/spec/rack_test_spec.rb +176 -125
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +101 -46
- data/spec/rspec/features_spec.rb +37 -31
- data/spec/rspec/scenarios_spec.rb +9 -7
- data/spec/rspec/shared_spec_matchers.rb +448 -421
- data/spec/rspec/views_spec.rb +5 -3
- data/spec/rspec_matchers_spec.rb +27 -11
- data/spec/rspec_spec.rb +109 -89
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +396 -67
- data/spec/selenium_spec_chrome.rb +184 -35
- data/spec/selenium_spec_chrome_remote.rb +100 -0
- data/spec/selenium_spec_edge.rb +47 -0
- data/spec/selenium_spec_firefox.rb +183 -41
- data/spec/selenium_spec_firefox_remote.rb +80 -0
- data/spec/selenium_spec_ie.rb +150 -0
- data/spec/selenium_spec_safari.rb +148 -0
- data/spec/server_spec.rb +198 -99
- data/spec/session_spec.rb +53 -16
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +486 -97
- data/spec/spec_helper.rb +93 -7
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +338 -64
- data/.yard/templates_custom/default/class/html/selectors.erb +0 -38
- data/.yard/templates_custom/default/class/html/setup.rb +0 -17
- data/.yard/yard_extensions.rb +0 -78
- data/lib/capybara/query.rb +0 -7
- data/lib/capybara/rspec/compound.rb +0 -95
- data/lib/capybara/spec/session/assert_current_path.rb +0 -72
- data/lib/capybara/spec/session/assert_selector.rb +0 -148
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/spec/selenium_spec_marionette.rb +0 -117
data/lib/capybara/cucumber.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'capybara/dsl'
|
3
4
|
require 'capybara/rspec/matchers'
|
4
5
|
require 'capybara/rspec/matcher_proxies'
|
@@ -21,8 +22,6 @@ end
|
|
21
22
|
Before do |scenario|
|
22
23
|
scenario.source_tag_names.each do |tag|
|
23
24
|
driver_name = tag.sub(/^@/, '').to_sym
|
24
|
-
if Capybara.drivers
|
25
|
-
Capybara.current_driver = driver_name
|
26
|
-
end
|
25
|
+
Capybara.current_driver = driver_name if Capybara.drivers[driver_name]
|
27
26
|
end
|
28
27
|
end
|
data/lib/capybara/driver/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
class Capybara::Driver::Base
|
3
4
|
attr_writer :session
|
4
5
|
|
@@ -14,11 +15,11 @@ class Capybara::Driver::Base
|
|
14
15
|
raise NotImplementedError
|
15
16
|
end
|
16
17
|
|
17
|
-
def find_xpath(query)
|
18
|
+
def find_xpath(query, **options)
|
18
19
|
raise NotImplementedError
|
19
20
|
end
|
20
21
|
|
21
|
-
def find_css(query)
|
22
|
+
def find_css(query, **options)
|
22
23
|
raise NotImplementedError
|
23
24
|
end
|
24
25
|
|
@@ -42,7 +43,11 @@ class Capybara::Driver::Base
|
|
42
43
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#evaluate_script'
|
43
44
|
end
|
44
45
|
|
45
|
-
def
|
46
|
+
def evaluate_async_script(script, *args)
|
47
|
+
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#evaluate_script_asnyc'
|
48
|
+
end
|
49
|
+
|
50
|
+
def save_screenshot(path, **options)
|
46
51
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#save_screenshot'
|
47
52
|
end
|
48
53
|
|
@@ -54,6 +59,10 @@ class Capybara::Driver::Base
|
|
54
59
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#status_code'
|
55
60
|
end
|
56
61
|
|
62
|
+
def send_keys(*)
|
63
|
+
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#send_keys'
|
64
|
+
end
|
65
|
+
|
57
66
|
##
|
58
67
|
#
|
59
68
|
# @param frame [Capybara::Node::Element, :parent, :top] The iframe element to switch to
|
@@ -62,6 +71,16 @@ class Capybara::Driver::Base
|
|
62
71
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#switch_to_frame'
|
63
72
|
end
|
64
73
|
|
74
|
+
def frame_title
|
75
|
+
find_xpath('/html/head/title').map(&:all_text).first.to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
def frame_url
|
79
|
+
evaluate_script('document.location.href')
|
80
|
+
rescue Capybara::NotSupportedByDriverError
|
81
|
+
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#frame_title'
|
82
|
+
end
|
83
|
+
|
65
84
|
def current_window_handle
|
66
85
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#current_window_handle'
|
67
86
|
end
|
@@ -75,7 +94,11 @@ class Capybara::Driver::Base
|
|
75
94
|
end
|
76
95
|
|
77
96
|
def maximize_window(handle)
|
78
|
-
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#
|
97
|
+
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#maximize_window'
|
98
|
+
end
|
99
|
+
|
100
|
+
def fullscreen_window(handle)
|
101
|
+
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#fullscreen_window'
|
79
102
|
end
|
80
103
|
|
81
104
|
def close_window(handle)
|
@@ -94,15 +117,10 @@ class Capybara::Driver::Base
|
|
94
117
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#switch_to_window'
|
95
118
|
end
|
96
119
|
|
97
|
-
def within_window(locator)
|
98
|
-
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#within_window'
|
99
|
-
end
|
100
|
-
|
101
120
|
def no_such_window_error
|
102
121
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#no_such_window_error'
|
103
122
|
end
|
104
123
|
|
105
|
-
|
106
124
|
##
|
107
125
|
#
|
108
126
|
# Execute the block, and then accept the modal opened.
|
@@ -113,7 +131,7 @@ class Capybara::Driver::Base
|
|
113
131
|
# @return [String] the message shown in the modal
|
114
132
|
# @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
|
115
133
|
#
|
116
|
-
def accept_modal(type, options
|
134
|
+
def accept_modal(type, **options, &blk)
|
117
135
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#accept_modal'
|
118
136
|
end
|
119
137
|
|
@@ -126,7 +144,7 @@ class Capybara::Driver::Base
|
|
126
144
|
# @return [String] the message shown in the modal
|
127
145
|
# @raise [Capybara::ModalNotFound] if modal dialog hasn't been found
|
128
146
|
#
|
129
|
-
def dismiss_modal(type, options
|
147
|
+
def dismiss_modal(type, **options, &blk)
|
130
148
|
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#dismiss_modal'
|
131
149
|
end
|
132
150
|
|
@@ -138,20 +156,19 @@ class Capybara::Driver::Base
|
|
138
156
|
false
|
139
157
|
end
|
140
158
|
|
141
|
-
def reset
|
142
|
-
end
|
159
|
+
def reset!; end
|
143
160
|
|
144
161
|
def needs_server?
|
145
162
|
false
|
146
163
|
end
|
147
164
|
|
148
165
|
def session_options
|
149
|
-
|
166
|
+
session&.config || Capybara.session_options
|
150
167
|
end
|
151
168
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
169
|
+
private
|
170
|
+
|
171
|
+
def session
|
172
|
+
@session ||= nil
|
156
173
|
end
|
157
174
|
end
|
data/lib/capybara/driver/node.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Capybara
|
3
4
|
module Driver
|
4
5
|
class Node
|
5
|
-
attr_reader :driver, :native
|
6
|
+
attr_reader :driver, :native, :initial_cache
|
6
7
|
|
7
|
-
def initialize(driver, native)
|
8
|
+
def initialize(driver, native, initial_cache = {})
|
8
9
|
@driver = driver
|
9
10
|
@native = native
|
11
|
+
@initial_cache = initial_cache
|
10
12
|
end
|
11
13
|
|
12
14
|
def all_text
|
@@ -25,9 +27,13 @@ module Capybara
|
|
25
27
|
raise NotImplementedError
|
26
28
|
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def style(styles)
|
31
|
+
raise NotImplementedError
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param value [String, Array] Array is only allowed if node has 'multiple' attribute
|
35
|
+
# @param options [Hash] Driver specific options for how to set a value on a node
|
36
|
+
def set(value, **options)
|
31
37
|
raise NotImplementedError
|
32
38
|
end
|
33
39
|
|
@@ -39,15 +45,15 @@ module Capybara
|
|
39
45
|
raise NotImplementedError
|
40
46
|
end
|
41
47
|
|
42
|
-
def click
|
48
|
+
def click(keys = [], **options)
|
43
49
|
raise NotImplementedError
|
44
50
|
end
|
45
51
|
|
46
|
-
def right_click
|
52
|
+
def right_click(keys = [], **options)
|
47
53
|
raise NotImplementedError
|
48
54
|
end
|
49
55
|
|
50
|
-
def double_click
|
56
|
+
def double_click(keys = [], **options)
|
51
57
|
raise NotImplementedError
|
52
58
|
end
|
53
59
|
|
@@ -59,7 +65,19 @@ module Capybara
|
|
59
65
|
raise NotImplementedError
|
60
66
|
end
|
61
67
|
|
62
|
-
def drag_to(element)
|
68
|
+
def drag_to(element, **options)
|
69
|
+
raise NotImplementedError
|
70
|
+
end
|
71
|
+
|
72
|
+
def drop(*args)
|
73
|
+
raise NotImplementedError
|
74
|
+
end
|
75
|
+
|
76
|
+
def scroll_by(x, y)
|
77
|
+
raise NotImplementedError
|
78
|
+
end
|
79
|
+
|
80
|
+
def scroll_to(element, alignment, position = nil)
|
63
81
|
raise NotImplementedError
|
64
82
|
end
|
65
83
|
|
@@ -71,6 +89,10 @@ module Capybara
|
|
71
89
|
raise NotImplementedError
|
72
90
|
end
|
73
91
|
|
92
|
+
def obscured?
|
93
|
+
raise NotImplementedError
|
94
|
+
end
|
95
|
+
|
74
96
|
def checked?
|
75
97
|
raise NotImplementedError
|
76
98
|
end
|
@@ -91,6 +113,10 @@ module Capybara
|
|
91
113
|
!!self[:multiple]
|
92
114
|
end
|
93
115
|
|
116
|
+
def rect
|
117
|
+
raise NotSupportedByDriverError, 'Capybara::Driver::Node#rect'
|
118
|
+
end
|
119
|
+
|
94
120
|
def path
|
95
121
|
raise NotSupportedByDriverError, 'Capybara::Driver::Node#path'
|
96
122
|
end
|
data/lib/capybara/dsl.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'capybara'
|
3
4
|
|
4
5
|
module Capybara
|
5
6
|
module DSL
|
6
7
|
def self.included(base)
|
7
|
-
warn
|
8
|
+
warn 'including Capybara::DSL in the global scope is not recommended!' if base == Object
|
8
9
|
super
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.extended(base)
|
12
|
-
warn
|
13
|
+
warn 'extending the main object with Capybara::DSL is not recommended!' if base == TOPLEVEL_BINDING.eval('self')
|
13
14
|
super
|
14
15
|
end
|
15
16
|
|
@@ -17,8 +18,8 @@ module Capybara
|
|
17
18
|
#
|
18
19
|
# Shortcut to working in a different session.
|
19
20
|
#
|
20
|
-
def using_session(
|
21
|
-
Capybara.using_session(
|
21
|
+
def using_session(name_or_session, &block)
|
22
|
+
Capybara.using_session(name_or_session, &block)
|
22
23
|
end
|
23
24
|
|
24
25
|
# Shortcut to using a different wait time.
|
@@ -46,8 +47,16 @@ module Capybara
|
|
46
47
|
end
|
47
48
|
|
48
49
|
Session::DSL_METHODS.each do |method|
|
49
|
-
|
50
|
-
|
50
|
+
if RUBY_VERSION >= '2.7'
|
51
|
+
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
52
|
+
def #{method}(...)
|
53
|
+
page.method("#{method}").call(...)
|
54
|
+
end
|
55
|
+
METHOD
|
56
|
+
else
|
57
|
+
define_method method do |*args, &block|
|
58
|
+
page.send method, *args, &block
|
59
|
+
end
|
51
60
|
end
|
52
61
|
end
|
53
62
|
end
|
data/lib/capybara/helpers.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Capybara
|
5
|
-
|
6
4
|
# @api private
|
7
5
|
module Helpers
|
8
|
-
|
6
|
+
module_function
|
9
7
|
|
10
8
|
##
|
11
|
-
#
|
9
|
+
# @deprecated
|
12
10
|
# Normalizes whitespace space by stripping leading and trailing
|
13
11
|
# whitespace and replacing sequences of whitespace characters
|
14
12
|
# with a single space.
|
@@ -17,6 +15,7 @@ module Capybara
|
|
17
15
|
# @return [String] Normalized text
|
18
16
|
#
|
19
17
|
def normalize_whitespace(text)
|
18
|
+
Capybara::Helpers.warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
|
20
19
|
text.to_s.gsub(/[[:space:]]+/, ' ').strip
|
21
20
|
end
|
22
21
|
|
@@ -26,34 +25,34 @@ module Capybara
|
|
26
25
|
# if text is not a regexp
|
27
26
|
#
|
28
27
|
# @param [String] text Text to escape
|
29
|
-
# @
|
28
|
+
# @param [Boolean] exact (false) Whether or not this should be an exact text match
|
29
|
+
# @param [Fixnum, Boolean, nil] options Options passed to Regexp.new when creating the Regexp
|
30
|
+
# @return [Regexp] Regexp to match the passed in text and options
|
30
31
|
#
|
31
|
-
def to_regexp(text,
|
32
|
-
if text.is_a?(Regexp)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
32
|
+
def to_regexp(text, exact: false, all_whitespace: false, options: nil)
|
33
|
+
return text if text.is_a?(Regexp)
|
34
|
+
|
35
|
+
escaped = Regexp.escape(text)
|
36
|
+
escaped = escaped.gsub('\\ ', '[[:blank:]]') if all_whitespace
|
37
|
+
escaped = "\\A#{escaped}\\z" if exact
|
38
|
+
Regexp.new(escaped, options)
|
39
39
|
end
|
40
40
|
|
41
41
|
##
|
42
42
|
#
|
43
43
|
# Injects a `<base>` tag into the given HTML code, pointing to
|
44
|
-
#
|
44
|
+
# {Capybara.configure asset_host}.
|
45
45
|
#
|
46
46
|
# @param [String] html HTML code to inject into
|
47
|
+
# @param [URL] host (Capybara.asset_host) The host from which assets should be loaded
|
47
48
|
# @return [String] The modified HTML code
|
48
49
|
#
|
49
|
-
def inject_asset_host(html,
|
50
|
-
if
|
51
|
-
|
52
|
-
|
53
|
-
return html.clone.insert match.end(0), "<base href='#{asset_host}' />"
|
50
|
+
def inject_asset_host(html, host: Capybara.asset_host)
|
51
|
+
if host && Nokogiri::HTML(html).css('base').empty?
|
52
|
+
html.match(/<head[^<]*?>/) do |m|
|
53
|
+
return html.clone.insert m.end(0), "<base href='#{host}' />"
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
57
56
|
html
|
58
57
|
end
|
59
58
|
|
@@ -68,20 +67,65 @@ module Capybara
|
|
68
67
|
# @param [Integer] count The number of items
|
69
68
|
#
|
70
69
|
def declension(singular, plural, count)
|
71
|
-
|
72
|
-
|
70
|
+
count == 1 ? singular : plural
|
71
|
+
end
|
72
|
+
|
73
|
+
def filter_backtrace(trace)
|
74
|
+
return 'No backtrace' unless trace
|
75
|
+
|
76
|
+
filter = %r{lib/capybara/|lib/rspec/|lib/minitest/}
|
77
|
+
new_trace = trace.take_while { |line| line !~ filter }
|
78
|
+
new_trace = trace.reject { |line| line =~ filter } if new_trace.empty?
|
79
|
+
new_trace = trace.dup if new_trace.empty?
|
80
|
+
|
81
|
+
new_trace.first.split(/:in /, 2).first
|
82
|
+
end
|
83
|
+
|
84
|
+
def warn(message, uplevel: 1)
|
85
|
+
return Kernel.warn(message, uplevel: uplevel) if RUBY_VERSION >= '2.6'
|
86
|
+
|
87
|
+
# TODO: Remove when we drop support for Ruby 2.5
|
88
|
+
# Workaround for emulating `warn '...', uplevel: n` in Ruby 2.5 or lower.
|
89
|
+
if (match = /^(?<file>.+?):(?<line>\d+)(?::in `.*')?/.match(caller[uplevel]))
|
90
|
+
location = [match[:file], match[:line]].join(':')
|
91
|
+
Kernel.warn "#{location}: #{message}"
|
73
92
|
else
|
74
|
-
|
93
|
+
Kernel.warn message
|
75
94
|
end
|
76
95
|
end
|
77
96
|
|
78
97
|
if defined?(Process::CLOCK_MONOTONIC)
|
79
|
-
def monotonic_time
|
80
|
-
Process.clock_gettime Process::CLOCK_MONOTONIC
|
81
|
-
end
|
98
|
+
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end
|
82
99
|
else
|
83
|
-
def monotonic_time
|
84
|
-
|
100
|
+
def monotonic_time; Time.now.to_f; end
|
101
|
+
end
|
102
|
+
|
103
|
+
def timer(expire_in:)
|
104
|
+
Timer.new(expire_in)
|
105
|
+
end
|
106
|
+
|
107
|
+
class Timer
|
108
|
+
def initialize(expire_in)
|
109
|
+
@start = current
|
110
|
+
@expire_in = expire_in
|
111
|
+
end
|
112
|
+
|
113
|
+
def expired?
|
114
|
+
if stalled?
|
115
|
+
raise Capybara::FrozenInTime, 'Time appears to be frozen. Capybara does not work with libraries which freeze time, consider using time travelling instead'
|
116
|
+
end
|
117
|
+
|
118
|
+
current - @start >= @expire_in
|
119
|
+
end
|
120
|
+
|
121
|
+
def stalled?
|
122
|
+
@start == current
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def current
|
128
|
+
Capybara::Helpers.monotonic_time
|
85
129
|
end
|
86
130
|
end
|
87
131
|
end
|
@@ -1,175 +1,267 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/spec'
|
2
4
|
|
3
5
|
module Capybara
|
4
6
|
module Minitest
|
5
7
|
module Expectations
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
##
|
9
|
+
# Expectation that there is an ancestor
|
10
|
+
#
|
11
|
+
# @!method must_have_ancestor
|
12
|
+
# See {Capybara::Node::Matchers#has_ancestor?}
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
["refute_matches_#{assertion}", "wont_match_#{assertion}"]]
|
17
|
-
end.flatten(1)).each do |(meth, new_name)|
|
18
|
-
self.class_eval <<-EOM, __FILE__, __LINE__ + 1
|
19
|
-
def #{new_name} *args, &block
|
20
|
-
::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, &block)
|
21
|
-
end
|
22
|
-
EOM
|
14
|
+
##
|
15
|
+
# Expectation that there is button
|
16
|
+
#
|
17
|
+
# @!method must_have_button
|
18
|
+
# See {Capybara::Node::Matchers#has_button?}
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
20
|
+
##
|
21
|
+
# Expectation that there is no button
|
22
|
+
#
|
23
|
+
# @!method wont_have_button
|
24
|
+
# See {Capybara::Node::Matchers#has_no_button?}
|
30
25
|
|
31
26
|
##
|
32
|
-
# Expectation that there is
|
27
|
+
# Expectation that there is checked_field
|
33
28
|
#
|
34
|
-
# @!method
|
35
|
-
#
|
29
|
+
# @!method must_have_checked_field
|
30
|
+
# See {Capybara::Node::Matchers#has_checked_field?}
|
36
31
|
|
37
32
|
##
|
38
|
-
# Expectation that there is no
|
33
|
+
# Expectation that there is no checked_field
|
39
34
|
#
|
40
|
-
# @!method
|
41
|
-
#
|
35
|
+
# @!method wont_have_checked_field
|
36
|
+
# See {Capybara::Node::Matchers#has_no_checked_field?}
|
42
37
|
|
43
38
|
##
|
44
|
-
# Expectation that there is
|
39
|
+
# Expectation that there is unchecked_field
|
45
40
|
#
|
46
|
-
# @!method
|
47
|
-
#
|
41
|
+
# @!method must_have_unchecked_field
|
42
|
+
# See {Capybara::Node::Matchers#has_unchecked_field?}
|
48
43
|
|
49
44
|
##
|
50
|
-
# Expectation that there is no
|
45
|
+
# Expectation that there is no unchecked_field
|
51
46
|
#
|
52
|
-
# @!method
|
53
|
-
#
|
47
|
+
# @!method wont_have_unchecked_field
|
48
|
+
# See {Capybara::Node::Matchers#has_no_unchecked_field?}
|
54
49
|
|
55
50
|
##
|
56
|
-
# Expectation that
|
51
|
+
# Expectation that page content does match
|
57
52
|
#
|
58
|
-
# @!method
|
59
|
-
#
|
53
|
+
# @!method must_have_content
|
54
|
+
# See {Capybara::Node::Matchers#has_content?}
|
60
55
|
|
61
56
|
##
|
62
|
-
# Expectation that
|
57
|
+
# Expectation that page content does not match
|
63
58
|
#
|
64
|
-
# @!method
|
65
|
-
#
|
59
|
+
# @!method wont_have_content
|
60
|
+
# See {Capybara::Node::Matchers#has_no_content?}
|
66
61
|
|
67
62
|
##
|
68
|
-
# Expectation that there is
|
63
|
+
# Expectation that there is css
|
69
64
|
#
|
70
|
-
# @!method
|
71
|
-
#
|
65
|
+
# @!method must_have_css
|
66
|
+
# See {Capybara::Node::Matchers#has_css?}
|
72
67
|
|
73
68
|
##
|
74
|
-
# Expectation that there is no
|
69
|
+
# Expectation that there is no css
|
75
70
|
#
|
76
|
-
# @!method
|
77
|
-
#
|
71
|
+
# @!method wont_have_css
|
72
|
+
# See {Capybara::Node::Matchers#has_no_css?}
|
73
|
+
|
74
|
+
##
|
75
|
+
# Expectation that current path matches
|
76
|
+
#
|
77
|
+
# @!method must_have_current_path
|
78
|
+
# See {Capybara::SessionMatchers#has_current_path?}
|
79
|
+
|
80
|
+
##
|
81
|
+
# Expectation that current page does not match
|
82
|
+
#
|
83
|
+
# @!method wont_have_current_path
|
84
|
+
# See {Capybara::SessionMatchers#has_no_current_path?}
|
78
85
|
|
79
86
|
##
|
80
87
|
# Expectation that there is field
|
81
88
|
#
|
82
89
|
# @!method must_have_field
|
83
|
-
#
|
90
|
+
# See {Capybara::Node::Matchers#has_field?}
|
84
91
|
|
85
92
|
##
|
86
93
|
# Expectation that there is no field
|
87
94
|
#
|
88
95
|
# @!method wont_have_field
|
89
|
-
#
|
96
|
+
# See {Capybara::Node::Matchers#has_no_field?}
|
90
97
|
|
91
98
|
##
|
92
|
-
# Expectation that there is
|
99
|
+
# Expectation that there is link
|
93
100
|
#
|
94
|
-
# @!method
|
95
|
-
#
|
101
|
+
# @!method must_have_link
|
102
|
+
# See {Capybara::Node::Matchers#has_link?}
|
96
103
|
|
97
104
|
##
|
98
|
-
# Expectation that there is no
|
105
|
+
# Expectation that there is no link
|
99
106
|
#
|
100
|
-
# @!method
|
107
|
+
# @!method wont_have_link
|
108
|
+
# See {Capybara::Node::Matchers#has_no_link?}
|
101
109
|
|
102
110
|
##
|
103
|
-
# Expectation that
|
111
|
+
# Expectation that page text does match
|
104
112
|
#
|
105
|
-
# @!method
|
106
|
-
#
|
113
|
+
# @!method must_have_text
|
114
|
+
# See {Capybara::Node::Matchers#has_text?}
|
107
115
|
|
108
116
|
##
|
109
|
-
# Expectation that
|
117
|
+
# Expectation that page text does not match
|
110
118
|
#
|
111
|
-
# @!method
|
119
|
+
# @!method wont_have_text
|
120
|
+
# See {Capybara::Node::Matchers#has_no_text?}
|
121
|
+
|
122
|
+
##
|
123
|
+
# Expectation that page title does match
|
124
|
+
#
|
125
|
+
# @!method must_have_title
|
126
|
+
# See {Capybara::Node::DocumentMatchers#has_title?}
|
127
|
+
|
128
|
+
##
|
129
|
+
# Expectation that page title does not match
|
130
|
+
#
|
131
|
+
# @!method wont_have_title
|
132
|
+
# See {Capybara::Node::DocumentMatchers#has_no_title?}
|
112
133
|
|
113
134
|
##
|
114
135
|
# Expectation that there is select
|
115
136
|
#
|
116
137
|
# @!method must_have_select
|
117
|
-
#
|
138
|
+
# See {Capybara::Node::Matchers#has_select?}
|
118
139
|
|
119
140
|
##
|
120
141
|
# Expectation that there is no select
|
121
142
|
#
|
122
143
|
# @!method wont_have_select
|
123
|
-
#
|
144
|
+
# See {Capybara::Node::Matchers#has_no_select?}
|
124
145
|
|
125
146
|
##
|
126
|
-
# Expectation that there is
|
147
|
+
# Expectation that there is a selector
|
127
148
|
#
|
128
|
-
# @!method
|
129
|
-
#
|
149
|
+
# @!method must_have_selector
|
150
|
+
# See {Capybara::Node::Matchers#has_selector?}
|
130
151
|
|
131
152
|
##
|
132
|
-
# Expectation that there is no
|
153
|
+
# Expectation that there is no selector
|
133
154
|
#
|
134
|
-
# @!method
|
135
|
-
#
|
155
|
+
# @!method wont_have_selector
|
156
|
+
# See {Capybara::Node::Matchers#has_no_selector?}
|
136
157
|
|
137
158
|
##
|
138
|
-
# Expectation that
|
159
|
+
# Expectation that all of the provided selectors are present
|
139
160
|
#
|
140
|
-
# @!method
|
141
|
-
#
|
161
|
+
# @!method must_have_all_of_selectors
|
162
|
+
# See {Capybara::Node::Matchers#assert_all_of_selectors}
|
142
163
|
|
143
164
|
##
|
144
|
-
# Expectation that
|
165
|
+
# Expectation that none of the provided selectors are present
|
145
166
|
#
|
146
|
-
# @!method
|
147
|
-
#
|
167
|
+
# @!method must_have_none_of_selectors
|
168
|
+
# See {Capybara::Node::Matchers#assert_none_of_selectors}
|
148
169
|
|
149
170
|
##
|
150
|
-
# Expectation that
|
171
|
+
# Expectation that any of the provided selectors are present
|
151
172
|
#
|
152
|
-
# @!method
|
153
|
-
#
|
173
|
+
# @!method must_have_any_of_selectors
|
174
|
+
# See {Capybara::Node::Matchers#assert_any_of_selectors}
|
154
175
|
|
155
176
|
##
|
156
|
-
# Expectation that
|
177
|
+
# Expectation that there is a sibling
|
157
178
|
#
|
158
|
-
# @!method
|
159
|
-
#
|
179
|
+
# @!method must_have_sibling
|
180
|
+
# See {Capybara::Node::Matchers#has_sibling?}
|
181
|
+
|
182
|
+
##
|
183
|
+
# Expectation that element has style
|
184
|
+
#
|
185
|
+
# @!method must_match_style
|
186
|
+
# See {Capybara::Node::Matchers#matches_style?}
|
160
187
|
|
188
|
+
##
|
189
|
+
# Expectation that there is table
|
190
|
+
#
|
191
|
+
# @!method must_have_table
|
192
|
+
# See {Capybara::Node::Matchers#has_table?}
|
193
|
+
|
194
|
+
##
|
195
|
+
# Expectation that there is no table
|
196
|
+
#
|
197
|
+
# @!method wont_have_table
|
198
|
+
# See {Capybara::Node::Matchers#has_no_table?}
|
199
|
+
|
200
|
+
##
|
201
|
+
# Expectation that there is xpath
|
202
|
+
#
|
203
|
+
# @!method must_have_xpath
|
204
|
+
# See {Capybara::Node::Matchers#has_xpath?}
|
205
|
+
|
206
|
+
##
|
207
|
+
# Expectation that there is no xpath
|
208
|
+
#
|
209
|
+
# @!method wont_have_xpath
|
210
|
+
# See {Capybara::Node::Matchers#has_no_xpath?}
|
211
|
+
|
212
|
+
# This currently doesn't work for Ruby 2.8 due to Minitest not forwarding keyword args separately
|
213
|
+
# %w[text content title current_path].each do |assertion|
|
214
|
+
# infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
|
215
|
+
# infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
|
216
|
+
# end
|
217
|
+
|
218
|
+
# rubocop:disable Style/MultilineBlockChain
|
219
|
+
(%w[text content title current_path
|
220
|
+
selector xpath css link button field select table checked_field unchecked_field
|
221
|
+
ancestor sibling].flat_map do |assertion|
|
222
|
+
[%W[assert_#{assertion} must_have_#{assertion}],
|
223
|
+
%W[refute_#{assertion} wont_have_#{assertion}]]
|
224
|
+
end + [%w[assert_all_of_selectors must_have_all_of_selectors],
|
225
|
+
%w[assert_none_of_selectors must_have_none_of_selectors],
|
226
|
+
%w[assert_any_of_selectors must_have_any_of_selectors],
|
227
|
+
%w[assert_matches_style must_match_style]] +
|
228
|
+
%w[selector xpath css].flat_map do |assertion|
|
229
|
+
[%W[assert_matches_#{assertion} must_match_#{assertion}],
|
230
|
+
%W[refute_matches_#{assertion} wont_match_#{assertion}]]
|
231
|
+
end).each do |(meth, new_name)|
|
232
|
+
class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
|
233
|
+
def #{new_name} *args, **kw_args, &block
|
234
|
+
::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, **kw_args, &block)
|
235
|
+
end
|
236
|
+
ASSERTION
|
237
|
+
|
238
|
+
::Minitest::Expectation.class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
|
239
|
+
def #{new_name} *args, **kw_args, &block
|
240
|
+
raise "Calling ##{new_name} outside of test." unless ctx
|
241
|
+
ctx.#{meth}(target, *args, **kw_args, &block)
|
242
|
+
end
|
243
|
+
ASSERTION
|
244
|
+
end
|
245
|
+
# rubocop:enable Style/MultilineBlockChain
|
246
|
+
|
247
|
+
##
|
248
|
+
# @deprecated
|
249
|
+
def must_have_style(*args, **kw_args, &block)
|
250
|
+
warn 'must_have_style is deprecated, please use must_match_style'
|
251
|
+
must_match_style(*args, **kw_args, &block)
|
252
|
+
end
|
161
253
|
end
|
162
254
|
end
|
163
255
|
end
|
164
256
|
|
165
257
|
class Capybara::Session
|
166
|
-
include Capybara::Minitest::Expectations unless ENV[
|
258
|
+
include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
|
167
259
|
end
|
168
260
|
|
169
261
|
class Capybara::Node::Base
|
170
|
-
include Capybara::Minitest::Expectations unless ENV[
|
262
|
+
include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
|
171
263
|
end
|
172
264
|
|
173
265
|
class Capybara::Node::Simple
|
174
|
-
include Capybara::Minitest::Expectations unless ENV[
|
266
|
+
include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
|
175
267
|
end
|