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
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XPath
|
4
|
+
class Renderer
|
5
|
+
def join(*expressions)
|
6
|
+
expressions.join('/')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module XPath
|
12
|
+
module DSL
|
13
|
+
def join(*expressions)
|
14
|
+
XPath::Expression.new(:join, *[self, expressions].flatten)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/capybara/selector.rb
CHANGED
@@ -1,542 +1,242 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'capybara/selector/selector'
|
3
|
-
Capybara::Selector::FilterSet.add(:_field) do
|
4
|
-
filter(:checked, :boolean) { |node, value| not(value ^ node.checked?) }
|
5
|
-
filter(:unchecked, :boolean) { |node, value| (value ^ node.checked?) }
|
6
|
-
filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
|
7
|
-
filter(:multiple, :boolean) { |node, value| !(value ^ node.multiple?) }
|
8
|
-
|
9
|
-
expression_filter(:name) { |xpath, val| xpath[XPath.attr(:name).equals(val)] }
|
10
|
-
expression_filter(:placeholder) { |xpath, val| xpath[XPath.attr(:placeholder).equals(val)] }
|
11
|
-
|
12
|
-
describe do |options|
|
13
|
-
desc, states = String.new, []
|
14
|
-
states << 'checked' if options[:checked] || (options[:unchecked] == false)
|
15
|
-
states << 'not checked' if options[:unchecked] || (options[:checked] == false)
|
16
|
-
states << 'disabled' if options[:disabled] == true
|
17
|
-
states << 'not disabled' if options[:disabled] == false
|
18
|
-
desc << " that is #{states.join(' and ')}" unless states.empty?
|
19
|
-
desc << " with the multiple attribute" if options[:multiple] == true
|
20
|
-
desc << " without the multiple attribute" if options[:multiple] == false
|
21
|
-
desc
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
#
|
27
|
-
# Select elements by XPath expression
|
28
|
-
#
|
29
|
-
# @locator An XPath expression
|
30
|
-
#
|
31
|
-
Capybara.add_selector(:xpath) do
|
32
|
-
xpath { |xpath| xpath }
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
#
|
37
|
-
# Select elements by CSS selector
|
38
|
-
#
|
39
|
-
# @locator A CSS selector
|
40
|
-
#
|
41
|
-
Capybara.add_selector(:css) do
|
42
|
-
css { |css| css }
|
43
|
-
end
|
44
|
-
|
45
|
-
##
|
46
|
-
#
|
47
|
-
# Select element by id
|
48
|
-
#
|
49
|
-
# @locator The id of the element to match
|
50
|
-
#
|
51
|
-
Capybara.add_selector(:id) do
|
52
|
-
xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
|
53
|
-
end
|
54
|
-
|
55
|
-
##
|
56
|
-
#
|
57
|
-
# Select field elements (input [not of type submit, image, or hidden], textarea, select)
|
58
|
-
#
|
59
|
-
# @locator Matches against the id, name, or placeholder
|
60
|
-
# @filter [String] :id Matches the id attribute
|
61
|
-
# @filter [String] :name Matches the name attribute
|
62
|
-
# @filter [String] :placeholder Matches the placeholder attribute
|
63
|
-
# @filter [String] :type Matches the type attribute of the field or element type for 'textarea' and 'select'
|
64
|
-
# @filter [Boolean] :readonly
|
65
|
-
# @filter [String] :with Matches the current value of the field
|
66
|
-
# @filter [String, Array<String>] :class Matches the class(es) provided
|
67
|
-
# @filter [Boolean] :checked Match checked fields?
|
68
|
-
# @filter [Boolean] :unchecked Match unchecked fields?
|
69
|
-
# @filter [Boolean] :disabled Match disabled field?
|
70
|
-
# @filter [Boolean] :multiple Match fields that accept multiple values
|
71
|
-
Capybara.add_selector(:field) do
|
72
|
-
xpath do |locator, options|
|
73
|
-
xpath = XPath.descendant(:input, :textarea, :select)[~XPath.attr(:type).one_of('submit', 'image', 'hidden')]
|
74
|
-
locate_field(xpath, locator, options)
|
75
|
-
end
|
76
|
-
|
77
|
-
expression_filter(:type) do |expr, type|
|
78
|
-
type = type.to_s
|
79
|
-
if ['textarea', 'select'].include?(type)
|
80
|
-
expr.axis(:self, type.to_sym)
|
81
|
-
else
|
82
|
-
expr[XPath.attr(:type).equals(type)]
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
filter_set(:_field) # checked/unchecked/disabled/multiple/name/placeholder
|
87
|
-
|
88
|
-
filter(:readonly, :boolean) { |node, value| not(value ^ node.readonly?) }
|
89
|
-
filter(:with) do |node, with|
|
90
|
-
with.is_a?(Regexp) ? node.value =~ with : node.value == with.to_s
|
91
|
-
end
|
92
|
-
describe do |options|
|
93
|
-
desc = String.new
|
94
|
-
(expression_filters.keys - [:type]).each { |ef| desc << " with #{ef} #{options[ef]}" if options.has_key?(ef) }
|
95
|
-
desc << " of type #{options[:type].inspect}" if options[:type]
|
96
|
-
desc << " with value #{options[:with].to_s.inspect}" if options.has_key?(:with)
|
97
|
-
desc
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
##
|
102
|
-
#
|
103
|
-
# Select fieldset elements
|
104
|
-
#
|
105
|
-
# @locator Matches id or contents of wrapped legend
|
106
|
-
#
|
107
|
-
# @filter [String] :id Matches id attribute
|
108
|
-
# @filter [String] :legend Matches contents of wrapped legend
|
109
|
-
# @filter [String, Array<String>] :class Matches the class(es) provided
|
110
|
-
#
|
111
|
-
Capybara.add_selector(:fieldset) do
|
112
|
-
xpath(:legend) do |locator, options|
|
113
|
-
xpath = XPath.descendant(:fieldset)
|
114
|
-
xpath = xpath[XPath.attr(:id).equals(locator.to_s).or XPath.child(:legend)[XPath.string.n.is(locator.to_s)]] unless locator.nil?
|
115
|
-
xpath = xpath[XPath.child(:legend)[XPath.string.n.is(options[:legend])]] if options[:legend]
|
116
|
-
xpath
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
##
|
121
|
-
#
|
122
|
-
# Find links ( <a> elements with an href attribute )
|
123
|
-
#
|
124
|
-
# @locator Matches the id or title attributes, or the string content of the link, or the alt attribute of a contained img element
|
125
|
-
#
|
126
|
-
# @filter [String] :id Matches the id attribute
|
127
|
-
# @filter [String] :title Matches the title attribute
|
128
|
-
# @filter [String] :alt Matches the alt attribute of a contained img element
|
129
|
-
# @filter [String] :class Matches the class(es) provided
|
130
|
-
# @filter [String, Regexp,nil] :href Matches the normalized href of the link, if nil will find <a> elements with no href attribute
|
131
|
-
#
|
132
|
-
Capybara.add_selector(:link) do
|
133
|
-
xpath(:title, :alt) do |locator, options={}|
|
134
|
-
xpath = XPath.descendant(:a)
|
135
|
-
xpath = if options.fetch(:href, true).nil?
|
136
|
-
xpath[~XPath.attr(:href)]
|
137
|
-
else
|
138
|
-
xpath[XPath.attr(:href)]
|
139
|
-
end
|
140
|
-
unless locator.nil?
|
141
|
-
locator = locator.to_s
|
142
|
-
matchers = XPath.attr(:id).equals(locator).or(
|
143
|
-
XPath.string.n.is(locator)).or(
|
144
|
-
XPath.attr(:title).is(locator)).or(
|
145
|
-
XPath.descendant(:img)[XPath.attr(:alt).is(locator)])
|
146
|
-
matchers = matchers.or XPath.attr(:'aria-label').is(locator) if options[:enable_aria_label]
|
147
|
-
xpath = xpath[matchers]
|
148
|
-
end
|
149
|
-
xpath = [:title].inject(xpath) { |memo, ef| memo[find_by_attr(ef, options[ef])] }
|
150
|
-
xpath = xpath[XPath.descendant(:img)[XPath.attr(:alt).equals(options[:alt])]] if options[:alt]
|
151
|
-
xpath
|
152
|
-
end
|
153
|
-
|
154
|
-
filter(:href) do |node, href|
|
155
|
-
case href
|
156
|
-
when nil
|
157
|
-
true
|
158
|
-
when Regexp
|
159
|
-
node[:href].match href
|
160
|
-
else
|
161
|
-
node.first(:xpath, XPath.axis(:self)[XPath.attr(:href).equals(href.to_s)], minimum: 0)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe do |options|
|
166
|
-
desc = String.new()
|
167
|
-
desc << " with href #{options[:href].inspect}" if options[:href]
|
168
|
-
desc << " with no href attribute" if options.fetch(:href, true).nil?
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
##
|
173
|
-
#
|
174
|
-
# Find buttons ( input [of type submit, reset, image, button] or button elements )
|
175
|
-
#
|
176
|
-
# @locator Matches the id, value, or title attributes, string content of a button, or the alt attribute of an image type button or of a descendant image of a button
|
177
|
-
#
|
178
|
-
# @filter [String] :id Matches the id attribute
|
179
|
-
# @filter [String] :title Matches the title attribute
|
180
|
-
# @filter [String] :class Matches the class(es) provided
|
181
|
-
# @filter [String] :value Matches the value of an input button
|
182
|
-
#
|
183
|
-
Capybara.add_selector(:button) do
|
184
|
-
xpath(:value, :title) do |locator, options={}|
|
185
|
-
input_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')]
|
186
|
-
btn_xpath = XPath.descendant(:button)
|
187
|
-
image_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).equals('image')]
|
188
|
-
|
189
|
-
unless locator.nil?
|
190
|
-
locator = locator.to_s
|
191
|
-
locator_matches = XPath.attr(:id).equals(locator).or XPath.attr(:value).is(locator).or XPath.attr(:title).is(locator)
|
192
|
-
locator_matches = locator_matches.or XPath.attr(:'aria-label').is(locator) if options[:enable_aria_label]
|
193
|
-
|
194
|
-
input_btn_xpath = input_btn_xpath[locator_matches]
|
195
|
-
|
196
|
-
btn_xpath = btn_xpath[locator_matches.or XPath.string.n.is(locator).or XPath.descendant(:img)[XPath.attr(:alt).is(locator)]]
|
197
|
-
|
198
|
-
alt_matches = XPath.attr(:alt).is(locator)
|
199
|
-
alt_matches = alt_matches.or XPath.attr(:'aria-label').is(locator) if options[:enable_aria_label]
|
200
|
-
image_btn_xpath = image_btn_xpath[alt_matches]
|
201
|
-
end
|
202
|
-
|
203
|
-
res_xpath = input_btn_xpath.union(btn_xpath).union(image_btn_xpath)
|
204
2
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
#
|
281
|
-
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
#
|
313
|
-
#
|
314
|
-
#
|
315
|
-
#
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
#
|
321
|
-
#
|
322
|
-
#
|
323
|
-
#
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
#
|
344
|
-
#
|
345
|
-
#
|
346
|
-
#
|
347
|
-
#
|
348
|
-
#
|
349
|
-
#
|
350
|
-
#
|
351
|
-
#
|
352
|
-
#
|
353
|
-
#
|
354
|
-
#
|
355
|
-
#
|
356
|
-
#
|
357
|
-
#
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
3
|
+
require 'capybara/selector/xpath_extensions'
|
4
|
+
require 'capybara/selector/selector'
|
5
|
+
require 'capybara/selector/definition'
|
6
|
+
|
7
|
+
#
|
8
|
+
# All Selectors below support the listed selector specific filters in addition to the following system-wide filters
|
9
|
+
# * :id (String, Regexp, XPath::Expression) - Matches the id attribute
|
10
|
+
# * :class (String, Array<String | Regexp>, Regexp, XPath::Expression) - Matches the class(es) provided
|
11
|
+
# * :style (String, Regexp, Hash<String, String>) - Match on elements style
|
12
|
+
# * :above (Element) - Match elements above the passed element on the page
|
13
|
+
# * :below (Element) - Match elements below the passed element on the page
|
14
|
+
# * :left_of (Element) - Match elements left of the passed element on the page
|
15
|
+
# * :right_of (Element) - Match elements right of the passed element on the page
|
16
|
+
# * :near (Element) - Match elements near (within 50px) the passed element on the page
|
17
|
+
#
|
18
|
+
# ### Built-in Selectors
|
19
|
+
#
|
20
|
+
# * **:xpath** - Select elements by XPath expression
|
21
|
+
# * Locator: An XPath expression
|
22
|
+
#
|
23
|
+
# * **:css** - Select elements by CSS selector
|
24
|
+
# * Locator: A CSS selector
|
25
|
+
#
|
26
|
+
# * **:id** - Select element by id
|
27
|
+
# * Locator: (String, Regexp, XPath::Expression) The id of the element to match
|
28
|
+
#
|
29
|
+
# * **:field** - Select field elements (input [not of type submit, image, or hidden], textarea, select)
|
30
|
+
# * Locator: Matches against the id, {Capybara.configure test_id} attribute, name, placeholder, or
|
31
|
+
# associated label text
|
32
|
+
# * Filters:
|
33
|
+
# * :name (String, Regexp) - Matches the name attribute
|
34
|
+
# * :placeholder (String, Regexp) - Matches the placeholder attribute
|
35
|
+
# * :type (String) - Matches the type attribute of the field or element type for 'textarea' and 'select'
|
36
|
+
# * :readonly (Boolean) - Match on the element being readonly
|
37
|
+
# * :with (String, Regexp) - Matches the current value of the field
|
38
|
+
# * :checked (Boolean) - Match checked fields?
|
39
|
+
# * :unchecked (Boolean) - Match unchecked fields?
|
40
|
+
# * :disabled (Boolean, :all) - Match disabled field? (Default: false)
|
41
|
+
# * :multiple (Boolean) - Match fields that accept multiple values
|
42
|
+
# * :valid (Boolean) - Match fields that are valid/invalid according to HTML5 form validation
|
43
|
+
# * :validation_message (String, Regexp) - Matches the elements current validationMessage
|
44
|
+
#
|
45
|
+
# * **:fieldset** - Select fieldset elements
|
46
|
+
# * Locator: Matches id, {Capybara.configure test_id}, or contents of wrapped legend
|
47
|
+
# * Filters:
|
48
|
+
# * :legend (String) - Matches contents of wrapped legend
|
49
|
+
# * :disabled (Boolean) - Match disabled fieldset?
|
50
|
+
#
|
51
|
+
# * **:link** - Find links (`<a>` elements with an href attribute)
|
52
|
+
# * Locator: Matches the id, {Capybara.configure test_id}, or title attributes, or the string content of the link,
|
53
|
+
# or the alt attribute of a contained img element. By default this selector requires a link to have an href attribute.
|
54
|
+
# * Filters:
|
55
|
+
# * :title (String) - Matches the title attribute
|
56
|
+
# * :alt (String) - Matches the alt attribute of a contained img element
|
57
|
+
# * :href (String, Regexp, nil, false) - Matches the normalized href of the link, if nil will find `<a>` elements with no href attribute, if false ignores href presence
|
58
|
+
#
|
59
|
+
# * **:button** - Find buttons ( input [of type submit, reset, image, button] or button elements )
|
60
|
+
# * Locator: Matches the id, {Capybara.configure test_id} attribute, name, value, or title attributes, string content of a button, or the alt attribute of an image type button or of a descendant image of a button
|
61
|
+
# * Filters:
|
62
|
+
# * :name (String, Regexp) - Matches the name attribute
|
63
|
+
# * :title (String) - Matches the title attribute
|
64
|
+
# * :value (String) - Matches the value of an input button
|
65
|
+
# * :type (String) - Matches the type attribute
|
66
|
+
# * :disabled (Boolean, :all) - Match disabled buttons (Default: false)
|
67
|
+
#
|
68
|
+
# * **:link_or_button** - Find links or buttons
|
69
|
+
# * Locator: See :link and :button selectors
|
70
|
+
# * Filters:
|
71
|
+
# * :disabled (Boolean, :all) - Match disabled buttons? (Default: false)
|
72
|
+
#
|
73
|
+
# * **:fillable_field** - Find text fillable fields ( textarea, input [not of type submit, image, radio, checkbox, hidden, file] )
|
74
|
+
# * Locator: Matches against the id, {Capybara.configure test_id} attribute, name, placeholder, or associated label text
|
75
|
+
# * Filters:
|
76
|
+
# * :name (String, Regexp) - Matches the name attribute
|
77
|
+
# * :placeholder (String, Regexp) - Matches the placeholder attribute
|
78
|
+
# * :with (String, Regexp) - Matches the current value of the field
|
79
|
+
# * :type (String) - Matches the type attribute of the field or element type for 'textarea'
|
80
|
+
# * :disabled (Boolean, :all) - Match disabled field? (Default: false)
|
81
|
+
# * :multiple (Boolean) - Match fields that accept multiple values
|
82
|
+
# * :valid (Boolean) - Match fields that are valid/invalid according to HTML5 form validation
|
83
|
+
# * :validation_message (String, Regexp) - Matches the elements current validationMessage
|
84
|
+
#
|
85
|
+
# * **:radio_button** - Find radio buttons
|
86
|
+
# * Locator: Match id, {Capybara.configure test_id} attribute, name, or associated label text
|
87
|
+
# * Filters:
|
88
|
+
# * :name (String, Regexp) - Matches the name attribute
|
89
|
+
# * :checked (Boolean) - Match checked fields?
|
90
|
+
# * :unchecked (Boolean) - Match unchecked fields?
|
91
|
+
# * :disabled (Boolean, :all) - Match disabled field? (Default: false)
|
92
|
+
# * :option (String, Regexp) - Match the current value
|
93
|
+
# * :with - Alias of :option
|
94
|
+
#
|
95
|
+
# * **:checkbox** - Find checkboxes
|
96
|
+
# * Locator: Match id, {Capybara.configure test_id} attribute, name, or associated label text
|
97
|
+
# * Filters:
|
98
|
+
# * :name (String, Regexp) - Matches the name attribute
|
99
|
+
# * :checked (Boolean) - Match checked fields?
|
100
|
+
# * :unchecked (Boolean) - Match unchecked fields?
|
101
|
+
# * :disabled (Boolean, :all) - Match disabled field? (Default: false)
|
102
|
+
# * :with (String, Regexp) - Match the current value
|
103
|
+
# * :option - Alias of :with
|
104
|
+
#
|
105
|
+
# * **:select** - Find select elements
|
106
|
+
# * Locator: Match id, {Capybara.configure test_id} attribute, name, placeholder, or associated label text
|
107
|
+
# * Filters:
|
108
|
+
# * :name (String, Regexp) - Matches the name attribute
|
109
|
+
# * :placeholder (String, Placeholder) - Matches the placeholder attribute
|
110
|
+
# * :disabled (Boolean, :all) - Match disabled field? (Default: false)
|
111
|
+
# * :multiple (Boolean) - Match fields that accept multiple values
|
112
|
+
# * :options (Array<String>) - Exact match options
|
113
|
+
# * :enabled_options (Array<String>) - Exact match enabled options
|
114
|
+
# * :disabled_options (Array<String>) - Exact match disabled options
|
115
|
+
# * :with_options (Array<String>) - Partial match options
|
116
|
+
# * :selected (String, Array<String>) - Match the selection(s)
|
117
|
+
# * :with_selected (String, Array<String>) - Partial match the selection(s)
|
118
|
+
#
|
119
|
+
# * **:option** - Find option elements
|
120
|
+
# * Locator: Match text of option
|
121
|
+
# * Filters:
|
122
|
+
# * :disabled (Boolean) - Match disabled option
|
123
|
+
# * :selected (Boolean) - Match selected option
|
124
|
+
#
|
125
|
+
# * **:datalist_input** - Find input field with datalist completion
|
126
|
+
# * Locator: Matches against the id, {Capybara.configure test_id} attribute, name,
|
127
|
+
# placeholder, or associated label text
|
128
|
+
# * Filters:
|
129
|
+
# * :name (String, Regexp) - Matches the name attribute
|
130
|
+
# * :placeholder (String, Regexp) - Matches the placeholder attribute
|
131
|
+
# * :disabled (Boolean, :all) - Match disabled field? (Default: false)
|
132
|
+
# * :options (Array<String>) - Exact match options
|
133
|
+
# * :with_options (Array<String>) - Partial match options
|
134
|
+
#
|
135
|
+
# * **:datalist_option** - Find datalist option
|
136
|
+
# * Locator: Match text or value of option
|
137
|
+
# * Filters:
|
138
|
+
# * :disabled (Boolean) - Match disabled option
|
139
|
+
#
|
140
|
+
# * **:file_field** - Find file input elements
|
141
|
+
# * Locator: Match id, {Capybara.configure test_id} attribute, name, or associated label text
|
142
|
+
# * Filters:
|
143
|
+
# * :name (String, Regexp) - Matches the name attribute
|
144
|
+
# * :disabled (Boolean, :all) - Match disabled field? (Default: false)
|
145
|
+
# * :multiple (Boolean) - Match field that accepts multiple values
|
146
|
+
#
|
147
|
+
# * **:label** - Find label elements
|
148
|
+
# * Locator: Match id, {Capybara.configure test_id}, or text contents
|
149
|
+
# * Filters:
|
150
|
+
# * :for (Element, String, Regexp) - The element or id of the element associated with the label
|
151
|
+
#
|
152
|
+
# * **:table** - Find table elements
|
153
|
+
# * Locator: id, {Capybara.configure test_id}, or caption text of table
|
154
|
+
# * Filters:
|
155
|
+
# * :caption (String) - Match text of associated caption
|
156
|
+
# * :with_rows (Array<Array<String>>, Array<Hash<String, String>>) - Partial match `<td>` data - visibility of `<td>` elements is not considered
|
157
|
+
# * :rows (Array<Array<String>>) - Match all `<td>`s - visibility of `<td>` elements is not considered
|
158
|
+
# * :with_cols (Array<Array<String>>, Array<Hash<String, String>>) - Partial match `<td>` data - visibility of `<td>` elements is not considered
|
159
|
+
# * :cols (Array<Array<String>>) - Match all `<td>`s - visibility of `<td>` elements is not considered
|
160
|
+
#
|
161
|
+
# * **:table_row** - Find table row
|
162
|
+
# * Locator: Array<String>, Hash<String, String> table row `<td>` contents - visibility of `<td>` elements is not considered
|
163
|
+
#
|
164
|
+
# * **:frame** - Find frame/iframe elements
|
165
|
+
# * Locator: Match id, {Capybara.configure test_id} attribute, or name
|
166
|
+
# * Filters:
|
167
|
+
# * :name (String) - Match name attribute
|
168
|
+
#
|
169
|
+
# * **:element**
|
170
|
+
# * Locator: Type of element ('div', 'a', etc) - if not specified defaults to '*'
|
171
|
+
# * Filters:
|
172
|
+
# * :\<any> (String, Regexp) - Match on any specified element attribute
|
173
|
+
#
|
174
|
+
class Capybara::Selector; end # rubocop:disable Lint/EmptyClass
|
366
175
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
176
|
+
Capybara::Selector::FilterSet.add(:_field) do
|
177
|
+
node_filter(:checked, :boolean) { |node, value| !(value ^ node.checked?) }
|
178
|
+
node_filter(:unchecked, :boolean) { |node, value| (value ^ node.checked?) }
|
179
|
+
node_filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| !(value ^ node.disabled?) }
|
180
|
+
node_filter(:valid, :boolean) { |node, value| node.evaluate_script('this.validity.valid') == value }
|
181
|
+
node_filter(:name) { |node, value| !value.is_a?(Regexp) || value.match?(node[:name]) }
|
182
|
+
node_filter(:placeholder) { |node, value| !value.is_a?(Regexp) || value.match?(node[:placeholder]) }
|
183
|
+
node_filter(:validation_message) do |node, msg|
|
184
|
+
vm = node[:validationMessage]
|
185
|
+
(msg.is_a?(Regexp) ? msg.match?(vm) : vm == msg.to_s).tap do |res|
|
186
|
+
add_error("Expected validation message to be #{msg.inspect} but was #{vm}") unless res
|
372
187
|
end
|
373
|
-
options.sort == actual.sort
|
374
188
|
end
|
375
189
|
|
376
|
-
|
377
|
-
|
378
|
-
if !node.visible?
|
379
|
-
finder_settings[:visible] = false
|
380
|
-
end
|
381
|
-
options.all? { |option| node.first(:option, option, finder_settings) }
|
190
|
+
expression_filter(:name) do |xpath, val|
|
191
|
+
builder(xpath).add_attribute_conditions(name: val)
|
382
192
|
end
|
383
|
-
|
384
|
-
|
385
|
-
actual = node.all(:xpath, './/option', visible: false).select(&:selected?).map { |option| option.text(:all) }
|
386
|
-
Array(selected).sort == actual.sort
|
193
|
+
expression_filter(:placeholder) do |xpath, val|
|
194
|
+
builder(xpath).add_attribute_conditions(placeholder: val)
|
387
195
|
end
|
196
|
+
expression_filter(:disabled) { |xpath, val| val ? xpath : xpath[~XPath.attr(:disabled)] }
|
197
|
+
expression_filter(:multiple) { |xpath, val| xpath[val ? XPath.attr(:multiple) : ~XPath.attr(:multiple)] }
|
388
198
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
desc
|
396
|
-
desc << " with options #{options[:options].inspect}" if options[:options]
|
397
|
-
desc << " with at least options #{options[:with_options].inspect}" if options[:with_options]
|
398
|
-
desc << " with #{options[:selected].inspect} selected" if options[:selected]
|
399
|
-
desc << " with at least #{options[:with_selected].inspect} selected" if options[:with_selected]
|
400
|
-
desc << describe_all_expression_filters(options)
|
199
|
+
describe(:expression_filters) do |name: nil, placeholder: nil, disabled: nil, multiple: nil, **|
|
200
|
+
desc = +''
|
201
|
+
desc << ' that is not disabled' if disabled == false
|
202
|
+
desc << " with name #{name}" if name
|
203
|
+
desc << " with placeholder #{placeholder}" if placeholder
|
204
|
+
desc << ' with the multiple attribute' if multiple == true
|
205
|
+
desc << ' without the multiple attribute' if multiple == false
|
401
206
|
desc
|
402
207
|
end
|
403
|
-
end
|
404
208
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
xpath do |locator|
|
415
|
-
xpath = XPath.descendant(:option)
|
416
|
-
xpath = xpath[XPath.string.n.is(locator.to_s)] unless locator.nil?
|
417
|
-
xpath
|
418
|
-
end
|
419
|
-
|
420
|
-
filter(:disabled, :boolean) { |node, value| not(value ^ node.disabled?) }
|
421
|
-
filter(:selected, :boolean) { |node, value| not(value ^ node.selected?) }
|
422
|
-
|
423
|
-
describe do |options|
|
424
|
-
desc = String.new
|
425
|
-
desc << " that is#{' not' unless options[:disabled]} disabled" if options.has_key?(:disabled)
|
426
|
-
desc << " that is#{' not' unless options[:selected]} selected" if options.has_key?(:selected)
|
427
|
-
desc
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
##
|
432
|
-
#
|
433
|
-
# Find file input elements
|
434
|
-
#
|
435
|
-
# @locator Match id, name, or associated label text
|
436
|
-
# @filter [String] :id Matches the id attribute
|
437
|
-
# @filter [String] :name Matches the name attribute
|
438
|
-
# @filter [String, Array<String>] :class Matches the class(es) provided
|
439
|
-
# @filter [Boolean] :disabled Match disabled field?
|
440
|
-
# @filter [Boolean] :multiple Match field that accepts multiple values
|
441
|
-
#
|
442
|
-
Capybara.add_selector(:file_field) do
|
443
|
-
label "file field"
|
444
|
-
xpath do |locator, options|
|
445
|
-
xpath = XPath.descendant(:input)[XPath.attr(:type).equals('file')]
|
446
|
-
locate_field(xpath, locator, options)
|
447
|
-
end
|
448
|
-
|
449
|
-
filter_set(:_field, [:disabled, :multiple, :name])
|
450
|
-
|
451
|
-
describe do |options|
|
452
|
-
desc = String.new
|
453
|
-
desc << describe_all_expression_filters(options)
|
454
|
-
desc
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
##
|
459
|
-
#
|
460
|
-
# Find label elements
|
461
|
-
#
|
462
|
-
# @locator Match id or text contents
|
463
|
-
# @filter [Element, String] :for The element or id of the element associated with the label
|
464
|
-
#
|
465
|
-
Capybara.add_selector(:label) do
|
466
|
-
label "label"
|
467
|
-
xpath(:for) do |locator, options|
|
468
|
-
xpath = XPath.descendant(:label)
|
469
|
-
xpath = xpath[XPath.string.n.is(locator.to_s).or XPath.attr(:id).equals(locator.to_s)] unless locator.nil?
|
470
|
-
if options.has_key?(:for) && !options[:for].is_a?(Capybara::Node::Element)
|
471
|
-
xpath = xpath[XPath.attr(:for).equals(options[:for].to_s).or((~XPath.attr(:for)).and(XPath.descendant()[XPath.attr(:id).equals(options[:for].to_s)]))]
|
472
|
-
end
|
473
|
-
xpath
|
474
|
-
end
|
475
|
-
|
476
|
-
filter(:for) do |node, field_or_value|
|
477
|
-
if field_or_value.is_a? Capybara::Node::Element
|
478
|
-
if node[:for]
|
479
|
-
field_or_value[:id] == node[:for]
|
480
|
-
else
|
481
|
-
field_or_value.find_xpath('./ancestor::label[1]').include? node.base
|
482
|
-
end
|
483
|
-
else
|
484
|
-
#Non element values were handled through the expression filter
|
485
|
-
true
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|
489
|
-
describe do |options|
|
490
|
-
desc = String.new
|
491
|
-
desc << " for #{options[:for]}" if options[:for]
|
492
|
-
desc
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
##
|
497
|
-
#
|
498
|
-
# Find table elements
|
499
|
-
#
|
500
|
-
# @locator id or caption text of table
|
501
|
-
# @filter [String] :id Match id attribute of table
|
502
|
-
# @filter [String] :caption Match text of associated caption
|
503
|
-
# @filter [String, Array<String>] :class Matches the class(es) provided
|
504
|
-
#
|
505
|
-
Capybara.add_selector(:table) do
|
506
|
-
xpath(:caption) do |locator, options|
|
507
|
-
xpath = XPath.descendant(:table)
|
508
|
-
xpath = xpath[XPath.attr(:id).equals(locator.to_s).or XPath.descendant(:caption).is(locator.to_s)] unless locator.nil?
|
509
|
-
xpath = xpath[XPath.descendant(:caption).equals(options[:caption])] if options[:caption]
|
510
|
-
xpath
|
511
|
-
end
|
512
|
-
|
513
|
-
describe do |options|
|
514
|
-
desc = String.new
|
515
|
-
desc << " with caption #{options[:caption]}" if options[:caption]
|
209
|
+
describe(:node_filters) do |checked: nil, unchecked: nil, disabled: nil, valid: nil, validation_message: nil, **|
|
210
|
+
desc, states = +'', []
|
211
|
+
states << 'checked' if checked || (unchecked == false)
|
212
|
+
states << 'not checked' if unchecked || (checked == false)
|
213
|
+
states << 'disabled' if disabled == true
|
214
|
+
desc << " that is #{states.join(' and ')}" unless states.empty?
|
215
|
+
desc << ' that is valid' if valid == true
|
216
|
+
desc << ' that is invalid' if valid == false
|
217
|
+
desc << " with validation message #{validation_message.to_s.inspect}" if validation_message
|
516
218
|
desc
|
517
219
|
end
|
518
220
|
end
|
519
221
|
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
end
|
542
|
-
end
|
222
|
+
require 'capybara/selector/definition/xpath'
|
223
|
+
require 'capybara/selector/definition/css'
|
224
|
+
require 'capybara/selector/definition/id'
|
225
|
+
require 'capybara/selector/definition/field'
|
226
|
+
require 'capybara/selector/definition/fieldset'
|
227
|
+
require 'capybara/selector/definition/link'
|
228
|
+
require 'capybara/selector/definition/button'
|
229
|
+
require 'capybara/selector/definition/link_or_button'
|
230
|
+
require 'capybara/selector/definition/fillable_field'
|
231
|
+
require 'capybara/selector/definition/radio_button'
|
232
|
+
require 'capybara/selector/definition/checkbox'
|
233
|
+
require 'capybara/selector/definition/select'
|
234
|
+
require 'capybara/selector/definition/datalist_input'
|
235
|
+
require 'capybara/selector/definition/option'
|
236
|
+
require 'capybara/selector/definition/datalist_option'
|
237
|
+
require 'capybara/selector/definition/file_field'
|
238
|
+
require 'capybara/selector/definition/label'
|
239
|
+
require 'capybara/selector/definition/table'
|
240
|
+
require 'capybara/selector/definition/table_row'
|
241
|
+
require 'capybara/selector/definition/frame'
|
242
|
+
require 'capybara/selector/definition/element'
|