capybara 3.3.0 → 3.40.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 -0
- data/History.md +803 -13
- data/License.txt +1 -1
- data/README.md +257 -84
- data/lib/capybara/config.rb +25 -9
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +17 -3
- data/lib/capybara/driver/node.rb +31 -6
- data/lib/capybara/dsl.rb +9 -7
- data/lib/capybara/helpers.rb +31 -7
- data/lib/capybara/minitest/spec.rb +180 -88
- data/lib/capybara/minitest.rb +262 -149
- data/lib/capybara/node/actions.rb +202 -116
- data/lib/capybara/node/base.rb +34 -19
- data/lib/capybara/node/document.rb +14 -2
- data/lib/capybara/node/document_matchers.rb +10 -12
- data/lib/capybara/node/element.rb +269 -115
- data/lib/capybara/node/finders.rb +99 -77
- data/lib/capybara/node/matchers.rb +327 -151
- data/lib/capybara/node/simple.rb +48 -13
- data/lib/capybara/node/whitespace_normalizer.rb +81 -0
- data/lib/capybara/queries/active_element_query.rb +18 -0
- data/lib/capybara/queries/ancestor_query.rb +8 -9
- data/lib/capybara/queries/base_query.rb +23 -16
- data/lib/capybara/queries/current_path_query.rb +16 -6
- data/lib/capybara/queries/match_query.rb +1 -0
- data/lib/capybara/queries/selector_query.rb +587 -130
- data/lib/capybara/queries/sibling_query.rb +8 -6
- data/lib/capybara/queries/style_query.rb +6 -2
- data/lib/capybara/queries/text_query.rb +28 -14
- data/lib/capybara/queries/title_query.rb +2 -2
- data/lib/capybara/rack_test/browser.rb +92 -25
- data/lib/capybara/rack_test/driver.rb +16 -7
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +68 -41
- data/lib/capybara/rack_test/node.rb +106 -39
- data/lib/capybara/rails.rb +1 -1
- data/lib/capybara/registration_container.rb +41 -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 +66 -0
- data/lib/capybara/result.rb +75 -52
- data/lib/capybara/rspec/features.rb +7 -7
- data/lib/capybara/rspec/matcher_proxies.rb +39 -18
- data/lib/capybara/rspec/matchers/base.rb +113 -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 +69 -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 +141 -339
- data/lib/capybara/rspec.rb +2 -0
- 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 +27 -25
- 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 +55 -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 +280 -0
- data/lib/capybara/selector/filter.rb +1 -0
- data/lib/capybara/selector/filter_set.rb +73 -25
- data/lib/capybara/selector/filters/base.rb +24 -5
- data/lib/capybara/selector/filters/expression_filter.rb +3 -3
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +16 -2
- data/lib/capybara/selector/regexp_disassembler.rb +211 -0
- data/lib/capybara/selector/selector.rb +85 -348
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +474 -447
- 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 +255 -143
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +93 -11
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +128 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +84 -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 +229 -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/node.rb +436 -134
- data/lib/capybara/selenium/nodes/chrome_node.rb +125 -0
- data/lib/capybara/selenium/nodes/edge_node.rb +110 -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/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 +56 -19
- data/lib/capybara/server/checker.rb +9 -3
- data/lib/capybara/server/middleware.rb +28 -12
- data/lib/capybara/server.rb +33 -10
- data/lib/capybara/session/config.rb +34 -10
- data/lib/capybara/session/matchers.rb +23 -16
- data/lib/capybara/session.rb +230 -170
- 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 +121 -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 +127 -40
- 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_spec.rb +21 -18
- data/lib/capybara/spec/session/assert_selector_spec.rb +52 -58
- data/lib/capybara/spec/session/assert_style_spec.rb +7 -7
- data/lib/capybara/spec/session/assert_text_spec.rb +74 -50
- data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
- data/lib/capybara/spec/session/attach_file_spec.rb +126 -72
- data/lib/capybara/spec/session/body_spec.rb +6 -6
- data/lib/capybara/spec/session/check_spec.rb +102 -47
- data/lib/capybara/spec/session/choose_spec.rb +58 -32
- data/lib/capybara/spec/session/click_button_spec.rb +219 -163
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +49 -23
- data/lib/capybara/spec/session/click_link_spec.rb +77 -54
- data/lib/capybara/spec/session/current_scope_spec.rb +8 -8
- data/lib/capybara/spec/session/current_url_spec.rb +38 -29
- 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_spec.rb +8 -8
- data/lib/capybara/spec/session/element/match_css_spec.rb +16 -10
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +68 -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 +101 -46
- data/lib/capybara/spec/session/find_button_spec.rb +23 -23
- data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
- data/lib/capybara/spec/session/find_field_spec.rb +32 -30
- data/lib/capybara/spec/session/find_link_spec.rb +31 -21
- data/lib/capybara/spec/session/find_spec.rb +244 -141
- data/lib/capybara/spec/session/first_spec.rb +43 -43
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +30 -18
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +45 -18
- 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 +23 -23
- 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 +94 -13
- data/lib/capybara/spec/session/has_css_spec.rb +272 -132
- data/lib/capybara/spec/session/has_current_path_spec.rb +50 -35
- data/lib/capybara/spec/session/has_element_spec.rb +47 -0
- data/lib/capybara/spec/session/has_field_spec.rb +137 -58
- data/lib/capybara/spec/session/has_link_spec.rb +44 -4
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +31 -31
- data/lib/capybara/spec/session/has_select_spec.rb +84 -50
- data/lib/capybara/spec/session/has_selector_spec.rb +111 -71
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +181 -4
- data/lib/capybara/spec/session/has_text_spec.rb +101 -53
- 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_spec.rb +1 -1
- data/lib/capybara/spec/session/html_spec.rb +13 -6
- data/lib/capybara/spec/session/matches_style_spec.rb +37 -0
- data/lib/capybara/spec/session/node_spec.rb +894 -142
- data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
- data/lib/capybara/spec/session/refresh_spec.rb +9 -7
- data/lib/capybara/spec/session/reset_session_spec.rb +63 -35
- data/lib/capybara/spec/session/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 +2 -2
- data/lib/capybara/spec/session/save_page_spec.rb +37 -37
- data/lib/capybara/spec/session/save_screenshot_spec.rb +10 -10
- data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/scroll_spec.rb +119 -0
- data/lib/capybara/spec/session/select_spec.rb +85 -85
- data/lib/capybara/spec/session/selectors_spec.rb +49 -18
- data/lib/capybara/spec/session/sibling_spec.rb +9 -9
- data/lib/capybara/spec/session/text_spec.rb +25 -24
- data/lib/capybara/spec/session/title_spec.rb +7 -6
- data/lib/capybara/spec/session/uncheck_spec.rb +33 -21
- data/lib/capybara/spec/session/unselect_spec.rb +37 -37
- data/lib/capybara/spec/session/visit_spec.rb +68 -49
- data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +20 -16
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +6 -2
- data/lib/capybara/spec/session/window/window_spec.rb +62 -63
- data/lib/capybara/spec/session/window/windows_spec.rb +5 -1
- data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
- data/lib/capybara/spec/session/within_spec.rb +79 -42
- data/lib/capybara/spec/spec_helper.rb +41 -53
- data/lib/capybara/spec/test_app.rb +132 -43
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +139 -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 +67 -0
- data/lib/capybara/spec/views/with_animation.erb +39 -4
- 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 +37 -9
- 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 +26 -5
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_namespace.erb +1 -0
- data/lib/capybara/spec/views/with_scope.erb +2 -2
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_shadow.erb +31 -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 +19 -25
- data/lib/capybara.rb +126 -111
- data/spec/basic_node_spec.rb +59 -34
- data/spec/capybara_spec.rb +56 -44
- data/spec/counter_spec.rb +35 -0
- data/spec/css_builder_spec.rb +101 -0
- data/spec/css_splitter_spec.rb +8 -8
- data/spec/dsl_spec.rb +79 -52
- data/spec/filter_set_spec.rb +9 -9
- 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 +45 -7
- data/spec/minitest_spec_spec.rb +87 -64
- data/spec/per_session_config_spec.rb +6 -6
- data/spec/rack_test_spec.rb +172 -116
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +80 -72
- data/spec/rspec/features_spec.rb +21 -16
- data/spec/rspec/scenarios_spec.rb +10 -6
- data/spec/rspec/shared_spec_matchers.rb +407 -365
- data/spec/rspec/views_spec.rb +3 -3
- data/spec/rspec_matchers_spec.rb +35 -10
- data/spec/rspec_spec.rb +63 -41
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +334 -89
- data/spec/selenium_spec_chrome.rb +176 -62
- data/spec/selenium_spec_chrome_remote.rb +54 -14
- data/spec/selenium_spec_edge.rb +41 -8
- data/spec/selenium_spec_firefox.rb +228 -0
- data/spec/selenium_spec_firefox_remote.rb +94 -0
- data/spec/selenium_spec_ie.rb +129 -11
- data/spec/selenium_spec_safari.rb +162 -0
- data/spec/server_spec.rb +171 -97
- data/spec/session_spec.rb +34 -18
- data/spec/shared_selenium_node.rb +79 -0
- data/spec/shared_selenium_session.rb +344 -80
- data/spec/spec_helper.rb +124 -2
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +326 -28
- data/lib/capybara/rspec/compound.rb +0 -94
- data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -31
- data/lib/capybara/selenium/nodes/marionette_node.rb +0 -31
- data/lib/capybara/spec/session/has_style_spec.rb +0 -25
- 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 -167
@@ -1,5 +1,9 @@
|
|
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
8
|
before do
|
5
9
|
@window = @session.current_window
|
@@ -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
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
|
54
|
+
context 'with block' do
|
51
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,5 +1,9 @@
|
|
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
8
|
before do
|
5
9
|
@window = @session.current_window
|
@@ -15,8 +19,8 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
|
15
19
|
@session.switch_to_window(@window)
|
16
20
|
end
|
17
21
|
|
18
|
-
let(:zero_windows_message) {
|
19
|
-
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' }
|
20
24
|
|
21
25
|
context 'with :wait option' do
|
22
26
|
it 'should raise error if value of :wait is less than timeout' do
|
@@ -1,95 +1,97 @@
|
|
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 Capybara::Window, requires: [:windows] do
|
8
|
+
let!(:orig_window) { @session.current_window }
|
4
9
|
before do
|
5
|
-
@window = @session.current_window
|
6
10
|
@session.visit('/with_windows')
|
7
11
|
end
|
8
12
|
|
9
13
|
after do
|
10
|
-
(@session.windows - [
|
14
|
+
(@session.windows - [orig_window]).each do |w|
|
11
15
|
@session.switch_to_window w
|
12
16
|
w.close
|
13
17
|
end
|
14
|
-
@session.switch_to_window(
|
18
|
+
@session.switch_to_window(orig_window)
|
15
19
|
end
|
16
20
|
|
17
21
|
describe '#exists?' do
|
18
|
-
|
19
|
-
|
22
|
+
it 'should become false after window was closed' do
|
23
|
+
other_window = @session.window_opened_by do
|
20
24
|
@session.find(:css, '#openWindow').click
|
21
25
|
end
|
22
|
-
end
|
23
26
|
|
24
|
-
it "should become false after window was closed" do
|
25
27
|
expect do
|
26
|
-
@session.switch_to_window
|
27
|
-
|
28
|
-
end.to change
|
28
|
+
@session.switch_to_window other_window
|
29
|
+
other_window.close
|
30
|
+
end.to change(other_window, :exists?).from(true).to(false)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
describe '#closed?' do
|
33
|
-
it
|
34
|
-
|
35
|
+
it 'should become true after window was closed' do
|
36
|
+
other_window = @session.window_opened_by do
|
35
37
|
@session.find(:css, '#openWindow').click
|
36
38
|
end
|
37
39
|
expect do
|
38
|
-
@session.switch_to_window
|
39
|
-
|
40
|
-
end.to change {
|
40
|
+
@session.switch_to_window other_window
|
41
|
+
other_window.close
|
42
|
+
end.to change { other_window.closed? }.from(false).to(true)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
describe '#current?' do
|
45
|
-
|
46
|
-
@
|
47
|
+
let(:other_window) do
|
48
|
+
@session.window_opened_by do
|
47
49
|
@session.find(:css, '#openWindow').click
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
it 'should become true after switching to window' do
|
52
54
|
expect do
|
53
|
-
@session.switch_to_window(
|
54
|
-
end.to change
|
55
|
+
@session.switch_to_window(other_window)
|
56
|
+
end.to change(other_window, :current?).from(false).to(true)
|
55
57
|
end
|
56
58
|
|
57
59
|
it 'should return false if window is closed' do
|
58
|
-
@session.switch_to_window(
|
59
|
-
|
60
|
-
expect(
|
60
|
+
@session.switch_to_window(other_window)
|
61
|
+
other_window.close
|
62
|
+
expect(other_window.current?).to be(false)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
66
|
describe '#close' do
|
65
|
-
|
66
|
-
@
|
67
|
+
let!(:other_window) do
|
68
|
+
@session.window_opened_by do
|
67
69
|
@session.find(:css, '#openWindow').click
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
71
73
|
it 'should switch to original window if invoked not for current window' do
|
72
74
|
expect(@session.windows.size).to eq(2)
|
73
|
-
expect(@session.current_window).to eq(
|
74
|
-
|
75
|
+
expect(@session.current_window).to eq(orig_window)
|
76
|
+
other_window.close
|
75
77
|
expect(@session.windows.size).to eq(1)
|
76
|
-
expect(@session.current_window).to eq(
|
78
|
+
expect(@session.current_window).to eq(orig_window)
|
77
79
|
end
|
78
80
|
|
79
81
|
it 'should make subsequent invocations of other methods raise no_such_window_error if invoked for current window' do
|
80
|
-
@session.switch_to_window(
|
81
|
-
expect(@session.current_window).to eq(
|
82
|
-
|
82
|
+
@session.switch_to_window(other_window)
|
83
|
+
expect(@session.current_window).to eq(other_window)
|
84
|
+
other_window.close
|
83
85
|
expect do
|
84
86
|
@session.find(:css, '#some_id')
|
85
87
|
end.to raise_error(@session.driver.no_such_window_error)
|
86
|
-
@session.switch_to_window(
|
88
|
+
@session.switch_to_window(orig_window)
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
90
92
|
describe '#size' do
|
91
93
|
def win_size
|
92
|
-
@session.evaluate_script(
|
94
|
+
@session.evaluate_script('[window.outerWidth || window.innerWidth, window.outerHeight || window.innerHeight]')
|
93
95
|
end
|
94
96
|
|
95
97
|
it 'should return size of whole window', requires: %i[windows js] do
|
@@ -97,57 +99,54 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
97
99
|
end
|
98
100
|
|
99
101
|
it 'should switch to original window if invoked not for current window' do
|
100
|
-
|
102
|
+
other_window = @session.window_opened_by do
|
101
103
|
@session.find(:css, '#openWindow').click
|
102
104
|
end
|
103
105
|
sleep 1
|
104
|
-
size = @session.within_window(
|
106
|
+
size = @session.within_window(other_window) do
|
105
107
|
win_size
|
106
108
|
end
|
107
|
-
expect(
|
108
|
-
expect(@session.current_window).to eq(
|
109
|
+
expect(other_window.size).to eq(size)
|
110
|
+
expect(@session.current_window).to eq(orig_window)
|
109
111
|
end
|
110
112
|
end
|
111
113
|
|
112
114
|
describe '#resize_to' do
|
113
|
-
|
114
|
-
@initial_size = @session.current_window.size
|
115
|
-
end
|
115
|
+
let!(:initial_size) { @session.current_window.size }
|
116
116
|
|
117
117
|
after do
|
118
|
-
@session.current_window.resize_to(
|
119
|
-
sleep
|
118
|
+
@session.current_window.resize_to(*initial_size)
|
119
|
+
sleep 1
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should be able to resize window', requires: %i[windows js] do
|
123
|
-
width, height =
|
123
|
+
width, height = initial_size
|
124
124
|
@session.current_window.resize_to(width - 100, height - 100)
|
125
125
|
sleep 1
|
126
126
|
expect(@session.current_window.size).to eq([width - 100, height - 100])
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'should stay on current window if invoked not for current window', requires: %i[windows js] do
|
130
|
-
|
130
|
+
other_window = @session.window_opened_by do
|
131
131
|
@session.find(:css, '#openWindow').click
|
132
132
|
end
|
133
|
-
@other_window.resize_to(400, 300)
|
134
|
-
expect(@session.current_window).to eq(@window)
|
135
133
|
|
136
|
-
|
137
|
-
@session.
|
138
|
-
|
139
|
-
|
134
|
+
other_window.resize_to(600, 400)
|
135
|
+
expect(@session.current_window).to eq(orig_window)
|
136
|
+
|
137
|
+
@session.within_window(other_window) do
|
138
|
+
expect(@session.current_window.size).to eq([600, 400])
|
140
139
|
end
|
141
140
|
end
|
142
141
|
end
|
143
142
|
|
144
143
|
describe '#maximize' do
|
145
|
-
|
146
|
-
@
|
144
|
+
let! :initial_size do
|
145
|
+
@session.current_window.size
|
147
146
|
end
|
148
147
|
|
149
148
|
after do
|
150
|
-
@session.current_window.resize_to(
|
149
|
+
@session.current_window.resize_to(*initial_size)
|
151
150
|
sleep 0.5
|
152
151
|
end
|
153
152
|
|
@@ -167,35 +166,35 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
167
166
|
end
|
168
167
|
|
169
168
|
it 'should stay on current window if invoked not for current window', requires: %i[windows js] do
|
170
|
-
|
169
|
+
other_window = @session.window_opened_by do
|
171
170
|
@session.find(:css, '#openWindow').click
|
172
171
|
end
|
173
|
-
|
172
|
+
other_window.resize_to(400, 300)
|
174
173
|
sleep 0.5
|
175
|
-
|
174
|
+
other_window.maximize
|
176
175
|
sleep 0.5 # The timing on maximize is finicky on Travis -- wait a bit for maximize to occur
|
177
176
|
|
178
|
-
expect(@session.current_window).to eq(
|
177
|
+
expect(@session.current_window).to eq(orig_window)
|
179
178
|
# Maximizing the browser affects all tabs so this may not be valid in real browsers
|
180
|
-
# expect(@session.current_window.size).to eq(
|
179
|
+
# expect(@session.current_window.size).to eq(initial_size)
|
181
180
|
|
182
|
-
ow_width, ow_height =
|
181
|
+
ow_width, ow_height = other_window.size
|
183
182
|
expect(ow_width).to be > 400
|
184
183
|
expect(ow_height).to be > 300
|
185
184
|
end
|
186
185
|
end
|
187
186
|
|
188
187
|
describe '#fullscreen' do
|
189
|
-
|
190
|
-
@
|
188
|
+
let! :initial_size do
|
189
|
+
@session.current_window.size
|
191
190
|
end
|
192
191
|
|
193
192
|
after do
|
194
|
-
@session.current_window.resize_to(
|
195
|
-
sleep
|
193
|
+
@session.current_window.resize_to(*initial_size)
|
194
|
+
sleep 1
|
196
195
|
end
|
197
196
|
|
198
|
-
it
|
197
|
+
it 'should be able to fullscreen the window' do
|
199
198
|
expect do
|
200
199
|
@session.current_window.fullscreen
|
201
200
|
end.not_to raise_error
|
@@ -1,5 +1,9 @@
|
|
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 '#windows', requires: [:windows] do
|
4
8
|
before do
|
5
9
|
@window = @session.current_window
|
@@ -25,6 +29,6 @@ Capybara::SpecHelper.spec '#windows', requires: [:windows] do
|
|
25
29
|
titles = @session.windows.map do |window|
|
26
30
|
@session.within_window(window) { @session.title }
|
27
31
|
end
|
28
|
-
expect(titles).to match_array(['With Windows', 'Title of the first popup', 'Title of popup two'])
|
32
|
+
expect(titles).to match_array(['With Windows', 'Title of the first popup', 'Title of popup two']) # rubocop:disable RSpec/MatchArray
|
29
33
|
end
|
30
34
|
end
|
@@ -19,8 +19,8 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
19
19
|
@session.switch_to_window(@window)
|
20
20
|
end
|
21
21
|
|
22
|
-
context
|
23
|
-
it
|
22
|
+
context 'with an instance of Capybara::Window' do
|
23
|
+
it 'should not invoke driver#switch_to_window when given current window' do
|
24
24
|
allow(@session.driver).to receive(:switch_to_window).and_call_original
|
25
25
|
@session.within_window @window do
|
26
26
|
expect(@session.title).to eq('With Windows')
|
@@ -28,7 +28,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
28
28
|
expect(@session.driver).not_to have_received(:switch_to_window)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'should be able to switch to another window' do
|
32
32
|
window = (@session.windows - [@window]).first
|
33
33
|
@session.within_window window do
|
34
34
|
expect(@session).to have_title(/Title of the first popup|Title of popup two/)
|
@@ -36,7 +36,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
36
36
|
expect(@session.title).to eq('With Windows')
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'returns value from the block' do
|
40
40
|
window = (@session.windows - [@window]).first
|
41
41
|
value = @session.within_window window do
|
42
42
|
43252003274489856000
|
@@ -44,7 +44,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
44
44
|
expect(value).to eq(43252003274489856000)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'should switch back if exception was raised inside block' do
|
48
48
|
window = (@session.windows - [@window]).first
|
49
49
|
expect do
|
50
50
|
@session.within_window(window) do
|
@@ -58,7 +58,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
58
58
|
expect(@session.send(:scopes)).to eq([nil])
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'should leave correct scopes after execution in case of error', requires: %i[windows frames] do
|
62
62
|
window = (@session.windows - [@window]).first
|
63
63
|
expect do
|
64
64
|
@session.within_frame 'frameOne' do
|
@@ -86,14 +86,14 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
context
|
90
|
-
it
|
89
|
+
context 'with lambda' do
|
90
|
+
it 'should find the div in another window' do
|
91
91
|
@session.within_window(-> { @session.title == 'Title of the first popup' }) do
|
92
92
|
expect(@session).to have_css('#divInPopupOne')
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
it
|
96
|
+
it 'should find divs in both windows' do
|
97
97
|
@session.within_window(-> { @session.title == 'Title of popup two' }) do
|
98
98
|
expect(@session).to have_css('#divInPopupTwo')
|
99
99
|
end
|
@@ -103,7 +103,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
103
103
|
expect(@session.title).to eq('With Windows')
|
104
104
|
end
|
105
105
|
|
106
|
-
it
|
106
|
+
it 'should be able to nest within_window' do
|
107
107
|
@session.within_window(-> { @session.title == 'Title of popup two' }) do
|
108
108
|
expect(@session).to have_css('#divInPopupTwo')
|
109
109
|
@session.within_window(-> { @session.title == 'Title of the first popup' }) do
|
@@ -117,7 +117,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
117
117
|
expect(@session.title).to eq('With Windows')
|
118
118
|
end
|
119
119
|
|
120
|
-
it
|
120
|
+
it 'should work inside a normal scope' do
|
121
121
|
expect(@session).to have_css('#openWindow')
|
122
122
|
@session.within(:css, '#scope') do
|
123
123
|
@session.within_window(-> { @session.title == 'Title of the first popup' }) do
|
@@ -133,18 +133,18 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
|
|
133
133
|
@session.within_window(-> { @session.title == 'Invalid title' }) do
|
134
134
|
expect(@session).to have_css('#divInPopupOne')
|
135
135
|
end
|
136
|
-
end.to raise_error(Capybara::WindowError,
|
136
|
+
end.to raise_error(Capybara::WindowError, 'Could not find a window matching block/lambda')
|
137
137
|
expect(@session.current_window).to eq(@window)
|
138
138
|
expect(@session).to have_css('#doesNotOpenWindows')
|
139
139
|
expect(@session.send(:scopes)).to eq([nil])
|
140
140
|
end
|
141
141
|
|
142
|
-
it
|
142
|
+
it 'returns value from the block' do
|
143
143
|
value = @session.within_window(-> { @session.title == 'Title of popup two' }) { 42 }
|
144
144
|
expect(value).to eq(42)
|
145
145
|
end
|
146
146
|
|
147
|
-
it
|
147
|
+
it 'should switch back if exception was raised inside block' do
|
148
148
|
expect do
|
149
149
|
@session.within_window(-> { @session.title == 'Title of popup two' }) do
|
150
150
|
raise 'some error'
|