capybara 2.7.0 → 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 -0
- data/History.md +1147 -11
- data/License.txt +1 -1
- data/README.md +252 -131
- data/lib/capybara/config.rb +92 -0
- data/lib/capybara/cucumber.rb +3 -3
- data/lib/capybara/driver/base.rb +52 -21
- data/lib/capybara/driver/node.rb +48 -14
- data/lib/capybara/dsl.rb +16 -9
- data/lib/capybara/helpers.rb +72 -81
- data/lib/capybara/minitest/spec.rb +267 -0
- data/lib/capybara/minitest.rb +385 -0
- data/lib/capybara/node/actions.rb +337 -89
- data/lib/capybara/node/base.rb +50 -32
- data/lib/capybara/node/document.rb +19 -3
- data/lib/capybara/node/document_matchers.rb +22 -24
- data/lib/capybara/node/element.rb +388 -125
- data/lib/capybara/node/finders.rb +231 -121
- data/lib/capybara/node/matchers.rb +503 -217
- data/lib/capybara/node/simple.rb +64 -27
- data/lib/capybara/queries/ancestor_query.rb +27 -0
- data/lib/capybara/queries/base_query.rb +87 -11
- data/lib/capybara/queries/current_path_query.rb +24 -24
- data/lib/capybara/queries/match_query.rb +15 -10
- data/lib/capybara/queries/selector_query.rb +675 -81
- data/lib/capybara/queries/sibling_query.rb +26 -0
- data/lib/capybara/queries/style_query.rb +45 -0
- data/lib/capybara/queries/text_query.rb +88 -20
- data/lib/capybara/queries/title_query.rb +9 -11
- data/lib/capybara/rack_test/browser.rb +63 -39
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +26 -16
- 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 +187 -67
- data/lib/capybara/rails.rb +4 -8
- 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 +142 -14
- data/lib/capybara/rspec/features.rb +17 -42
- data/lib/capybara/rspec/matcher_proxies.rb +82 -0
- 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 +143 -244
- data/lib/capybara/rspec.rb +10 -12
- 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 +102 -0
- 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 +3 -46
- data/lib/capybara/selector/filter_set.rb +124 -0
- data/lib/capybara/selector/filters/base.rb +77 -0
- data/lib/capybara/selector/filters/expression_filter.rb +22 -0
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +31 -0
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +155 -0
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +232 -369
- 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 +380 -142
- 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 +528 -97
- 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 +74 -71
- data/lib/capybara/session/config.rb +126 -0
- data/lib/capybara/session/matchers.rb +44 -27
- data/lib/capybara/session.rb +500 -297
- data/lib/capybara/spec/fixtures/no_extension +1 -0
- 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 +168 -14
- data/lib/capybara/spec/session/accept_alert_spec.rb +37 -14
- data/lib/capybara/spec/session/accept_confirm_spec.rb +7 -6
- data/lib/capybara/spec/session/accept_prompt_spec.rb +38 -10
- data/lib/capybara/spec/session/all_spec.rb +179 -59
- data/lib/capybara/spec/session/ancestor_spec.rb +88 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +140 -0
- 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_spec.rb +258 -0
- data/lib/capybara/spec/session/assert_title_spec.rb +93 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +154 -48
- data/lib/capybara/spec/session/body_spec.rb +12 -13
- data/lib/capybara/spec/session/check_spec.rb +168 -41
- data/lib/capybara/spec/session/choose_spec.rb +75 -23
- data/lib/capybara/spec/session/click_button_spec.rb +243 -175
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +57 -32
- data/lib/capybara/spec/session/click_link_spec.rb +100 -53
- data/lib/capybara/spec/session/current_scope_spec.rb +11 -10
- data/lib/capybara/spec/session/current_url_spec.rb +61 -35
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +7 -7
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +5 -4
- data/lib/capybara/spec/session/element/{assert_match_selector.rb → assert_match_selector_spec.rb} +13 -6
- data/lib/capybara/spec/session/element/match_css_spec.rb +21 -7
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +9 -7
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +91 -34
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +45 -3
- data/lib/capybara/spec/session/execute_script_spec.rb +24 -4
- data/lib/capybara/spec/session/fill_in_spec.rb +166 -64
- data/lib/capybara/spec/session/find_button_spec.rb +37 -18
- data/lib/capybara/spec/session/find_by_id_spec.rb +10 -9
- data/lib/capybara/spec/session/find_field_spec.rb +57 -34
- data/lib/capybara/spec/session/find_link_spec.rb +47 -10
- data/lib/capybara/spec/session/find_spec.rb +290 -144
- data/lib/capybara/spec/session/first_spec.rb +91 -48
- 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 +116 -0
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +112 -0
- data/lib/capybara/spec/session/go_back_spec.rb +3 -2
- data/lib/capybara/spec/session/go_forward_spec.rb +3 -2
- 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 +76 -19
- data/lib/capybara/spec/session/has_css_spec.rb +277 -131
- data/lib/capybara/spec/session/has_current_path_spec.rb +98 -26
- data/lib/capybara/spec/session/has_field_spec.rb +177 -107
- data/lib/capybara/spec/session/has_link_spec.rb +13 -12
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +78 -0
- data/lib/capybara/spec/session/has_select_spec.rb +191 -95
- data/lib/capybara/spec/session/has_selector_spec.rb +128 -64
- 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 +126 -60
- data/lib/capybara/spec/session/has_title_spec.rb +35 -12
- data/lib/capybara/spec/session/has_xpath_spec.rb +74 -53
- 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 +1028 -131
- data/lib/capybara/spec/session/node_wrapper_spec.rb +39 -0
- data/lib/capybara/spec/session/refresh_spec.rb +34 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +75 -34
- 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 +11 -15
- 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 +112 -85
- data/lib/capybara/spec/session/selectors_spec.rb +71 -8
- data/lib/capybara/spec/session/sibling_spec.rb +52 -0
- data/lib/capybara/spec/session/text_spec.rb +38 -23
- data/lib/capybara/spec/session/title_spec.rb +17 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +71 -12
- data/lib/capybara/spec/session/unselect_spec.rb +44 -43
- data/lib/capybara/spec/session/visit_spec.rb +99 -32
- data/lib/capybara/spec/session/window/become_closed_spec.rb +33 -29
- 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 +39 -30
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +17 -10
- data/lib/capybara/spec/session/window/window_spec.rb +121 -73
- data/lib/capybara/spec/session/window/windows_spec.rb +12 -10
- data/lib/capybara/spec/session/window/within_window_spec.rb +52 -82
- data/lib/capybara/spec/session/within_spec.rb +76 -43
- data/lib/capybara/spec/spec_helper.rb +67 -33
- data/lib/capybara/spec/test_app.rb +85 -36
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/buttons.erb +1 -1
- data/lib/capybara/spec/views/fieldsets.erb +1 -1
- data/lib/capybara/spec/views/form.erb +227 -20
- data/lib/capybara/spec/views/frame_child.erb +10 -2
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +2 -2
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/header_links.erb +1 -1
- data/lib/capybara/spec/views/host_links.erb +1 -1
- 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/path.erb +1 -1
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/postback.erb +1 -1
- 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 +69 -2
- data/lib/capybara/spec/views/with_animation.erb +82 -0
- data/lib/capybara/spec/views/with_base_tag.erb +1 -1
- data/lib/capybara/spec/views/with_count.erb +1 -1
- 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 +7 -1
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +100 -10
- data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
- data/lib/capybara/spec/views/with_html_entities.erb +1 -1
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +49 -3
- 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.erb +1 -1
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_simple_html.erb +1 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/spec/views/with_title.erb +1 -1
- data/lib/capybara/spec/views/with_unload_alert.erb +3 -1
- data/lib/capybara/spec/views/with_windows.erb +7 -1
- data/lib/capybara/spec/views/within_frames.erb +6 -3
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +39 -21
- data/lib/capybara.rb +208 -186
- data/spec/basic_node_spec.rb +52 -39
- data/spec/capybara_spec.rb +72 -50
- data/spec/css_builder_spec.rb +101 -0
- data/spec/css_splitter_spec.rb +38 -0
- data/spec/dsl_spec.rb +81 -61
- data/spec/filter_set_spec.rb +46 -0
- data/spec/fixtures/capybara.csv +1 -0
- data/spec/fixtures/certificate.pem +25 -0
- data/spec/fixtures/key.pem +27 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +7 -3
- data/spec/fixtures/selenium_driver_rspec_success.rb +7 -3
- data/spec/minitest_spec.rb +164 -0
- data/spec/minitest_spec_spec.rb +162 -0
- data/spec/per_session_config_spec.rb +68 -0
- data/spec/rack_test_spec.rb +189 -96
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +143 -13
- data/spec/rspec/features_spec.rb +38 -32
- data/spec/rspec/scenarios_spec.rb +9 -7
- data/spec/rspec/shared_spec_matchers.rb +959 -0
- data/spec/rspec/views_spec.rb +9 -3
- data/spec/rspec_matchers_spec.rb +62 -0
- data/spec/rspec_spec.rb +127 -30
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +458 -37
- data/spec/selenium_spec_chrome.rb +196 -9
- data/spec/selenium_spec_chrome_remote.rb +100 -0
- data/spec/selenium_spec_edge.rb +47 -0
- data/spec/selenium_spec_firefox.rb +210 -0
- 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 +200 -101
- data/spec/session_spec.rb +91 -0
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +558 -0
- data/spec/spec_helper.rb +94 -2
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +420 -60
- data/lib/capybara/query.rb +0 -7
- data/lib/capybara/spec/session/assert_current_path.rb +0 -60
- data/lib/capybara/spec/session/assert_selector.rb +0 -148
- data/lib/capybara/spec/session/assert_text.rb +0 -196
- data/lib/capybara/spec/session/assert_title.rb +0 -70
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +0 -53
- data/spec/rspec/matchers_spec.rb +0 -827
- data/spec/selenium_spec.rb +0 -151
@@ -1,34 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#within' do
|
3
4
|
before do
|
4
5
|
@session.visit('/with_scope')
|
5
6
|
end
|
6
7
|
|
7
|
-
context
|
8
|
-
it
|
9
|
-
@session.within(:css,
|
8
|
+
context 'with CSS selector' do
|
9
|
+
it 'should click links in the given scope' do
|
10
|
+
@session.within(:css, '#for_bar li:first-child') do
|
10
11
|
@session.click_link('Go')
|
11
12
|
end
|
12
13
|
expect(@session).to have_content('Bar')
|
13
14
|
end
|
14
15
|
|
15
|
-
it
|
16
|
-
@session.within(:css,
|
16
|
+
it 'should assert content in the given scope' do
|
17
|
+
@session.within(:css, '#for_foo') do
|
17
18
|
expect(@session).not_to have_content('First Name')
|
18
19
|
end
|
19
20
|
expect(@session).to have_content('First Name')
|
20
21
|
end
|
21
22
|
|
22
|
-
it
|
23
|
-
@session.within(:css,
|
23
|
+
it 'should accept additional options' do
|
24
|
+
@session.within(:css, '#for_bar li', text: 'With Simple HTML') do
|
24
25
|
@session.click_link('Go')
|
25
26
|
end
|
26
27
|
expect(@session).to have_content('Bar')
|
27
28
|
end
|
29
|
+
|
30
|
+
it 'should reload the node if the page is changed' do
|
31
|
+
@session.within(:css, '#for_foo') do
|
32
|
+
@session.visit('/with_scope_other')
|
33
|
+
expect(@session).to have_content('Different text')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should reload multiple nodes if the page is changed' do
|
38
|
+
@session.within(:css, '#for_bar') do
|
39
|
+
@session.within(:css, 'form[action="/redirect"]') do
|
40
|
+
@session.refresh
|
41
|
+
expect(@session).to have_content('First Name')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should error if the page is changed and a matching node no longer exists' do
|
47
|
+
@session.within(:css, '#for_foo') do
|
48
|
+
@session.visit('/')
|
49
|
+
expect { @session.text }.to raise_error(StandardError)
|
50
|
+
end
|
51
|
+
end
|
28
52
|
end
|
29
53
|
|
30
|
-
context
|
31
|
-
it
|
54
|
+
context 'with XPath selector' do
|
55
|
+
it 'should click links in the given scope' do
|
32
56
|
@session.within(:xpath, "//div[@id='for_bar']//li[contains(.,'With Simple HTML')]") do
|
33
57
|
@session.click_link('Go')
|
34
58
|
end
|
@@ -36,8 +60,8 @@ Capybara::SpecHelper.spec '#within' do
|
|
36
60
|
end
|
37
61
|
end
|
38
62
|
|
39
|
-
context
|
40
|
-
it
|
63
|
+
context 'with the default selector' do
|
64
|
+
it 'should use XPath' do
|
41
65
|
@session.within("//div[@id='for_bar']//li[contains(.,'With Simple HTML')]") do
|
42
66
|
@session.click_link('Go')
|
43
67
|
end
|
@@ -45,9 +69,9 @@ Capybara::SpecHelper.spec '#within' do
|
|
45
69
|
end
|
46
70
|
end
|
47
71
|
|
48
|
-
context
|
49
|
-
it
|
50
|
-
node_of_interest = @session.find(:css,
|
72
|
+
context 'with Node rather than selector' do
|
73
|
+
it 'should click links in the given scope' do
|
74
|
+
node_of_interest = @session.find(:css, '#for_bar li', text: 'With Simple HTML')
|
51
75
|
|
52
76
|
@session.within(node_of_interest) do
|
53
77
|
@session.click_link('Go')
|
@@ -56,19 +80,21 @@ Capybara::SpecHelper.spec '#within' do
|
|
56
80
|
end
|
57
81
|
end
|
58
82
|
|
59
|
-
context
|
83
|
+
context 'with the default selector set to CSS' do
|
60
84
|
before { Capybara.default_selector = :css }
|
61
|
-
|
62
|
-
|
85
|
+
|
86
|
+
after { Capybara.default_selector = :xpath }
|
87
|
+
|
88
|
+
it 'should use CSS' do
|
89
|
+
@session.within('#for_bar li', text: 'With Simple HTML') do
|
63
90
|
@session.click_link('Go')
|
64
91
|
end
|
65
92
|
expect(@session).to have_content('Bar')
|
66
93
|
end
|
67
|
-
after { Capybara.default_selector = :xpath }
|
68
94
|
end
|
69
95
|
|
70
|
-
context
|
71
|
-
it
|
96
|
+
context 'with nested scopes' do
|
97
|
+
it 'should respect the inner scope' do
|
72
98
|
@session.within("//div[@id='for_bar']") do
|
73
99
|
@session.within(".//li[contains(.,'Bar')]") do
|
74
100
|
@session.click_link('Go')
|
@@ -77,7 +103,7 @@ Capybara::SpecHelper.spec '#within' do
|
|
77
103
|
expect(@session).to have_content('Another World')
|
78
104
|
end
|
79
105
|
|
80
|
-
it
|
106
|
+
it 'should respect the outer scope' do
|
81
107
|
@session.within("//div[@id='another_foo']") do
|
82
108
|
@session.within(".//li[contains(.,'With Simple HTML')]") do
|
83
109
|
@session.click_link('Go')
|
@@ -87,14 +113,14 @@ Capybara::SpecHelper.spec '#within' do
|
|
87
113
|
end
|
88
114
|
end
|
89
115
|
|
90
|
-
it
|
116
|
+
it 'should raise an error if the scope is not found on the page' do
|
91
117
|
expect do
|
92
118
|
@session.within("//div[@id='doesnotexist']") do
|
93
119
|
end
|
94
120
|
end.to raise_error(Capybara::ElementNotFound)
|
95
121
|
end
|
96
122
|
|
97
|
-
it
|
123
|
+
it 'should restore the scope when an error is raised' do
|
98
124
|
expect do
|
99
125
|
@session.within("//div[@id='for_bar']") do
|
100
126
|
expect do
|
@@ -102,23 +128,30 @@ Capybara::SpecHelper.spec '#within' do
|
|
102
128
|
@session.within(".//div[@id='doesnotexist']") do
|
103
129
|
end
|
104
130
|
end.to raise_error(Capybara::ElementNotFound)
|
105
|
-
end.
|
131
|
+
end.not_to change { @session.has_xpath?(".//div[@id='another_foo']") }.from(false)
|
106
132
|
end
|
107
|
-
end.
|
133
|
+
end.not_to change { @session.has_xpath?(".//div[@id='another_foo']") }.from(true)
|
108
134
|
end
|
109
135
|
|
110
|
-
it
|
136
|
+
it 'should fill in a field and click a button' do
|
111
137
|
@session.within("//li[contains(.,'Bar')]") do
|
112
138
|
@session.click_button('Go')
|
113
139
|
end
|
114
140
|
expect(extract_results(@session)['first_name']).to eq('Peter')
|
115
141
|
@session.visit('/with_scope')
|
116
142
|
@session.within("//li[contains(.,'Bar')]") do
|
117
|
-
@session.fill_in('First Name', :
|
143
|
+
@session.fill_in('First Name', with: 'Dagobert')
|
118
144
|
@session.click_button('Go')
|
119
145
|
end
|
120
146
|
expect(extract_results(@session)['first_name']).to eq('Dagobert')
|
121
147
|
end
|
148
|
+
|
149
|
+
it 'should have #within_element as an alias' do
|
150
|
+
expect(Capybara::Session.instance_method(:within)).to eq Capybara::Session.instance_method(:within_element)
|
151
|
+
@session.within_element(:css, '#for_foo') do
|
152
|
+
expect(@session).not_to have_content('First Name')
|
153
|
+
end
|
154
|
+
end
|
122
155
|
end
|
123
156
|
|
124
157
|
Capybara::SpecHelper.spec '#within_fieldset' do
|
@@ -126,18 +159,18 @@ Capybara::SpecHelper.spec '#within_fieldset' do
|
|
126
159
|
@session.visit('/fieldsets')
|
127
160
|
end
|
128
161
|
|
129
|
-
it
|
130
|
-
@session.within_fieldset(
|
131
|
-
@session.fill_in(
|
132
|
-
@session.click_button(
|
162
|
+
it 'should restrict scope to a fieldset given by id' do
|
163
|
+
@session.within_fieldset('villain_fieldset') do
|
164
|
+
@session.fill_in('Name', with: 'Goldfinger')
|
165
|
+
@session.click_button('Create')
|
133
166
|
end
|
134
167
|
expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
|
135
168
|
end
|
136
169
|
|
137
|
-
it
|
138
|
-
@session.within_fieldset(
|
139
|
-
@session.fill_in(
|
140
|
-
@session.click_button(
|
170
|
+
it 'should restrict scope to a fieldset given by legend' do
|
171
|
+
@session.within_fieldset('Villain') do
|
172
|
+
@session.fill_in('Name', with: 'Goldfinger')
|
173
|
+
@session.click_button('Create')
|
141
174
|
end
|
142
175
|
expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
|
143
176
|
end
|
@@ -148,18 +181,18 @@ Capybara::SpecHelper.spec '#within_table' do
|
|
148
181
|
@session.visit('/tables')
|
149
182
|
end
|
150
183
|
|
151
|
-
it
|
152
|
-
@session.within_table(
|
153
|
-
@session.fill_in(
|
154
|
-
@session.click_button(
|
184
|
+
it 'should restrict scope to a fieldset given by id' do
|
185
|
+
@session.within_table('girl_table') do
|
186
|
+
@session.fill_in('Name', with: 'Christmas')
|
187
|
+
@session.click_button('Create')
|
155
188
|
end
|
156
189
|
expect(extract_results(@session)['girl_name']).to eq('Christmas')
|
157
190
|
end
|
158
191
|
|
159
|
-
it
|
160
|
-
@session.within_table(
|
161
|
-
@session.fill_in(
|
162
|
-
@session.click_button(
|
192
|
+
it 'should restrict scope to a fieldset given by legend' do
|
193
|
+
@session.within_table('Villain') do
|
194
|
+
@session.fill_in('Name', with: 'Quantum')
|
195
|
+
@session.click_button('Create')
|
163
196
|
end
|
164
197
|
expect(extract_results(@session)['villain_name']).to eq('Quantum')
|
165
198
|
end
|
@@ -1,27 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
RSpec::Matchers.module_eval do
|
12
|
-
alias be_truthy be_true
|
13
|
-
alias be_falsey be_false
|
14
|
-
alias be_falsy be_false
|
15
|
-
end
|
16
|
-
end
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec/expectations'
|
5
|
+
require 'capybara'
|
6
|
+
require 'capybara/rspec' # Required here instead of in rspec_spec to avoid RSpec deprecation warning
|
7
|
+
require 'capybara/spec/test_app'
|
8
|
+
require 'nokogiri'
|
9
|
+
|
10
|
+
Capybara.save_path = File.join(Dir.pwd, 'save_path_tmp')
|
17
11
|
|
18
12
|
module Capybara
|
19
13
|
module SpecHelper
|
20
14
|
class << self
|
21
15
|
def configure(config)
|
22
|
-
config.filter_run_excluding :
|
16
|
+
config.filter_run_excluding requires: method(:filter).to_proc
|
23
17
|
config.before { Capybara::SpecHelper.reset! }
|
24
18
|
config.after { Capybara::SpecHelper.reset! }
|
19
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
25
20
|
end
|
26
21
|
|
27
22
|
def reset!
|
@@ -31,15 +26,23 @@ module Capybara
|
|
31
26
|
Capybara.default_max_wait_time = 1
|
32
27
|
Capybara.ignore_hidden_elements = true
|
33
28
|
Capybara.exact = false
|
34
|
-
Capybara.exact_options = false
|
35
29
|
Capybara.raise_server_errors = true
|
36
30
|
Capybara.visible_text_only = false
|
37
31
|
Capybara.match = :smart
|
38
|
-
Capybara.
|
32
|
+
Capybara.enable_aria_label = false
|
33
|
+
Capybara.enable_aria_role = false
|
34
|
+
Capybara.default_set_options = {}
|
35
|
+
Capybara.disable_animation = false
|
36
|
+
Capybara.test_id = nil
|
37
|
+
Capybara.predicates_wait = true
|
38
|
+
Capybara.default_normalize_ws = false
|
39
|
+
Capybara.allow_gumbo = true
|
40
|
+
Capybara.w3c_click_offset = false
|
41
|
+
reset_threadsafe
|
39
42
|
end
|
40
43
|
|
41
44
|
def filter(requires, metadata)
|
42
|
-
if requires
|
45
|
+
if requires && metadata[:capybara_skip]
|
43
46
|
requires.any? do |require|
|
44
47
|
metadata[:capybara_skip].include?(require)
|
45
48
|
end
|
@@ -48,53 +51,84 @@ module Capybara
|
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
|
-
def spec(name, options
|
54
|
+
def spec(name, *options, &block)
|
52
55
|
@specs ||= []
|
53
56
|
@specs << [name, options, block]
|
54
57
|
end
|
55
58
|
|
56
|
-
def run_specs(session, name, options
|
59
|
+
def run_specs(session, name, **options, &filter_block)
|
57
60
|
specs = @specs
|
58
61
|
RSpec.describe Capybara::Session, name, options do
|
59
62
|
include Capybara::SpecHelper
|
60
63
|
include Capybara::RSpecMatchers
|
61
|
-
|
64
|
+
|
65
|
+
before do |example|
|
62
66
|
@session = session
|
67
|
+
instance_exec(example, &filter_block) if filter_block
|
63
68
|
end
|
69
|
+
|
64
70
|
after do
|
65
|
-
|
71
|
+
session.reset_session!
|
66
72
|
end
|
73
|
+
|
74
|
+
before :each, psc: true do
|
75
|
+
SpecHelper.reset_threadsafe(bool: true, session: session)
|
76
|
+
end
|
77
|
+
|
78
|
+
after psc: true do
|
79
|
+
SpecHelper.reset_threadsafe(session: session)
|
80
|
+
end
|
81
|
+
|
82
|
+
before :each, :exact_false do
|
83
|
+
Capybara.exact = false
|
84
|
+
end
|
85
|
+
|
67
86
|
specs.each do |spec_name, spec_options, block|
|
68
|
-
describe spec_name, spec_options do
|
87
|
+
describe spec_name, *spec_options do
|
69
88
|
class_eval(&block)
|
70
89
|
end
|
71
90
|
end
|
72
91
|
end
|
73
92
|
end
|
74
|
-
|
93
|
+
|
94
|
+
def reset_threadsafe(bool: false, session: nil)
|
95
|
+
# Work around limit on when threadsafe can be changed
|
96
|
+
Capybara::Session.class_variable_set(:@@instance_created, false) # rubocop:disable Style/ClassVars
|
97
|
+
Capybara.threadsafe = bool
|
98
|
+
session = session.current_session if session.respond_to?(:current_session)
|
99
|
+
session&.instance_variable_set(:@config, nil)
|
100
|
+
end
|
101
|
+
end
|
75
102
|
|
76
103
|
def silence_stream(stream)
|
77
104
|
old_stream = stream.dup
|
78
|
-
stream.reopen(RbConfig::CONFIG['host_os']
|
105
|
+
stream.reopen(RbConfig::CONFIG['host_os'].match?(/rmswin|mingw/) ? 'NUL:' : '/dev/null')
|
79
106
|
stream.sync = true
|
80
107
|
yield
|
81
108
|
ensure
|
82
109
|
stream.reopen(old_stream)
|
83
110
|
end
|
84
111
|
|
85
|
-
def quietly
|
86
|
-
silence_stream(
|
87
|
-
silence_stream(
|
88
|
-
yield
|
89
|
-
end
|
112
|
+
def quietly(&block)
|
113
|
+
silence_stream($stdout) do
|
114
|
+
silence_stream($stderr, &block)
|
90
115
|
end
|
91
116
|
end
|
92
117
|
|
93
118
|
def extract_results(session)
|
94
119
|
expect(session).to have_xpath("//pre[@id='results']")
|
95
|
-
YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
|
120
|
+
# YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
|
121
|
+
YAML.load Capybara::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
|
122
|
+
end
|
123
|
+
|
124
|
+
def be_an_invalid_element_error(session)
|
125
|
+
satisfy { |error| session.driver.invalid_element_errors.any? { |e| error.is_a? e } }
|
126
|
+
end
|
127
|
+
|
128
|
+
def with_os_path_separators(path)
|
129
|
+
Gem.win_platform? ? path.to_s.tr('/', '\\') : path.to_s
|
96
130
|
end
|
97
131
|
end
|
98
132
|
end
|
99
133
|
|
100
|
-
Dir[File.dirname(__FILE__)
|
134
|
+
Dir["#{File.dirname(__FILE__)}/session/**/*.rb"].each { |file| require_relative file }
|
@@ -1,12 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'sinatra/base'
|
3
4
|
require 'tilt/erb'
|
4
5
|
require 'rack'
|
5
6
|
require 'yaml'
|
6
7
|
|
7
8
|
class TestApp < Sinatra::Base
|
8
|
-
class TestAppError <
|
9
|
+
class TestAppError < Exception; end # rubocop:disable Lint/InheritException
|
9
10
|
|
11
|
+
class TestAppOtherError < Exception # rubocop:disable Lint/InheritException
|
12
|
+
def initialize(string1, msg)
|
13
|
+
super()
|
14
|
+
@something = string1
|
15
|
+
@message = msg
|
16
|
+
end
|
17
|
+
end
|
10
18
|
set :root, File.dirname(__FILE__)
|
11
19
|
set :static, true
|
12
20
|
set :raise_errors, true
|
@@ -15,7 +23,7 @@ class TestApp < Sinatra::Base
|
|
15
23
|
# Also check lib/capybara/spec/views/*.erb for pages not listed here
|
16
24
|
|
17
25
|
get '/' do
|
18
|
-
response.set_cookie('capybara',
|
26
|
+
response.set_cookie('capybara', value: 'root cookie', domain: request.host, path: request.path)
|
19
27
|
'Hello world! <a href="with_html">Relative</a>'
|
20
28
|
end
|
21
29
|
|
@@ -27,13 +35,25 @@ class TestApp < Sinatra::Base
|
|
27
35
|
redirect '/redirect_again'
|
28
36
|
end
|
29
37
|
|
38
|
+
get '/redirect_with_fragment' do
|
39
|
+
redirect '/landed#with_fragment'
|
40
|
+
end
|
41
|
+
|
30
42
|
get '/redirect_again' do
|
31
43
|
redirect '/landed'
|
32
44
|
end
|
33
45
|
|
46
|
+
post '/redirect_307' do
|
47
|
+
redirect '/landed', 307
|
48
|
+
end
|
49
|
+
|
50
|
+
post '/redirect_308' do
|
51
|
+
redirect '/landed', 308
|
52
|
+
end
|
53
|
+
|
34
54
|
get '/referer_base' do
|
35
|
-
'<a href="/get_referer">direct link</a>'
|
36
|
-
'<a href="/redirect_to_get_referer">link via redirect</a>'
|
55
|
+
'<a href="/get_referer">direct link</a>' \
|
56
|
+
'<a href="/redirect_to_get_referer">link via redirect</a>' \
|
37
57
|
'<form action="/get_referer" method="get"><input type="submit"></form>'
|
38
58
|
end
|
39
59
|
|
@@ -42,7 +62,7 @@ class TestApp < Sinatra::Base
|
|
42
62
|
end
|
43
63
|
|
44
64
|
get '/get_referer' do
|
45
|
-
request.referer.nil? ?
|
65
|
+
request.referer.nil? ? 'No referer' : "Got referer: #{request.referer}"
|
46
66
|
end
|
47
67
|
|
48
68
|
get '/host' do
|
@@ -52,26 +72,30 @@ class TestApp < Sinatra::Base
|
|
52
72
|
get '/redirect/:times/times' do
|
53
73
|
times = params[:times].to_i
|
54
74
|
if times.zero?
|
55
|
-
|
75
|
+
'redirection complete'
|
56
76
|
else
|
57
77
|
redirect "/redirect/#{times - 1}/times"
|
58
78
|
end
|
59
79
|
end
|
60
80
|
|
61
81
|
get '/landed' do
|
62
|
-
|
82
|
+
'You landed'
|
83
|
+
end
|
84
|
+
|
85
|
+
post '/landed' do
|
86
|
+
"You post landed: #{params.dig(:form, 'data')}"
|
63
87
|
end
|
64
88
|
|
65
89
|
get '/with-quotes' do
|
66
|
-
%q
|
90
|
+
%q("No," he said, "you can't do that.")
|
67
91
|
end
|
68
92
|
|
69
93
|
get '/form/get' do
|
70
|
-
|
94
|
+
%(<pre id="results">#{params[:form].to_yaml}</pre>)
|
71
95
|
end
|
72
96
|
|
73
97
|
post '/relative' do
|
74
|
-
|
98
|
+
%(<pre id="results">#{params[:form].to_yaml}</pre>)
|
75
99
|
end
|
76
100
|
|
77
101
|
get '/favicon.ico' do
|
@@ -82,12 +106,12 @@ class TestApp < Sinatra::Base
|
|
82
106
|
redirect '/redirect_again'
|
83
107
|
end
|
84
108
|
|
85
|
-
delete
|
86
|
-
|
109
|
+
delete '/delete' do
|
110
|
+
'The requested object was deleted'
|
87
111
|
end
|
88
112
|
|
89
|
-
get
|
90
|
-
|
113
|
+
get '/delete' do
|
114
|
+
'Not deleted'
|
91
115
|
end
|
92
116
|
|
93
117
|
get '/redirect_back' do
|
@@ -122,7 +146,11 @@ class TestApp < Sinatra::Base
|
|
122
146
|
end
|
123
147
|
|
124
148
|
get '/error' do
|
125
|
-
raise TestAppError,
|
149
|
+
raise TestAppError, 'some error'
|
150
|
+
end
|
151
|
+
|
152
|
+
get '/other_error' do
|
153
|
+
raise TestAppOtherError.new('something', 'other error')
|
126
154
|
end
|
127
155
|
|
128
156
|
get '/load_error' do
|
@@ -133,12 +161,28 @@ class TestApp < Sinatra::Base
|
|
133
161
|
erb :with_html, locals: { referrer: request.referrer }
|
134
162
|
end
|
135
163
|
|
164
|
+
get '/with_title' do
|
165
|
+
<<-HTML
|
166
|
+
<title>#{params[:title] || 'Test Title'}</title>
|
167
|
+
<body>
|
168
|
+
<svg><title>abcdefg</title></svg>
|
169
|
+
</body>
|
170
|
+
HTML
|
171
|
+
end
|
172
|
+
|
173
|
+
get '/download.csv' do
|
174
|
+
content_type 'text/csv'
|
175
|
+
'This, is, comma, separated' \
|
176
|
+
'Thomas, Walpole, was , here'
|
177
|
+
end
|
178
|
+
|
136
179
|
get '/:view' do |view|
|
137
180
|
erb view.to_sym, locals: { referrer: request.referrer }
|
138
181
|
end
|
139
182
|
|
140
183
|
post '/form' do
|
141
|
-
|
184
|
+
self.class.form_post_count += 1
|
185
|
+
%(<pre id="results">#{params[:form].merge('post_count' => self.class.form_post_count).to_yaml}</pre>)
|
142
186
|
end
|
143
187
|
|
144
188
|
post '/upload_empty' do
|
@@ -150,30 +194,35 @@ class TestApp < Sinatra::Base
|
|
150
194
|
end
|
151
195
|
|
152
196
|
post '/upload' do
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
'No file uploaded'
|
160
|
-
end
|
197
|
+
buffer = []
|
198
|
+
buffer << "Content-type: #{params.dig(:form, :document, :type)}"
|
199
|
+
buffer << "File content: #{params.dig(:form, :document, :tempfile).read}"
|
200
|
+
buffer.join(' | ')
|
201
|
+
rescue StandardError
|
202
|
+
'No file uploaded'
|
161
203
|
end
|
162
204
|
|
163
205
|
post '/upload_multiple' do
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
170
|
-
buffer.join(' | ')
|
171
|
-
rescue
|
172
|
-
'No files uploaded'
|
206
|
+
docs = params.dig(:form, :multiple_documents)
|
207
|
+
buffer = [docs.size.to_s]
|
208
|
+
docs.each do |doc|
|
209
|
+
buffer << "Content-type: #{doc[:type]}"
|
210
|
+
buffer << "File content: #{doc[:tempfile].read}"
|
173
211
|
end
|
212
|
+
buffer.join(' | ')
|
213
|
+
rescue StandardError
|
214
|
+
'No files uploaded'
|
215
|
+
end
|
216
|
+
|
217
|
+
get '/apple-touch-icon-precomposed.png' do
|
218
|
+
halt(404)
|
174
219
|
end
|
175
|
-
end
|
176
220
|
|
177
|
-
|
178
|
-
|
221
|
+
class << self
|
222
|
+
attr_accessor :form_post_count
|
223
|
+
end
|
224
|
+
|
225
|
+
@form_post_count = 0
|
179
226
|
end
|
227
|
+
|
228
|
+
Rack::Handler::Puma.run TestApp, Port: 8070 if $PROGRAM_NAME == __FILE__
|