capybara 3.0.0 → 3.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/History.md +777 -10
- data/License.txt +1 -1
- data/README.md +75 -58
- data/lib/capybara/config.rb +29 -10
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +22 -4
- data/lib/capybara/driver/node.rb +34 -9
- data/lib/capybara/dsl.rb +14 -6
- data/lib/capybara/helpers.rb +52 -7
- data/lib/capybara/minitest/spec.rb +173 -84
- data/lib/capybara/minitest.rb +250 -144
- data/lib/capybara/node/actions.rb +248 -124
- data/lib/capybara/node/base.rb +34 -20
- data/lib/capybara/node/document.rb +14 -2
- data/lib/capybara/node/document_matchers.rb +13 -15
- data/lib/capybara/node/element.rb +339 -113
- data/lib/capybara/node/finders.rb +95 -82
- data/lib/capybara/node/matchers.rb +338 -157
- data/lib/capybara/node/simple.rb +54 -15
- data/lib/capybara/queries/active_element_query.rb +18 -0
- data/lib/capybara/queries/ancestor_query.rb +9 -10
- data/lib/capybara/queries/base_query.rb +25 -18
- data/lib/capybara/queries/current_path_query.rb +16 -6
- data/lib/capybara/queries/match_query.rb +11 -0
- data/lib/capybara/queries/selector_query.rb +600 -103
- data/lib/capybara/queries/sibling_query.rb +9 -7
- data/lib/capybara/queries/style_query.rb +45 -0
- data/lib/capybara/queries/text_query.rb +40 -22
- data/lib/capybara/queries/title_query.rb +2 -2
- data/lib/capybara/rack_test/browser.rb +47 -28
- data/lib/capybara/rack_test/driver.rb +12 -3
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +53 -50
- data/lib/capybara/rack_test/node.rb +114 -37
- data/lib/capybara/rails.rb +1 -1
- 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 +86 -52
- data/lib/capybara/rspec/features.rb +8 -10
- data/lib/capybara/rspec/matcher_proxies.rb +39 -18
- 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 +138 -316
- data/lib/capybara/rspec.rb +3 -2
- 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 -12
- data/lib/capybara/selector/definition/button.rb +68 -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 +279 -0
- data/lib/capybara/selector/filter.rb +1 -0
- data/lib/capybara/selector/filter_set.rb +72 -27
- data/lib/capybara/selector/filters/base.rb +45 -2
- data/lib/capybara/selector/filters/expression_filter.rb +5 -6
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +18 -4
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +85 -200
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +226 -537
- 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 +296 -238
- 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 +436 -166
- 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 +69 -0
- data/lib/capybara/server/checker.rb +44 -0
- data/lib/capybara/server/middleware.rb +71 -0
- data/lib/capybara/server.rb +58 -67
- data/lib/capybara/session/config.rb +38 -6
- data/lib/capybara/session/matchers.rb +26 -19
- data/lib/capybara/session.rb +258 -190
- 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 +122 -8
- data/lib/capybara/spec/session/accept_alert_spec.rb +11 -11
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
- data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
- data/lib/capybara/spec/session/active_element_spec.rb +31 -0
- data/lib/capybara/spec/session/all_spec.rb +135 -42
- data/lib/capybara/spec/session/ancestor_spec.rb +24 -19
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +67 -38
- data/lib/capybara/spec/session/{assert_current_path.rb → assert_current_path_spec.rb} +20 -18
- 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} +62 -38
- data/lib/capybara/spec/session/{assert_title.rb → assert_title_spec.rb} +12 -12
- data/lib/capybara/spec/session/attach_file_spec.rb +120 -72
- data/lib/capybara/spec/session/body_spec.rb +11 -13
- data/lib/capybara/spec/session/check_spec.rb +111 -51
- data/lib/capybara/spec/session/choose_spec.rb +62 -30
- data/lib/capybara/spec/session/click_button_spec.rb +227 -161
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +49 -30
- data/lib/capybara/spec/session/click_link_spec.rb +78 -55
- data/lib/capybara/spec/session/current_scope_spec.rb +7 -7
- data/lib/capybara/spec/session/current_url_spec.rb +44 -37
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -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 +8 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +70 -56
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
- data/lib/capybara/spec/session/evaluate_script_spec.rb +28 -8
- data/lib/capybara/spec/session/execute_script_spec.rb +8 -7
- data/lib/capybara/spec/session/fill_in_spec.rb +104 -44
- data/lib/capybara/spec/session/find_button_spec.rb +23 -23
- data/lib/capybara/spec/session/find_by_id_spec.rb +8 -8
- data/lib/capybara/spec/session/find_field_spec.rb +33 -31
- data/lib/capybara/spec/session/find_link_spec.rb +32 -14
- data/lib/capybara/spec/session/find_spec.rb +236 -141
- data/lib/capybara/spec/session/first_spec.rb +44 -43
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +6 -6
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +6 -6
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +32 -20
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +44 -19
- data/lib/capybara/spec/session/go_back_spec.rb +1 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +18 -18
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +29 -0
- data/lib/capybara/spec/session/has_button_spec.rb +92 -12
- data/lib/capybara/spec/session/has_css_spec.rb +271 -137
- data/lib/capybara/spec/session/has_current_path_spec.rb +48 -33
- data/lib/capybara/spec/session/has_field_spec.rb +137 -58
- data/lib/capybara/spec/session/has_link_spec.rb +30 -6
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +26 -24
- data/lib/capybara/spec/session/has_select_spec.rb +75 -47
- data/lib/capybara/spec/session/has_selector_spec.rb +102 -69
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +170 -4
- data/lib/capybara/spec/session/has_text_spec.rb +108 -52
- data/lib/capybara/spec/session/has_title_spec.rb +19 -14
- data/lib/capybara/spec/session/has_xpath_spec.rb +56 -38
- data/lib/capybara/spec/session/{headers.rb → headers_spec.rb} +1 -1
- data/lib/capybara/spec/session/html_spec.rb +13 -6
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +871 -122
- data/lib/capybara/spec/session/node_wrapper_spec.rb +15 -12
- data/lib/capybara/spec/session/refresh_spec.rb +9 -7
- data/lib/capybara/spec/session/reset_session_spec.rb +52 -37
- data/lib/capybara/spec/session/{response_code.rb → response_code_spec.rb} +1 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +5 -4
- data/lib/capybara/spec/session/save_page_spec.rb +41 -38
- data/lib/capybara/spec/session/save_screenshot_spec.rb +13 -11
- 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 +102 -76
- data/lib/capybara/spec/session/selectors_spec.rb +51 -18
- data/lib/capybara/spec/session/sibling_spec.rb +9 -9
- data/lib/capybara/spec/session/text_spec.rb +26 -24
- data/lib/capybara/spec/session/title_spec.rb +8 -6
- data/lib/capybara/spec/session/uncheck_spec.rb +40 -21
- data/lib/capybara/spec/session/unselect_spec.rb +37 -37
- data/lib/capybara/spec/session/visit_spec.rb +59 -53
- data/lib/capybara/spec/session/window/become_closed_spec.rb +22 -19
- data/lib/capybara/spec/session/window/current_window_spec.rb +4 -3
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +4 -3
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +25 -21
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +10 -5
- data/lib/capybara/spec/session/window/window_spec.rb +88 -54
- data/lib/capybara/spec/session/window/windows_spec.rb +10 -7
- data/lib/capybara/spec/session/window/within_window_spec.rb +17 -16
- data/lib/capybara/spec/session/within_spec.rb +69 -44
- data/lib/capybara/spec/spec_helper.rb +41 -53
- data/lib/capybara/spec/test_app.rb +79 -40
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +134 -42
- data/lib/capybara/spec/views/frame_child.erb +4 -3
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +1 -1
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +2 -1
- data/lib/capybara/spec/views/layout.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +47 -0
- data/lib/capybara/spec/views/offset.erb +33 -0
- data/lib/capybara/spec/views/path.erb +2 -2
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/scroll.erb +21 -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 +81 -0
- data/lib/capybara/spec/views/with_base_tag.erb +2 -2
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
- data/lib/capybara/spec/views/with_hover.erb +3 -2
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +43 -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 +30 -5
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_namespace.erb +21 -0
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
- data/lib/capybara/spec/views/with_windows.erb +1 -1
- data/lib/capybara/spec/views/within_frames.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +31 -25
- data/lib/capybara.rb +120 -100
- data/spec/basic_node_spec.rb +59 -34
- data/spec/capybara_spec.rb +54 -52
- data/spec/css_builder_spec.rb +101 -0
- data/spec/css_splitter_spec.rb +38 -0
- data/spec/dsl_spec.rb +80 -53
- data/spec/filter_set_spec.rb +24 -7
- data/spec/fixtures/certificate.pem +25 -0
- data/spec/fixtures/key.pem +27 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +4 -4
- data/spec/fixtures/selenium_driver_rspec_success.rb +4 -4
- data/spec/minitest_spec.rb +38 -5
- data/spec/minitest_spec_spec.rb +88 -62
- data/spec/per_session_config_spec.rb +5 -5
- data/spec/rack_test_spec.rb +169 -115
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +86 -33
- data/spec/rspec/features_spec.rb +26 -23
- data/spec/rspec/scenarios_spec.rb +8 -4
- data/spec/rspec/shared_spec_matchers.rb +393 -363
- data/spec/rspec/views_spec.rb +4 -3
- data/spec/rspec_matchers_spec.rb +10 -10
- data/spec/rspec_spec.rb +109 -85
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +391 -61
- data/spec/selenium_spec_chrome.rb +180 -41
- data/spec/selenium_spec_chrome_remote.rb +101 -0
- data/spec/selenium_spec_edge.rb +28 -8
- data/spec/selenium_spec_firefox.rb +211 -0
- data/spec/selenium_spec_firefox_remote.rb +80 -0
- data/spec/selenium_spec_ie.rb +127 -11
- data/spec/selenium_spec_safari.rb +156 -0
- data/spec/server_spec.rb +177 -78
- data/spec/session_spec.rb +52 -16
- data/spec/shared_selenium_node.rb +79 -0
- data/spec/shared_selenium_session.rb +455 -123
- data/spec/spec_helper.rb +91 -2
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +343 -42
- 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/rspec/compound.rb +0 -90
- data/lib/capybara/spec/session/assert_selector.rb +0 -149
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/lib/capybara/spec/views/with_title.erb +0 -5
- data/spec/selenium_spec_marionette.rb +0 -143
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#visit' do
|
4
|
-
it
|
4
|
+
it 'should fetch a response from the driver with a relative url' do
|
5
5
|
@session.visit('/')
|
6
6
|
expect(@session).to have_content('Hello world!')
|
7
7
|
@session.visit('/foo')
|
8
8
|
expect(@session).to have_content('Another World')
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'should fetch a response from the driver with an absolute url with a port' do
|
12
12
|
# Preparation
|
13
13
|
@session.visit('/')
|
14
14
|
root_uri = URI.parse(@session.current_url)
|
@@ -28,41 +28,40 @@ Capybara::SpecHelper.spec '#visit' do
|
|
28
28
|
expect(@session).to have_content('Hello world!')
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
skip "Chrome/chromedriver has an issue visiting URL with target after visiting same URL without target" if chrome_lt?(65.0, @session)
|
31
|
+
it 'should fetch a response when sequentially visiting same destination with a target' do
|
33
32
|
@session.visit('/form')
|
34
33
|
expect(@session).to have_css('#form_title')
|
35
34
|
@session.visit('/form#form_title')
|
36
35
|
expect(@session).to have_css('#form_title')
|
37
36
|
end
|
38
37
|
|
39
|
-
it
|
40
|
-
quietly { @session.visit(
|
38
|
+
it 'raises any errors caught inside the server', requires: [:server] do
|
39
|
+
quietly { @session.visit('/error') }
|
41
40
|
expect do
|
42
|
-
@session.visit(
|
41
|
+
@session.visit('/')
|
43
42
|
end.to raise_error(TestApp::TestAppError)
|
44
43
|
end
|
45
44
|
|
46
|
-
it
|
47
|
-
@session.visit(
|
48
|
-
@session.assert_no_selector :xpath,
|
45
|
+
it 'should be able to open non-http url', requires: [:about_scheme] do
|
46
|
+
@session.visit('about:blank')
|
47
|
+
@session.assert_no_selector :xpath, '/html/body/*'
|
49
48
|
end
|
50
49
|
|
51
|
-
context
|
50
|
+
context 'when Capybara.always_include_port is true' do
|
52
51
|
let(:root_uri) do
|
53
52
|
@session.visit('/')
|
54
53
|
URI.parse(@session.current_url)
|
55
54
|
end
|
56
55
|
|
57
|
-
before
|
56
|
+
before do
|
58
57
|
Capybara.always_include_port = true
|
59
58
|
end
|
60
59
|
|
61
|
-
after
|
60
|
+
after do
|
62
61
|
Capybara.always_include_port = false
|
63
62
|
end
|
64
63
|
|
65
|
-
it
|
64
|
+
it 'should fetch a response from the driver with an absolute url without a port' do
|
66
65
|
@session.visit("http://#{root_uri.host}/")
|
67
66
|
expect(URI.parse(@session.current_url).port).to eq(root_uri.port)
|
68
67
|
expect(@session).to have_content('Hello world!')
|
@@ -72,126 +71,133 @@ Capybara::SpecHelper.spec '#visit' do
|
|
72
71
|
expect(@session).to have_content('Another World')
|
73
72
|
end
|
74
73
|
|
75
|
-
it
|
76
|
-
|
77
|
-
@session.visit(
|
74
|
+
it 'should add the server port to a visited url if no port specified', requires: [:server] do
|
75
|
+
allow(@session.driver).to receive(:visit)
|
76
|
+
@session.visit('http://www.example.com')
|
77
|
+
expect(@session.driver).to have_received(:visit).with("http://www.example.com:#{@session.server.port}")
|
78
78
|
end
|
79
79
|
|
80
|
-
it
|
81
|
-
|
80
|
+
it 'should not override the visit specified port even if default for scheme', requires: [:server] do
|
81
|
+
allow(@session.driver).to receive(:visit)
|
82
82
|
@session.visit('http://www.example.com:80')
|
83
|
+
expect(@session.driver).to have_received(:visit).with('http://www.example.com:80')
|
83
84
|
end
|
84
85
|
|
85
|
-
it
|
86
|
-
|
87
|
-
|
86
|
+
it 'should give preference to app_host port if specified', requires: [:server] do
|
87
|
+
allow(@session.driver).to receive(:visit)
|
88
|
+
Capybara.app_host = 'http://www.example.com:6666'
|
88
89
|
@session.visit('/random')
|
90
|
+
expect(@session.driver).to have_received(:visit).with('http://www.example.com:6666/random')
|
89
91
|
end
|
90
92
|
|
91
93
|
it "shouldn't override port if no server", requires: [:server] do
|
92
94
|
session = Capybara::Session.new(@session.mode, nil)
|
93
|
-
|
94
|
-
session.visit(
|
95
|
+
allow(session.driver).to receive(:visit)
|
96
|
+
session.visit('http://www.google.com')
|
97
|
+
expect(session.driver).to have_received(:visit).with('http://www.google.com')
|
95
98
|
end
|
96
99
|
|
97
100
|
it "shouldn't override port if no server but app_host is set", requires: [:server] do
|
98
101
|
session = Capybara::Session.new(@session.mode, nil)
|
99
|
-
Capybara.app_host =
|
100
|
-
|
101
|
-
session.visit(
|
102
|
+
Capybara.app_host = 'http://www.example.com:6666'
|
103
|
+
allow(session.driver).to receive(:visit)
|
104
|
+
session.visit('http://www.google.com')
|
105
|
+
expect(session.driver).to have_received(:visit).with('http://www.google.com')
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
105
|
-
context
|
106
|
-
before
|
109
|
+
context 'when Capybara.always_include_port is false' do
|
110
|
+
before do
|
107
111
|
Capybara.always_include_port = false
|
108
112
|
end
|
109
113
|
|
110
114
|
it "shouldn't overwrite port if app_host is set", requires: [:server] do
|
111
115
|
session = Capybara::Session.new(@session.mode, nil)
|
112
|
-
Capybara.app_host =
|
113
|
-
|
114
|
-
session.visit(
|
116
|
+
Capybara.app_host = 'http://www.example.com:6666'
|
117
|
+
allow(session.driver).to receive(:visit)
|
118
|
+
session.visit('http://www.google.com')
|
119
|
+
expect(session.driver).to have_received(:visit).with('http://www.google.com')
|
115
120
|
end
|
116
121
|
|
117
122
|
it "shouldn't overwrite port if port specfified", requires: [:server] do
|
118
123
|
session = Capybara::Session.new(@session.mode, nil)
|
119
|
-
Capybara.app_host =
|
120
|
-
|
121
|
-
session.visit(
|
124
|
+
Capybara.app_host = 'http://www.example.com:6666'
|
125
|
+
allow(session.driver).to receive(:visit)
|
126
|
+
session.visit('http://www.google.com:99')
|
127
|
+
expect(session.driver).to have_received(:visit).with('http://www.google.com:99')
|
122
128
|
end
|
123
129
|
end
|
124
130
|
|
125
|
-
context
|
126
|
-
it
|
131
|
+
context 'without a server', requires: [:server] do
|
132
|
+
it 'should respect `app_host`' do
|
127
133
|
serverless_session = Capybara::Session.new(@session.mode, nil)
|
128
134
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
129
|
-
serverless_session.visit(
|
130
|
-
expect(serverless_session).to have_content(
|
135
|
+
serverless_session.visit('/foo')
|
136
|
+
expect(serverless_session).to have_content('Another World')
|
131
137
|
end
|
132
138
|
|
133
|
-
it
|
139
|
+
it 'should visit a fully qualified URL' do
|
134
140
|
serverless_session = Capybara::Session.new(@session.mode, nil)
|
135
141
|
serverless_session.visit("http://#{@session.server.host}:#{@session.server.port}/foo")
|
136
|
-
expect(serverless_session).to have_content(
|
142
|
+
expect(serverless_session).to have_content('Another World')
|
137
143
|
end
|
138
144
|
end
|
139
145
|
|
140
|
-
context
|
141
|
-
it
|
146
|
+
context 'with Capybara.app_host set' do
|
147
|
+
it 'should override server', requires: [:server] do
|
142
148
|
another_session = Capybara::Session.new(@session.mode, @session.app.dup)
|
143
149
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
144
150
|
another_session.visit('/foo')
|
145
|
-
expect(another_session).to have_content(
|
151
|
+
expect(another_session).to have_content('Another World')
|
146
152
|
expect(another_session.current_url).to start_with(Capybara.app_host)
|
147
153
|
expect(URI.parse(another_session.current_url).port).not_to eq another_session.server.port
|
148
154
|
expect(URI.parse(another_session.current_url).port).to eq @session.server.port
|
149
155
|
end
|
150
156
|
|
151
|
-
it
|
157
|
+
it 'should append relative path', requires: [:server] do
|
152
158
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}/redirect/0"
|
153
159
|
@session.visit('/times')
|
154
160
|
expect(@session).to have_content('redirection complete')
|
155
161
|
end
|
156
162
|
|
157
|
-
it
|
163
|
+
it 'should work if `app_host` has a trailing /', requires: [:server] do
|
158
164
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}/"
|
159
165
|
@session.visit('/')
|
160
166
|
expect(@session).to have_content('Hello world!')
|
161
167
|
end
|
162
168
|
end
|
163
169
|
|
164
|
-
it
|
170
|
+
it 'should send no referer when visiting a page' do
|
165
171
|
@session.visit '/get_referer'
|
166
172
|
expect(@session).to have_content 'No referer'
|
167
173
|
end
|
168
174
|
|
169
|
-
it
|
175
|
+
it 'should send no referer when visiting a second page' do
|
170
176
|
@session.visit '/get_referer'
|
171
177
|
@session.visit '/get_referer'
|
172
178
|
expect(@session).to have_content 'No referer'
|
173
179
|
end
|
174
180
|
|
175
|
-
it
|
181
|
+
it 'should send a referer when following a link' do
|
176
182
|
@session.visit '/referer_base'
|
177
183
|
@session.find('//a[@href="/get_referer"]').click
|
178
184
|
expect(@session).to have_content %r{http://.*/referer_base}
|
179
185
|
end
|
180
186
|
|
181
|
-
it
|
187
|
+
it 'should preserve the original referer URL when following a redirect' do
|
182
188
|
@session.visit('/referer_base')
|
183
189
|
@session.find('//a[@href="/redirect_to_get_referer"]').click
|
184
190
|
expect(@session).to have_content %r{http://.*/referer_base}
|
185
191
|
end
|
186
192
|
|
187
|
-
it
|
193
|
+
it 'should send a referer when submitting a form' do
|
188
194
|
@session.visit '/referer_base'
|
189
195
|
@session.find('//input').click
|
190
196
|
expect(@session).to have_content %r{http://.*/referer_base}
|
191
197
|
end
|
192
198
|
|
193
|
-
it
|
194
|
-
@session.visit(
|
199
|
+
it 'can set cookie if a blank path is specified' do
|
200
|
+
@session.visit('')
|
195
201
|
@session.visit('/get_cookie')
|
196
202
|
expect(@session).to have_content('root cookie')
|
197
203
|
end
|
@@ -1,38 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
|
4
|
-
|
5
|
-
|
6
|
-
@session.
|
7
|
-
@other_window = @session.window_opened_by do
|
4
|
+
let!(:window) { @session.current_window }
|
5
|
+
let(:other_window) do
|
6
|
+
@session.window_opened_by do
|
8
7
|
@session.find(:css, '#openWindow').click
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
before do
|
12
|
+
@session.visit('/with_windows')
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
13
16
|
@session.document.synchronize(5, errors: [Capybara::CapybaraError]) do
|
14
17
|
raise Capybara::CapybaraError if @session.windows.size != 1
|
15
18
|
end
|
16
|
-
@session.switch_to_window(
|
19
|
+
@session.switch_to_window(window)
|
17
20
|
end
|
18
21
|
|
19
22
|
context 'with :wait option' do
|
20
23
|
it 'should wait if value of :wait is more than timeout' do
|
21
|
-
@session.within_window
|
24
|
+
@session.within_window other_window do
|
22
25
|
@session.execute_script('setTimeout(function(){ window.close(); }, 500);')
|
23
26
|
end
|
24
27
|
Capybara.using_wait_time 0.1 do
|
25
|
-
expect(
|
28
|
+
expect(other_window).to become_closed(wait: 5)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
32
|
it 'should raise error if value of :wait is less than timeout' do
|
30
|
-
@session.within_window
|
33
|
+
@session.within_window other_window do
|
31
34
|
@session.execute_script('setTimeout(function(){ window.close(); }, 1000);')
|
32
35
|
end
|
33
36
|
Capybara.using_wait_time 2 do
|
34
37
|
expect do
|
35
|
-
expect(
|
38
|
+
expect(other_window).to become_closed(wait: 0.2)
|
36
39
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> to become closed after 0.2 seconds\Z/)
|
37
40
|
end
|
38
41
|
end
|
@@ -40,21 +43,21 @@ Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
|
|
40
43
|
|
41
44
|
context 'without :wait option' do
|
42
45
|
it 'should wait if value of default_max_wait_time is more than timeout' do
|
43
|
-
@session.within_window
|
46
|
+
@session.within_window other_window do
|
44
47
|
@session.execute_script('setTimeout(function(){ window.close(); }, 500);')
|
45
48
|
end
|
46
49
|
Capybara.using_wait_time 5 do
|
47
|
-
expect(
|
50
|
+
expect(other_window).to become_closed
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
54
|
it 'should raise error if value of default_max_wait_time is less than timeout' do
|
52
|
-
@session.within_window
|
55
|
+
@session.within_window other_window do
|
53
56
|
@session.execute_script('setTimeout(function(){ window.close(); }, 900);')
|
54
57
|
end
|
55
58
|
Capybara.using_wait_time 0.4 do
|
56
59
|
expect do
|
57
|
-
expect(
|
60
|
+
expect(other_window).to become_closed
|
58
61
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> to become closed after 0.4 seconds\Z/)
|
59
62
|
end
|
60
63
|
end
|
@@ -62,23 +65,23 @@ Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
|
|
62
65
|
|
63
66
|
context 'with not_to' do
|
64
67
|
it "should not raise error if window doesn't close before default_max_wait_time" do
|
65
|
-
@session.within_window
|
68
|
+
@session.within_window other_window do
|
66
69
|
@session.execute_script('setTimeout(function(){ window.close(); }, 1000);')
|
67
70
|
end
|
68
71
|
Capybara.using_wait_time 0.3 do
|
69
72
|
expect do
|
70
|
-
expect(
|
71
|
-
end
|
73
|
+
expect(other_window).not_to become_closed
|
74
|
+
end.not_to raise_error
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
75
78
|
it 'should raise error if window closes before default_max_wait_time' do
|
76
|
-
@session.within_window
|
79
|
+
@session.within_window other_window do
|
77
80
|
@session.execute_script('setTimeout(function(){ window.close(); }, 700);')
|
78
81
|
end
|
79
82
|
Capybara.using_wait_time 3.1 do
|
80
83
|
expect do
|
81
|
-
expect(
|
84
|
+
expect(other_window).not_to become_closed
|
82
85
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> not to become closed after 3.1 seconds\Z/)
|
83
86
|
end
|
84
87
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#current_window', requires: [:windows] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
|
+
after do
|
9
10
|
(@session.windows - [@window]).each do |w|
|
10
11
|
@session.switch_to_window w
|
11
12
|
w.close
|
@@ -17,7 +18,7 @@ Capybara::SpecHelper.spec '#current_window', requires: [:windows] do
|
|
17
18
|
expect(@session.current_window).to be_instance_of(Capybara::Window)
|
18
19
|
end
|
19
20
|
|
20
|
-
it
|
21
|
+
it 'should be modified by switching to another window' do
|
21
22
|
window = @session.window_opened_by { @session.find(:css, '#openWindow').click }
|
22
23
|
|
23
24
|
expect do
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
|
+
after do
|
9
10
|
(@session.windows - [@window]).each do |w|
|
10
11
|
@session.switch_to_window w
|
11
12
|
w.close
|
@@ -16,7 +17,7 @@ Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
|
|
16
17
|
it 'should open new window with blank url and title' do
|
17
18
|
window = @session.open_new_window
|
18
19
|
@session.switch_to_window(window)
|
19
|
-
expect(['', 'about:blank']
|
20
|
+
expect(@session.title).to satisfy('be a blank title') { |title| ['', 'about:blank'].include? title }
|
20
21
|
expect(@session.current_url).to eq('about:blank')
|
21
22
|
end
|
22
23
|
|
@@ -1,13 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
|
4
|
+
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
|
5
|
+
# using Capybara provided assertions with builtin waiting behavior.
|
6
|
+
|
3
7
|
Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
4
|
-
before
|
8
|
+
before do
|
5
9
|
@window = @session.current_window
|
6
10
|
@session.visit('/with_windows')
|
7
|
-
|
11
|
+
@session.assert_selector(:css, 'body.loaded')
|
8
12
|
end
|
9
13
|
|
10
|
-
after
|
14
|
+
after do
|
11
15
|
(@session.windows - [@window]).each do |w|
|
12
16
|
@session.switch_to_window w
|
13
17
|
w.close
|
@@ -15,27 +19,27 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
15
19
|
@session.switch_to_window(@window)
|
16
20
|
end
|
17
21
|
|
18
|
-
it
|
22
|
+
it 'should raise error when invoked without args' do
|
19
23
|
expect do
|
20
24
|
@session.switch_to_window
|
21
|
-
end.to raise_error(ArgumentError,
|
25
|
+
end.to raise_error(ArgumentError, '`switch_to_window`: either window or block should be provided')
|
22
26
|
end
|
23
27
|
|
24
|
-
it
|
28
|
+
it 'should raise error when invoked with window and block' do
|
25
29
|
expect do
|
26
30
|
@session.switch_to_window(@window) { @session.title == 'Title of the first popup' }
|
27
|
-
end.to raise_error(ArgumentError,
|
31
|
+
end.to raise_error(ArgumentError, '`switch_to_window` can take either a block or a window, not both')
|
28
32
|
end
|
29
33
|
|
30
|
-
context
|
31
|
-
it
|
34
|
+
context 'with an instance of Capybara::Window' do
|
35
|
+
it 'should be able to switch to window' do
|
32
36
|
window = @session.open_new_window
|
33
37
|
expect(@session.title).to eq('With Windows')
|
34
38
|
@session.switch_to_window(window)
|
35
|
-
expect(['', 'about:blank']
|
39
|
+
expect(@session.title).to satisfy('be a blank title') { |title| ['', 'about:blank'].include? title }
|
36
40
|
end
|
37
41
|
|
38
|
-
it
|
42
|
+
it 'should raise error when closed window is passed' do
|
39
43
|
original_window = @session.current_window
|
40
44
|
new_window = @session.open_new_window
|
41
45
|
@session.switch_to_window(new_window)
|
@@ -47,30 +51,30 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
50
|
-
context
|
51
|
-
before
|
54
|
+
context 'with block' do
|
55
|
+
before do
|
52
56
|
@session.find(:css, '#openTwoWindows').click
|
53
57
|
sleep(1) # wait for the windows to open
|
54
58
|
end
|
55
59
|
|
56
|
-
it
|
60
|
+
it 'should be able to switch to current window' do
|
57
61
|
@session.switch_to_window { @session.title == 'With Windows' }
|
58
62
|
expect(@session).to have_css('#openTwoWindows')
|
59
63
|
end
|
60
64
|
|
61
|
-
it
|
65
|
+
it 'should find the div in another window' do
|
62
66
|
@session.switch_to_window { @session.title == 'Title of popup two' }
|
63
67
|
expect(@session).to have_css('#divInPopupTwo')
|
64
68
|
end
|
65
69
|
|
66
|
-
it
|
70
|
+
it 'should be able to switch multiple times' do
|
67
71
|
@session.switch_to_window { @session.title == 'Title of the first popup' }
|
68
72
|
expect(@session).to have_css('#divInPopupOne')
|
69
73
|
@session.switch_to_window { @session.title == 'Title of popup two' }
|
70
74
|
expect(@session).to have_css('#divInPopupTwo')
|
71
75
|
end
|
72
76
|
|
73
|
-
it
|
77
|
+
it 'should return window' do
|
74
78
|
window = @session.switch_to_window { @session.title == 'Title of popup two' }
|
75
79
|
expect((@session.windows - [@window])).to include(window)
|
76
80
|
end
|
@@ -91,7 +95,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
91
95
|
end.to raise_error(Capybara::ScopeError, /`switch_to_window` is not supposed to be invoked from/)
|
92
96
|
end
|
93
97
|
|
94
|
-
it
|
98
|
+
it 'should allow to be called inside within_window and within_window will still return to original' do
|
95
99
|
other_windows = (@session.windows - [@window])
|
96
100
|
expect(@session.current_window).to eq(@window)
|
97
101
|
@session.within_window other_windows[0] do
|
@@ -106,11 +110,11 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
106
110
|
original = @session.current_window
|
107
111
|
expect do
|
108
112
|
@session.switch_to_window { @session.title == 'A title' }
|
109
|
-
end.to raise_error(Capybara::WindowError,
|
113
|
+
end.to raise_error(Capybara::WindowError, 'Could not find a window matching block/lambda')
|
110
114
|
expect(@session.current_window).to eq(original)
|
111
115
|
end
|
112
116
|
|
113
|
-
it
|
117
|
+
it 'should switch to original window if error is raised inside block' do
|
114
118
|
original = @session.switch_to_window(@session.windows[1])
|
115
119
|
expect do
|
116
120
|
@session.switch_to_window { raise 'error' }
|
@@ -119,7 +123,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
122
|
-
it
|
126
|
+
it 'should wait for window to appear' do
|
123
127
|
@session.find(:css, '#openWindowWithTimeout').click
|
124
128
|
expect do
|
125
129
|
@session.switch_to_window(wait: 5) { @session.title == 'Title of the first popup' }
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
|
4
|
+
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
|
5
|
+
# using Capybara provided assertions with builtin waiting behavior.
|
6
|
+
|
3
7
|
Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
4
|
-
before
|
8
|
+
before do
|
5
9
|
@window = @session.current_window
|
6
10
|
@session.visit('/with_windows')
|
7
|
-
|
11
|
+
@session.assert_selector(:css, 'body.loaded')
|
8
12
|
end
|
9
|
-
|
13
|
+
|
14
|
+
after do
|
10
15
|
(@session.windows - [@window]).each do |w|
|
11
16
|
@session.switch_to_window w
|
12
17
|
w.close
|
@@ -14,8 +19,8 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
|
14
19
|
@session.switch_to_window(@window)
|
15
20
|
end
|
16
21
|
|
17
|
-
let(:zero_windows_message) {
|
18
|
-
let(:two_windows_message) {
|
22
|
+
let(:zero_windows_message) { 'block passed to #window_opened_by opened 0 windows instead of 1' }
|
23
|
+
let(:two_windows_message) { 'block passed to #window_opened_by opened 2 windows instead of 1' }
|
19
24
|
|
20
25
|
context 'with :wait option' do
|
21
26
|
it 'should raise error if value of :wait is less than timeout' do
|