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,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#visit' do
|
3
|
-
it
|
4
|
+
it 'should fetch a response from the driver with a relative url' do
|
4
5
|
@session.visit('/')
|
5
6
|
expect(@session).to have_content('Hello world!')
|
6
7
|
@session.visit('/foo')
|
7
8
|
expect(@session).to have_content('Another World')
|
8
9
|
end
|
9
10
|
|
10
|
-
it
|
11
|
+
it 'should fetch a response from the driver with an absolute url with a port' do
|
11
12
|
# Preparation
|
12
13
|
@session.visit('/')
|
13
14
|
root_uri = URI.parse(@session.current_url)
|
@@ -27,34 +28,40 @@ Capybara::SpecHelper.spec '#visit' do
|
|
27
28
|
expect(@session).to have_content('Hello world!')
|
28
29
|
end
|
29
30
|
|
30
|
-
it
|
31
|
-
|
31
|
+
it 'should fetch a response when sequentially visiting same destination with a target' do
|
32
|
+
@session.visit('/form')
|
33
|
+
expect(@session).to have_css('#form_title')
|
34
|
+
@session.visit('/form#form_title')
|
35
|
+
expect(@session).to have_css('#form_title')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'raises any errors caught inside the server', requires: [:server] do
|
39
|
+
quietly { @session.visit('/error') }
|
32
40
|
expect do
|
33
|
-
@session.visit(
|
41
|
+
@session.visit('/')
|
34
42
|
end.to raise_error(TestApp::TestAppError)
|
35
43
|
end
|
36
44
|
|
37
|
-
it
|
38
|
-
@session.visit(
|
39
|
-
@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/*'
|
40
48
|
end
|
41
49
|
|
42
|
-
context
|
43
|
-
|
50
|
+
context 'when Capybara.always_include_port is true' do
|
44
51
|
let(:root_uri) do
|
45
52
|
@session.visit('/')
|
46
53
|
URI.parse(@session.current_url)
|
47
54
|
end
|
48
55
|
|
49
|
-
before
|
56
|
+
before do
|
50
57
|
Capybara.always_include_port = true
|
51
58
|
end
|
52
59
|
|
53
|
-
after
|
60
|
+
after do
|
54
61
|
Capybara.always_include_port = false
|
55
62
|
end
|
56
63
|
|
57
|
-
it
|
64
|
+
it 'should fetch a response from the driver with an absolute url without a port' do
|
58
65
|
@session.visit("http://#{root_uri.host}/")
|
59
66
|
expect(URI.parse(@session.current_url).port).to eq(root_uri.port)
|
60
67
|
expect(@session).to have_content('Hello world!')
|
@@ -63,75 +70,135 @@ Capybara::SpecHelper.spec '#visit' do
|
|
63
70
|
expect(URI.parse(@session.current_url).port).to eq(root_uri.port)
|
64
71
|
expect(@session).to have_content('Another World')
|
65
72
|
end
|
73
|
+
|
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
|
+
end
|
79
|
+
|
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
|
+
@session.visit('http://www.example.com:80')
|
83
|
+
expect(@session.driver).to have_received(:visit).with('http://www.example.com:80')
|
84
|
+
end
|
85
|
+
|
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'
|
89
|
+
@session.visit('/random')
|
90
|
+
expect(@session.driver).to have_received(:visit).with('http://www.example.com:6666/random')
|
91
|
+
end
|
92
|
+
|
93
|
+
it "shouldn't override port if no server", requires: [:server] do
|
94
|
+
session = Capybara::Session.new(@session.mode, nil)
|
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')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "shouldn't override port if no server but app_host is set", requires: [:server] do
|
101
|
+
session = Capybara::Session.new(@session.mode, nil)
|
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')
|
106
|
+
end
|
66
107
|
end
|
67
108
|
|
68
|
-
context
|
69
|
-
|
109
|
+
context 'when Capybara.always_include_port is false' do
|
110
|
+
before do
|
111
|
+
Capybara.always_include_port = false
|
112
|
+
end
|
113
|
+
|
114
|
+
it "shouldn't overwrite port if app_host is set", requires: [:server] do
|
115
|
+
session = Capybara::Session.new(@session.mode, nil)
|
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')
|
120
|
+
end
|
121
|
+
|
122
|
+
it "shouldn't overwrite port if port specfified", requires: [:server] do
|
123
|
+
session = Capybara::Session.new(@session.mode, nil)
|
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')
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'without a server', requires: [:server] do
|
132
|
+
it 'should respect `app_host`' do
|
70
133
|
serverless_session = Capybara::Session.new(@session.mode, nil)
|
71
134
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
72
|
-
serverless_session.visit(
|
73
|
-
expect(serverless_session).to have_content(
|
135
|
+
serverless_session.visit('/foo')
|
136
|
+
expect(serverless_session).to have_content('Another World')
|
74
137
|
end
|
75
138
|
|
76
|
-
it
|
139
|
+
it 'should visit a fully qualified URL' do
|
77
140
|
serverless_session = Capybara::Session.new(@session.mode, nil)
|
78
141
|
serverless_session.visit("http://#{@session.server.host}:#{@session.server.port}/foo")
|
79
|
-
expect(serverless_session).to have_content(
|
142
|
+
expect(serverless_session).to have_content('Another World')
|
80
143
|
end
|
81
144
|
end
|
82
145
|
|
83
|
-
context
|
84
|
-
it
|
146
|
+
context 'with Capybara.app_host set' do
|
147
|
+
it 'should override server', requires: [:server] do
|
85
148
|
another_session = Capybara::Session.new(@session.mode, @session.app.dup)
|
86
149
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
87
150
|
another_session.visit('/foo')
|
88
|
-
expect(another_session).to have_content(
|
151
|
+
expect(another_session).to have_content('Another World')
|
89
152
|
expect(another_session.current_url).to start_with(Capybara.app_host)
|
90
153
|
expect(URI.parse(another_session.current_url).port).not_to eq another_session.server.port
|
91
154
|
expect(URI.parse(another_session.current_url).port).to eq @session.server.port
|
92
155
|
end
|
93
156
|
|
94
|
-
it
|
157
|
+
it 'should append relative path', requires: [:server] do
|
95
158
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}/redirect/0"
|
96
159
|
@session.visit('/times')
|
97
160
|
expect(@session).to have_content('redirection complete')
|
98
161
|
end
|
99
|
-
end
|
100
162
|
|
163
|
+
it 'should work if `app_host` has a trailing /', requires: [:server] do
|
164
|
+
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}/"
|
165
|
+
@session.visit('/')
|
166
|
+
expect(@session).to have_content('Hello world!')
|
167
|
+
end
|
168
|
+
end
|
101
169
|
|
102
|
-
it
|
170
|
+
it 'should send no referer when visiting a page' do
|
103
171
|
@session.visit '/get_referer'
|
104
172
|
expect(@session).to have_content 'No referer'
|
105
173
|
end
|
106
174
|
|
107
|
-
it
|
175
|
+
it 'should send no referer when visiting a second page' do
|
108
176
|
@session.visit '/get_referer'
|
109
177
|
@session.visit '/get_referer'
|
110
178
|
expect(@session).to have_content 'No referer'
|
111
179
|
end
|
112
180
|
|
113
|
-
it
|
181
|
+
it 'should send a referer when following a link' do
|
114
182
|
@session.visit '/referer_base'
|
115
183
|
@session.find('//a[@href="/get_referer"]').click
|
116
184
|
expect(@session).to have_content %r{http://.*/referer_base}
|
117
185
|
end
|
118
186
|
|
119
|
-
it
|
187
|
+
it 'should preserve the original referer URL when following a redirect' do
|
120
188
|
@session.visit('/referer_base')
|
121
189
|
@session.find('//a[@href="/redirect_to_get_referer"]').click
|
122
190
|
expect(@session).to have_content %r{http://.*/referer_base}
|
123
191
|
end
|
124
192
|
|
125
|
-
it
|
193
|
+
it 'should send a referer when submitting a form' do
|
126
194
|
@session.visit '/referer_base'
|
127
195
|
@session.find('//input').click
|
128
196
|
expect(@session).to have_content %r{http://.*/referer_base}
|
129
197
|
end
|
130
198
|
|
131
|
-
it
|
132
|
-
@session.visit(
|
199
|
+
it 'can set cookie if a blank path is specified' do
|
200
|
+
@session.visit('')
|
133
201
|
@session.visit('/get_cookie')
|
134
202
|
expect(@session).to have_content('root cookie')
|
135
203
|
end
|
136
|
-
|
137
204
|
end
|
@@ -1,84 +1,88 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
|
4
|
+
let!(:window) { @session.current_window }
|
5
|
+
let(:other_window) do
|
6
|
+
@session.window_opened_by do
|
7
7
|
@session.find(:css, '#openWindow').click
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
before do
|
12
|
+
@session.visit('/with_windows')
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
12
16
|
@session.document.synchronize(5, errors: [Capybara::CapybaraError]) do
|
13
17
|
raise Capybara::CapybaraError if @session.windows.size != 1
|
14
18
|
end
|
15
|
-
@session.switch_to_window(
|
19
|
+
@session.switch_to_window(window)
|
16
20
|
end
|
17
21
|
|
18
22
|
context 'with :wait option' do
|
19
23
|
it 'should wait if value of :wait is more than timeout' do
|
20
|
-
@session.within_window
|
24
|
+
@session.within_window other_window do
|
21
25
|
@session.execute_script('setTimeout(function(){ window.close(); }, 500);')
|
22
26
|
end
|
23
27
|
Capybara.using_wait_time 0.1 do
|
24
|
-
expect(
|
28
|
+
expect(other_window).to become_closed(wait: 5)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
32
|
it 'should raise error if value of :wait is less than timeout' do
|
29
|
-
@session.within_window
|
30
|
-
@session.execute_script('setTimeout(function(){ window.close(); },
|
33
|
+
@session.within_window other_window do
|
34
|
+
@session.execute_script('setTimeout(function(){ window.close(); }, 1000);')
|
31
35
|
end
|
32
36
|
Capybara.using_wait_time 2 do
|
33
37
|
expect do
|
34
|
-
expect(
|
35
|
-
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> to become closed after 0.
|
38
|
+
expect(other_window).to become_closed(wait: 0.2)
|
39
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> to become closed after 0.2 seconds\Z/)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
40
44
|
context 'without :wait option' do
|
41
45
|
it 'should wait if value of default_max_wait_time is more than timeout' do
|
42
|
-
@session.within_window
|
46
|
+
@session.within_window other_window do
|
43
47
|
@session.execute_script('setTimeout(function(){ window.close(); }, 500);')
|
44
48
|
end
|
45
|
-
Capybara.using_wait_time
|
46
|
-
expect(
|
49
|
+
Capybara.using_wait_time 5 do
|
50
|
+
expect(other_window).to become_closed
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
50
54
|
it 'should raise error if value of default_max_wait_time is less than timeout' do
|
51
|
-
@session.within_window
|
55
|
+
@session.within_window other_window do
|
52
56
|
@session.execute_script('setTimeout(function(){ window.close(); }, 900);')
|
53
57
|
end
|
54
58
|
Capybara.using_wait_time 0.4 do
|
55
59
|
expect do
|
56
|
-
expect(
|
60
|
+
expect(other_window).to become_closed
|
57
61
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> to become closed after 0.4 seconds\Z/)
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
62
66
|
context 'with not_to' do
|
63
|
-
it
|
64
|
-
@session.within_window
|
65
|
-
@session.execute_script('setTimeout(function(){ window.close(); },
|
67
|
+
it "should not raise error if window doesn't close before default_max_wait_time" do
|
68
|
+
@session.within_window other_window do
|
69
|
+
@session.execute_script('setTimeout(function(){ window.close(); }, 1000);')
|
66
70
|
end
|
67
|
-
Capybara.using_wait_time 0.
|
71
|
+
Capybara.using_wait_time 0.3 do
|
68
72
|
expect do
|
69
|
-
expect(
|
70
|
-
end
|
73
|
+
expect(other_window).not_to become_closed
|
74
|
+
end.not_to raise_error
|
71
75
|
end
|
72
76
|
end
|
73
77
|
|
74
|
-
it 'should raise error if
|
75
|
-
@session.within_window
|
78
|
+
it 'should raise error if window closes before default_max_wait_time' do
|
79
|
+
@session.within_window other_window do
|
76
80
|
@session.execute_script('setTimeout(function(){ window.close(); }, 700);')
|
77
81
|
end
|
78
|
-
Capybara.using_wait_time
|
82
|
+
Capybara.using_wait_time 3.1 do
|
79
83
|
expect do
|
80
|
-
expect(
|
81
|
-
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> not to become closed after
|
84
|
+
expect(other_window).not_to become_closed
|
85
|
+
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /\Aexpected #<Window @handle=".+"> not to become closed after 3.1 seconds\Z/)
|
82
86
|
end
|
83
87
|
end
|
84
88
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#current_window', requires: [:windows] do
|
3
|
-
before
|
4
|
+
before do
|
4
5
|
@window = @session.current_window
|
5
6
|
@session.visit('/with_windows')
|
6
7
|
end
|
7
|
-
|
8
|
+
|
9
|
+
after do
|
8
10
|
(@session.windows - [@window]).each do |w|
|
9
11
|
@session.switch_to_window w
|
10
12
|
w.close
|
@@ -16,7 +18,7 @@ Capybara::SpecHelper.spec '#current_window', requires: [:windows] do
|
|
16
18
|
expect(@session.current_window).to be_instance_of(Capybara::Window)
|
17
19
|
end
|
18
20
|
|
19
|
-
it
|
21
|
+
it 'should be modified by switching to another window' do
|
20
22
|
window = @session.window_opened_by { @session.find(:css, '#openWindow').click }
|
21
23
|
|
22
24
|
expect do
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
|
3
|
-
before
|
4
|
+
before do
|
4
5
|
@window = @session.current_window
|
5
6
|
@session.visit('/with_windows')
|
6
7
|
end
|
7
|
-
|
8
|
+
|
9
|
+
after do
|
8
10
|
(@session.windows - [@window]).each do |w|
|
9
11
|
@session.switch_to_window w
|
10
12
|
w.close
|
@@ -15,7 +17,7 @@ Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
|
|
15
17
|
it 'should open new window with blank url and title' do
|
16
18
|
window = @session.open_new_window
|
17
19
|
@session.switch_to_window(window)
|
18
|
-
expect(['', 'about:blank']
|
20
|
+
expect(@session.title).to satisfy('be a blank title') { |title| ['', 'about:blank'].include? title }
|
19
21
|
expect(@session.current_url).to eq('about:blank')
|
20
22
|
end
|
21
23
|
|
@@ -1,10 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
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
|
+
|
2
7
|
Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
3
|
-
before
|
8
|
+
before do
|
4
9
|
@window = @session.current_window
|
5
10
|
@session.visit('/with_windows')
|
11
|
+
@session.assert_selector(:css, 'body.loaded')
|
6
12
|
end
|
7
|
-
|
13
|
+
|
14
|
+
after do
|
8
15
|
(@session.windows - [@window]).each do |w|
|
9
16
|
@session.switch_to_window w
|
10
17
|
w.close
|
@@ -12,27 +19,27 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
12
19
|
@session.switch_to_window(@window)
|
13
20
|
end
|
14
21
|
|
15
|
-
it
|
22
|
+
it 'should raise error when invoked without args' do
|
16
23
|
expect do
|
17
24
|
@session.switch_to_window
|
18
|
-
end.to raise_error(ArgumentError,
|
25
|
+
end.to raise_error(ArgumentError, '`switch_to_window`: either window or block should be provided')
|
19
26
|
end
|
20
27
|
|
21
|
-
it
|
28
|
+
it 'should raise error when invoked with window and block' do
|
22
29
|
expect do
|
23
30
|
@session.switch_to_window(@window) { @session.title == 'Title of the first popup' }
|
24
|
-
end.to raise_error(ArgumentError,
|
31
|
+
end.to raise_error(ArgumentError, '`switch_to_window` can take either a block or a window, not both')
|
25
32
|
end
|
26
33
|
|
27
|
-
context
|
28
|
-
it
|
34
|
+
context 'with an instance of Capybara::Window' do
|
35
|
+
it 'should be able to switch to window' do
|
29
36
|
window = @session.open_new_window
|
30
37
|
expect(@session.title).to eq('With Windows')
|
31
38
|
@session.switch_to_window(window)
|
32
|
-
expect(['', 'about:blank']
|
39
|
+
expect(@session.title).to satisfy('be a blank title') { |title| ['', 'about:blank'].include? title }
|
33
40
|
end
|
34
41
|
|
35
|
-
it
|
42
|
+
it 'should raise error when closed window is passed' do
|
36
43
|
original_window = @session.current_window
|
37
44
|
new_window = @session.open_new_window
|
38
45
|
@session.switch_to_window(new_window)
|
@@ -44,30 +51,30 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
context
|
48
|
-
before
|
54
|
+
context 'with block' do
|
55
|
+
before do
|
49
56
|
@session.find(:css, '#openTwoWindows').click
|
50
|
-
sleep(
|
57
|
+
sleep(1) # wait for the windows to open
|
51
58
|
end
|
52
59
|
|
53
|
-
it
|
60
|
+
it 'should be able to switch to current window' do
|
54
61
|
@session.switch_to_window { @session.title == 'With Windows' }
|
55
62
|
expect(@session).to have_css('#openTwoWindows')
|
56
63
|
end
|
57
64
|
|
58
|
-
it
|
65
|
+
it 'should find the div in another window' do
|
59
66
|
@session.switch_to_window { @session.title == 'Title of popup two' }
|
60
67
|
expect(@session).to have_css('#divInPopupTwo')
|
61
68
|
end
|
62
69
|
|
63
|
-
it
|
70
|
+
it 'should be able to switch multiple times' do
|
64
71
|
@session.switch_to_window { @session.title == 'Title of the first popup' }
|
65
72
|
expect(@session).to have_css('#divInPopupOne')
|
66
73
|
@session.switch_to_window { @session.title == 'Title of popup two' }
|
67
74
|
expect(@session).to have_css('#divInPopupTwo')
|
68
75
|
end
|
69
76
|
|
70
|
-
it
|
77
|
+
it 'should return window' do
|
71
78
|
window = @session.switch_to_window { @session.title == 'Title of popup two' }
|
72
79
|
expect((@session.windows - [@window])).to include(window)
|
73
80
|
end
|
@@ -77,7 +84,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
77
84
|
@session.within(:css, '#doesNotOpenWindows') do
|
78
85
|
@session.switch_to_window { @session.title == 'With Windows' }
|
79
86
|
end
|
80
|
-
end.to raise_error(Capybara::ScopeError,
|
87
|
+
end.to raise_error(Capybara::ScopeError, /`switch_to_window` is not supposed to be invoked/)
|
81
88
|
end
|
82
89
|
|
83
90
|
it "should raise error when invoked inside `within_frame` as it's nonsense" do
|
@@ -85,27 +92,29 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
85
92
|
@session.within_frame('frameOne') do
|
86
93
|
@session.switch_to_window { @session.title == 'With Windows' }
|
87
94
|
end
|
88
|
-
end.to raise_error(Capybara::ScopeError,
|
95
|
+
end.to raise_error(Capybara::ScopeError, /`switch_to_window` is not supposed to be invoked from/)
|
89
96
|
end
|
90
97
|
|
91
|
-
it
|
92
|
-
|
93
|
-
expect
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
+
it 'should allow to be called inside within_window and within_window will still return to original' do
|
99
|
+
other_windows = (@session.windows - [@window])
|
100
|
+
expect(@session.current_window).to eq(@window)
|
101
|
+
@session.within_window other_windows[0] do
|
102
|
+
expect(@session.current_window).to eq(other_windows[0])
|
103
|
+
@session.switch_to_window other_windows[1]
|
104
|
+
expect(@session.current_window).to eq(other_windows[1])
|
105
|
+
end
|
106
|
+
expect(@session.current_window).to eq(@window)
|
98
107
|
end
|
99
108
|
|
100
109
|
it "should raise error if window matching block wasn't found" do
|
101
110
|
original = @session.current_window
|
102
111
|
expect do
|
103
112
|
@session.switch_to_window { @session.title == 'A title' }
|
104
|
-
end.to raise_error(Capybara::WindowError,
|
113
|
+
end.to raise_error(Capybara::WindowError, 'Could not find a window matching block/lambda')
|
105
114
|
expect(@session.current_window).to eq(original)
|
106
115
|
end
|
107
116
|
|
108
|
-
it
|
117
|
+
it 'should switch to original window if error is raised inside block' do
|
109
118
|
original = @session.switch_to_window(@session.windows[1])
|
110
119
|
expect do
|
111
120
|
@session.switch_to_window { raise 'error' }
|
@@ -114,10 +123,10 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
114
123
|
end
|
115
124
|
end
|
116
125
|
|
117
|
-
it
|
126
|
+
it 'should wait for window to appear' do
|
118
127
|
@session.find(:css, '#openWindowWithTimeout').click
|
119
128
|
expect do
|
120
|
-
@session.switch_to_window { @session.title == 'Title of the first popup'}
|
129
|
+
@session.switch_to_window(wait: 5) { @session.title == 'Title of the first popup' }
|
121
130
|
end.not_to raise_error
|
122
131
|
end
|
123
132
|
end
|