capybara 3.13.2 → 3.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/History.md +587 -16
- data/README.md +240 -90
- data/lib/capybara/config.rb +24 -11
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +8 -0
- data/lib/capybara/driver/node.rb +20 -4
- data/lib/capybara/dsl.rb +5 -3
- data/lib/capybara/helpers.rb +25 -4
- data/lib/capybara/minitest/spec.rb +174 -90
- data/lib/capybara/minitest.rb +256 -142
- data/lib/capybara/node/actions.rb +123 -77
- data/lib/capybara/node/base.rb +20 -12
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +223 -117
- data/lib/capybara/node/finders.rb +81 -71
- data/lib/capybara/node/matchers.rb +271 -134
- data/lib/capybara/node/simple.rb +18 -5
- 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 +3 -2
- data/lib/capybara/queries/current_path_query.rb +15 -5
- data/lib/capybara/queries/selector_query.rb +364 -54
- data/lib/capybara/queries/sibling_query.rb +8 -6
- data/lib/capybara/queries/style_query.rb +2 -2
- data/lib/capybara/queries/text_query.rb +13 -1
- data/lib/capybara/queries/title_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +76 -11
- data/lib/capybara/rack_test/driver.rb +10 -5
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +31 -9
- data/lib/capybara/rack_test/node.rb +74 -23
- 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 +44 -20
- data/lib/capybara/rspec/matcher_proxies.rb +13 -11
- data/lib/capybara/rspec/matchers/base.rb +31 -16
- data/lib/capybara/rspec/matchers/compound.rb +1 -1
- 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 +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +21 -21
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +4 -4
- data/lib/capybara/rspec/matchers/have_title.rb +2 -2
- data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
- data/lib/capybara/rspec/matchers/match_style.rb +7 -2
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +111 -68
- data/lib/capybara/rspec.rb +2 -0
- data/lib/capybara/selector/builders/css_builder.rb +11 -7
- data/lib/capybara/selector/builders/xpath_builder.rb +5 -3
- data/lib/capybara/selector/css.rb +11 -9
- 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_set.rb +19 -18
- data/lib/capybara/selector/filters/base.rb +11 -2
- data/lib/capybara/selector/filters/locator_filter.rb +13 -3
- data/lib/capybara/selector/regexp_disassembler.rb +11 -7
- data/lib/capybara/selector/selector.rb +50 -440
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +473 -482
- 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 +174 -62
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +74 -18
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +128 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +37 -3
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +14 -1
- 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 +68 -45
- data/lib/capybara/selenium/extensions/html5_drag.rb +192 -22
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +8 -10
- data/lib/capybara/selenium/node.rb +268 -72
- data/lib/capybara/selenium/nodes/chrome_node.rb +105 -9
- data/lib/capybara/selenium/nodes/edge_node.rb +110 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +51 -61
- 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 +1 -1
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +43 -21
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +25 -13
- data/lib/capybara/server.rb +20 -4
- data/lib/capybara/session/config.rb +15 -11
- data/lib/capybara/session/matchers.rb +11 -11
- data/lib/capybara/session.rb +162 -131
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +105 -6
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
- data/lib/capybara/spec/session/active_element_spec.rb +31 -0
- data/lib/capybara/spec/session/all_spec.rb +89 -15
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_text_spec.rb +26 -22
- data/lib/capybara/spec/session/attach_file_spec.rb +64 -31
- data/lib/capybara/spec/session/check_spec.rb +26 -4
- data/lib/capybara/spec/session/choose_spec.rb +14 -2
- data/lib/capybara/spec/session/click_button_spec.rb +109 -61
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
- data/lib/capybara/spec/session/click_link_spec.rb +23 -1
- data/lib/capybara/spec/session/current_scope_spec.rb +1 -1
- data/lib/capybara/spec/session/current_url_spec.rb +11 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
- data/lib/capybara/spec/session/evaluate_script_spec.rb +12 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +46 -5
- data/lib/capybara/spec/session/find_link_spec.rb +10 -0
- data/lib/capybara/spec/session/find_spec.rb +80 -7
- data/lib/capybara/spec/session/first_spec.rb +2 -2
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +14 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +14 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +5 -5
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +6 -2
- data/lib/capybara/spec/session/has_button_spec.rb +81 -0
- data/lib/capybara/spec/session/has_css_spec.rb +45 -8
- data/lib/capybara/spec/session/has_current_path_spec.rb +22 -7
- data/lib/capybara/spec/session/has_element_spec.rb +47 -0
- data/lib/capybara/spec/session/has_field_spec.rb +59 -1
- data/lib/capybara/spec/session/has_link_spec.rb +40 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
- data/lib/capybara/spec/session/has_select_spec.rb +42 -8
- data/lib/capybara/spec/session/has_selector_spec.rb +19 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +177 -0
- data/lib/capybara/spec/session/has_text_spec.rb +31 -3
- data/lib/capybara/spec/session/html_spec.rb +1 -1
- data/lib/capybara/spec/session/matches_style_spec.rb +6 -4
- data/lib/capybara/spec/session/node_spec.rb +697 -23
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/refresh_spec.rb +2 -1
- data/lib/capybara/spec/session/reset_session_spec.rb +21 -7
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_page_spec.rb +4 -4
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +9 -7
- data/lib/capybara/spec/session/select_spec.rb +5 -10
- data/lib/capybara/spec/session/selectors_spec.rb +24 -3
- data/lib/capybara/spec/session/uncheck_spec.rb +3 -3
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/visit_spec.rb +20 -0
- data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_spec.rb +54 -57
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -2
- data/lib/capybara/spec/session/within_spec.rb +36 -0
- data/lib/capybara/spec/spec_helper.rb +30 -19
- data/lib/capybara/spec/test_app.rb +122 -34
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +86 -8
- data/lib/capybara/spec/views/frame_child.erb +3 -2
- 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 +10 -10
- 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 +2 -1
- 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 +34 -6
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +7 -4
- 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 +14 -18
- data/lib/capybara.rb +91 -126
- data/spec/basic_node_spec.rb +30 -16
- data/spec/capybara_spec.rb +40 -28
- data/spec/counter_spec.rb +35 -0
- data/spec/css_builder_spec.rb +3 -1
- data/spec/css_splitter_spec.rb +1 -1
- data/spec/dsl_spec.rb +33 -22
- data/spec/filter_set_spec.rb +5 -5
- data/spec/fixtures/selenium_driver_rspec_failure.rb +3 -3
- data/spec/fixtures/selenium_driver_rspec_success.rb +3 -3
- data/spec/minitest_spec.rb +24 -2
- data/spec/minitest_spec_spec.rb +60 -45
- data/spec/per_session_config_spec.rb +1 -1
- data/spec/rack_test_spec.rb +131 -98
- data/spec/regexp_dissassembler_spec.rb +53 -39
- data/spec/result_spec.rb +68 -66
- data/spec/rspec/features_spec.rb +9 -4
- data/spec/rspec/scenarios_spec.rb +6 -2
- data/spec/rspec/shared_spec_matchers.rb +137 -98
- data/spec/rspec_matchers_spec.rb +25 -0
- data/spec/rspec_spec.rb +23 -21
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +77 -21
- data/spec/selenium_spec_chrome.rb +141 -39
- data/spec/selenium_spec_chrome_remote.rb +32 -17
- data/spec/selenium_spec_edge.rb +36 -8
- data/spec/selenium_spec_firefox.rb +110 -68
- data/spec/selenium_spec_firefox_remote.rb +22 -15
- data/spec/selenium_spec_ie.rb +29 -22
- data/spec/selenium_spec_safari.rb +162 -0
- data/spec/server_spec.rb +153 -81
- data/spec/session_spec.rb +11 -4
- data/spec/shared_selenium_node.rb +79 -0
- data/spec/shared_selenium_session.rb +179 -74
- data/spec/spec_helper.rb +80 -5
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +3 -1
- metadata +218 -30
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -34,6 +34,6 @@ Capybara::SpecHelper.spec '#to_capybara_node' do
|
|
34
34
|
end.to raise_error(/^expected to find css "#second" within #<Capybara::Node::Element/)
|
35
35
|
expect do
|
36
36
|
expect(para).to have_link(href: %r{/without_simple_html})
|
37
|
-
end.to raise_error(%r{^expected to find link
|
37
|
+
end.to raise_error(%r{^expected to find link with href matching /\\/without_simple_html/ within #<Capybara::Node::Element})
|
38
38
|
end
|
39
39
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
|
4
4
|
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
|
5
5
|
# using Capybara provided assertions with builtin waiting behavior.
|
6
6
|
|
@@ -25,6 +25,7 @@ Capybara::SpecHelper.spec '#refresh' do
|
|
25
25
|
@session.visit('/form')
|
26
26
|
@session.select('Sweden', from: 'form_region')
|
27
27
|
@session.click_button('awesome')
|
28
|
+
sleep 2
|
28
29
|
expect do
|
29
30
|
@session.refresh
|
30
31
|
sleep 2
|
@@ -95,26 +95,40 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
95
95
|
expect(@session.windows.size).to eq 1
|
96
96
|
end
|
97
97
|
|
98
|
+
it 'does not block opening a new window after a frame was switched to and not switched back', requires: [:windows] do
|
99
|
+
@session.visit('/with_iframe?id=test_iframe&url=/')
|
100
|
+
@session.switch_to_frame(@session.find(:frame, 'test_iframe'))
|
101
|
+
within_window_test = lambda do
|
102
|
+
@session.within_window(@session.open_new_window) do
|
103
|
+
@session.visit('/')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
expect(&within_window_test).to raise_error(Capybara::ScopeError)
|
107
|
+
@session.reset_session!
|
108
|
+
expect(&within_window_test).not_to raise_error
|
109
|
+
end
|
110
|
+
|
98
111
|
context 'When reuse_server == false' do
|
112
|
+
let!(:orig_reuse_server) { Capybara.reuse_server }
|
113
|
+
|
99
114
|
before do
|
100
|
-
@reuse_server = Capybara.reuse_server
|
101
115
|
Capybara.reuse_server = false
|
102
116
|
end
|
103
117
|
|
104
118
|
after do
|
105
|
-
Capybara.reuse_server =
|
119
|
+
Capybara.reuse_server = orig_reuse_server
|
106
120
|
end
|
107
121
|
|
108
122
|
it 'raises any standard errors caught inside the server during a second session', requires: [:server] do
|
109
123
|
Capybara.using_driver(@session.mode) do
|
110
124
|
Capybara.using_session(:another_session) do
|
111
|
-
|
112
|
-
quietly {
|
125
|
+
another_session = Capybara.current_session
|
126
|
+
quietly { another_session.visit('/error') }
|
113
127
|
expect do
|
114
|
-
|
128
|
+
another_session.reset_session!
|
115
129
|
end.to raise_error(TestApp::TestAppError)
|
116
|
-
|
117
|
-
expect(
|
130
|
+
another_session.visit('/')
|
131
|
+
expect(another_session.current_path).to eq('/')
|
118
132
|
end
|
119
133
|
end
|
120
134
|
end
|
@@ -15,7 +15,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|
15
15
|
@session.save_and_open_screenshot
|
16
16
|
|
17
17
|
expect(@session.driver).to have_received(:save_screenshot)
|
18
|
-
.with(expected_file_regex,
|
18
|
+
.with(expected_file_regex, any_args)
|
19
19
|
expect(Launchy).to have_received(:open).with(expected_file_regex)
|
20
20
|
end
|
21
21
|
|
@@ -27,7 +27,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|
27
27
|
@session.save_and_open_screenshot(custom_path)
|
28
28
|
|
29
29
|
expect(@session.driver).to have_received(:save_screenshot)
|
30
|
-
.with(/#{custom_path}$/,
|
30
|
+
.with(/#{custom_path}$/, any_args)
|
31
31
|
expect(Launchy).to have_received(:open).with(/#{custom_path}$/)
|
32
32
|
end
|
33
33
|
|
@@ -31,7 +31,7 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
31
31
|
it 'can store files in a specified directory' do
|
32
32
|
Capybara.save_path = alternative_path
|
33
33
|
@session.save_page
|
34
|
-
path = Dir.glob(alternative_path
|
34
|
+
path = Dir.glob("#{alternative_path}/capybara-*.html").first
|
35
35
|
expect(File.read(path)).to include('Another World')
|
36
36
|
end
|
37
37
|
|
@@ -43,14 +43,14 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
43
43
|
it 'can store files in a specified directory with a given filename' do
|
44
44
|
Capybara.save_path = alternative_path
|
45
45
|
@session.save_page('capybara-001133.html')
|
46
|
-
path = alternative_path
|
46
|
+
path = "#{alternative_path}/capybara-001133.html"
|
47
47
|
expect(File.read(path)).to include('Another World')
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'can store files in a specified directory with a given relative filename' do
|
51
51
|
Capybara.save_path = alternative_path
|
52
52
|
@session.save_page('tmp/capybara-001144.html')
|
53
|
-
path = alternative_path
|
53
|
+
path = "#{alternative_path}/tmp/capybara-001144.html"
|
54
54
|
expect(File.read(path)).to include('Another World')
|
55
55
|
end
|
56
56
|
|
@@ -63,7 +63,7 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
63
63
|
it 'returns an absolute path in given directory' do
|
64
64
|
Capybara.save_path = alternative_path
|
65
65
|
result = @session.save_page
|
66
|
-
path = File.expand_path(Dir.glob(alternative_path
|
66
|
+
path = File.expand_path(Dir.glob("#{alternative_path}/capybara-*.html").first, alternative_path)
|
67
67
|
expect(result).to eq(path)
|
68
68
|
end
|
69
69
|
|
@@ -19,7 +19,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
|
|
19
19
|
@session.save_screenshot
|
20
20
|
|
21
21
|
regexp = Regexp.new(File.join(Dir.pwd, 'capybara-\d+\.png'))
|
22
|
-
expect(@session.driver).to have_received(:save_screenshot).with(regexp,
|
22
|
+
expect(@session.driver).to have_received(:save_screenshot).with(regexp, any_args)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'allows to specify another path' do
|
@@ -28,7 +28,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
|
|
28
28
|
custom_path = 'screenshots/1.png'
|
29
29
|
@session.save_screenshot(custom_path)
|
30
30
|
|
31
|
-
expect(@session.driver).to have_received(:save_screenshot).with(/#{custom_path}$/,
|
31
|
+
expect(@session.driver).to have_received(:save_screenshot).with(/#{custom_path}$/, any_args)
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'with Capybara.save_path' do
|
@@ -39,7 +39,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
|
|
39
39
|
@session.save_screenshot
|
40
40
|
|
41
41
|
regexp = Regexp.new(File.join(alternative_path, 'capybara-\d+\.png'))
|
42
|
-
expect(@session.driver).to have_received(:save_screenshot).with(regexp,
|
42
|
+
expect(@session.driver).to have_received(:save_screenshot).with(regexp, any_args)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'relative paths are relative to save_path' do
|
@@ -49,7 +49,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
|
|
49
49
|
custom_path = 'screenshots/2.png'
|
50
50
|
@session.save_screenshot(custom_path)
|
51
51
|
|
52
|
-
expect(@session.driver).to have_received(:save_screenshot).with(File.expand_path(custom_path, alternative_path),
|
52
|
+
expect(@session.driver).to have_received(:save_screenshot).with(File.expand_path(custom_path, alternative_path), any_args)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -15,7 +15,7 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|
15
15
|
el = @session.find(:css, '#scroll')
|
16
16
|
@session.scroll_to(el, align: :bottom)
|
17
17
|
el_bottom = el.evaluate_script('this.getBoundingClientRect().bottom')
|
18
|
-
viewport_bottom = el.evaluate_script('document.
|
18
|
+
viewport_bottom = el.evaluate_script('document.documentElement.clientHeight')
|
19
19
|
expect(el_bottom).to be_within(1).of(viewport_bottom)
|
20
20
|
end
|
21
21
|
|
@@ -23,8 +23,8 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|
23
23
|
el = @session.find(:css, '#scroll')
|
24
24
|
@session.scroll_to(el, align: :center)
|
25
25
|
el_center = el.evaluate_script('(function(rect){return (rect.top + rect.bottom)/2})(this.getBoundingClientRect())')
|
26
|
-
viewport_bottom = el.evaluate_script('document.
|
27
|
-
expect(el_center).to be_within(
|
26
|
+
viewport_bottom = el.evaluate_script('document.documentElement.clientHeight')
|
27
|
+
expect(el_center).to be_within(2).of(viewport_bottom / 2)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'can scroll the window to the vertical top' do
|
@@ -35,13 +35,15 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|
35
35
|
|
36
36
|
it 'can scroll the window to the vertical bottom' do
|
37
37
|
@session.scroll_to :bottom
|
38
|
-
max_scroll = @session.evaluate_script('document.
|
39
|
-
|
38
|
+
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.documentElement.clientHeight')
|
39
|
+
scrolled_location_x, scrolled_location_y = @session.evaluate_script('[window.scrollX || window.pageXOffset, window.scrollY || window.pageYOffset]')
|
40
|
+
expect(scrolled_location_x).to be_within(0.5).of(0)
|
41
|
+
expect(scrolled_location_y).to be_within(0.5).of(max_scroll)
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'can scroll the window to the vertical center' do
|
43
45
|
@session.scroll_to :center
|
44
|
-
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.
|
46
|
+
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.documentElement.clientHeight')
|
45
47
|
expect(@session.evaluate_script('[window.scrollX || window.pageXOffset, window.scrollY || window.pageYOffset]')).to eq [0, max_scroll / 2]
|
46
48
|
end
|
47
49
|
|
@@ -108,7 +110,7 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|
108
110
|
expect(@session.evaluate_script('[window.scrollX || window.pageXOffset, window.scrollY || window.pageYOffset]')).to eq [50, 75]
|
109
111
|
end
|
110
112
|
|
111
|
-
it 'can scroll the scroll the scrolling element by a
|
113
|
+
it 'can scroll the scroll the scrolling element by a specific amount' do
|
112
114
|
scrolling_element = @session.find(:css, '#scrollable')
|
113
115
|
scrolling_element.scroll_to 100, 100
|
114
116
|
scrolling_element.scroll_to(:current, offset: [-50, 50])
|
@@ -42,13 +42,13 @@ Capybara::SpecHelper.spec '#select' do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should select an option from a select box by id' do
|
45
|
-
@session.select('
|
45
|
+
@session.select('Finnish', from: 'form_locale')
|
46
46
|
@session.click_button('awesome')
|
47
47
|
expect(extract_results(@session)['locale']).to eq('fi')
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should select an option from a select box by label' do
|
51
|
-
@session.select('
|
51
|
+
@session.select('Finnish', from: 'Locale')
|
52
52
|
@session.click_button('awesome')
|
53
53
|
expect(extract_results(@session)['locale']).to eq('fi')
|
54
54
|
end
|
@@ -141,11 +141,6 @@ Capybara::SpecHelper.spec '#select' do
|
|
141
141
|
@session.select('Other', from: 'form_title')
|
142
142
|
expect(@session.find_field('form_title').value).not_to eq 'Other'
|
143
143
|
end
|
144
|
-
|
145
|
-
it 'should warn' do
|
146
|
-
expect_any_instance_of(Capybara::Node::Element).to receive(:warn).once
|
147
|
-
@session.select('Other', from: 'form_title')
|
148
|
-
end
|
149
144
|
end
|
150
145
|
|
151
146
|
context 'with multiple select' do
|
@@ -188,7 +183,7 @@ Capybara::SpecHelper.spec '#select' do
|
|
188
183
|
context 'with :exact option' do
|
189
184
|
context 'when `false`' do
|
190
185
|
it 'can match select box approximately' do
|
191
|
-
@session.select('
|
186
|
+
@session.select('Finnish', from: 'Loc', exact: false)
|
192
187
|
@session.click_button('awesome')
|
193
188
|
expect(extract_results(@session)['locale']).to eq('fi')
|
194
189
|
end
|
@@ -209,13 +204,13 @@ Capybara::SpecHelper.spec '#select' do
|
|
209
204
|
context 'when `true`' do
|
210
205
|
it 'can match select box approximately' do
|
211
206
|
expect do
|
212
|
-
@session.select('
|
207
|
+
@session.select('Finnish', from: 'Loc', exact: true)
|
213
208
|
end.to raise_error(Capybara::ElementNotFound)
|
214
209
|
end
|
215
210
|
|
216
211
|
it 'can match option approximately' do
|
217
212
|
expect do
|
218
|
-
@session.select('Fin', from: 'Locale', exact:
|
213
|
+
@session.select('Fin', from: 'Locale', exact: true)
|
219
214
|
end.to raise_error(Capybara::ElementNotFound)
|
220
215
|
end
|
221
216
|
|
@@ -14,15 +14,28 @@ Capybara::SpecHelper.spec Capybara::Selector do
|
|
14
14
|
expect(@session.find(:label, for: 'form_other_title')['for']).to eq 'form_other_title'
|
15
15
|
end
|
16
16
|
|
17
|
+
it 'finds a label for for attribute regex' do
|
18
|
+
expect(@session.find(:label, for: /_other_title/)['for']).to eq 'form_other_title'
|
19
|
+
end
|
20
|
+
|
17
21
|
it 'finds a label from nested input using :for filter with id string' do
|
18
22
|
expect(@session.find(:label, for: 'nested_label').text).to eq 'Nested Label'
|
19
23
|
end
|
20
24
|
|
25
|
+
it 'finds a label from nested input using :for filter with id regexp' do
|
26
|
+
expect(@session.find(:label, for: /nested_lab/).text).to eq 'Nested Label'
|
27
|
+
end
|
28
|
+
|
21
29
|
it 'finds a label from nested input using :for filter with element' do
|
22
30
|
input = @session.find(:id, 'nested_label')
|
23
31
|
expect(@session.find(:label, for: input).text).to eq 'Nested Label'
|
24
32
|
end
|
25
33
|
|
34
|
+
it 'finds a label from nested input using :for filter with element when no id on label' do
|
35
|
+
input = @session.find(:css, '#wrapper_label').find(:css, 'input')
|
36
|
+
expect(@session.find(:label, for: input).text).to eq 'Wrapper Label'
|
37
|
+
end
|
38
|
+
|
26
39
|
it 'finds the label for an non-nested element when using :for filter' do
|
27
40
|
select = @session.find(:id, 'form_other_title')
|
28
41
|
expect(@session.find(:label, for: select)['for']).to eq 'form_other_title'
|
@@ -54,14 +67,22 @@ Capybara::SpecHelper.spec Capybara::Selector do
|
|
54
67
|
end
|
55
68
|
end
|
56
69
|
|
57
|
-
it 'can find specifically by name' do
|
70
|
+
it 'can find specifically by name string' do
|
58
71
|
expect(@session.find(:field, name: 'form[other_title]')['id']).to eq 'form_other_title'
|
59
72
|
end
|
60
73
|
|
61
|
-
it 'can find specifically by
|
74
|
+
it 'can find specifically by name regex' do
|
75
|
+
expect(@session.find(:field, name: /form\[other_.*\]/)['id']).to eq 'form_other_title'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'can find specifically by placeholder string' do
|
62
79
|
expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq 'form_first_name'
|
63
80
|
end
|
64
81
|
|
82
|
+
it 'can find specifically by placeholder regex' do
|
83
|
+
expect(@session.find(:field, placeholder: /FirstN.*/)['id']).to eq 'form_first_name'
|
84
|
+
end
|
85
|
+
|
65
86
|
it 'can find by type' do
|
66
87
|
expect(@session.find(:field, 'Confusion', type: 'checkbox')['id']).to eq 'confusion_checkbox'
|
67
88
|
expect(@session.find(:field, 'Confusion', type: 'text')['id']).to eq 'confusion_text'
|
@@ -71,7 +92,7 @@ Capybara::SpecHelper.spec Capybara::Selector do
|
|
71
92
|
it 'can find by class' do
|
72
93
|
expect(@session.find(:field, class: 'confusion-checkbox')['id']).to eq 'confusion_checkbox'
|
73
94
|
expect(@session).to have_selector(:field, class: 'confusion', count: 3)
|
74
|
-
expect(@session.find(:field, class: [
|
95
|
+
expect(@session.find(:field, class: %w[confusion confusion-textarea])['id']).to eq 'confusion_textarea'
|
75
96
|
end
|
76
97
|
end
|
77
98
|
end
|
@@ -50,7 +50,7 @@ Capybara::SpecHelper.spec '#uncheck' do
|
|
50
50
|
|
51
51
|
it 'should not accept partial matches when true' do
|
52
52
|
expect do
|
53
|
-
@session.uncheck('Ham', exact:
|
53
|
+
@session.uncheck('Ham', exact: true)
|
54
54
|
end.to raise_error(Capybara::ElementNotFound)
|
55
55
|
end
|
56
56
|
end
|
@@ -85,11 +85,11 @@ Capybara::SpecHelper.spec '#uncheck' do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should raise original error when no label available' do
|
88
|
-
expect { @session.uncheck('form_cars_porsche') }.to raise_error(Capybara::ElementNotFound,
|
88
|
+
expect { @session.uncheck('form_cars_porsche') }.to raise_error(Capybara::ElementNotFound, /Unable to find visible checkbox "form_cars_porsche"/)
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should raise error if not allowed to click label' do
|
92
|
-
expect { @session.uncheck('form_cars_jaguar', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound,
|
92
|
+
expect { @session.uncheck('form_cars_jaguar', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, /Unable to find visible checkbox "form_cars_jaguar"/)
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should include node filter description in error if necessary' do
|
@@ -56,7 +56,7 @@ Capybara::SpecHelper.spec '#unselect' do
|
|
56
56
|
|
57
57
|
context "with a locator that doesn't exist" do
|
58
58
|
it 'should raise an error' do
|
59
|
-
msg =
|
59
|
+
msg = /Unable to find select box "does not exist"/
|
60
60
|
expect do
|
61
61
|
@session.unselect('foo', from: 'does not exist')
|
62
62
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
@@ -201,4 +201,24 @@ Capybara::SpecHelper.spec '#visit' do
|
|
201
201
|
@session.visit('/get_cookie')
|
202
202
|
expect(@session).to have_content('root cookie')
|
203
203
|
end
|
204
|
+
|
205
|
+
context 'with base element' do
|
206
|
+
it 'should use base href with relative links' do
|
207
|
+
@session.visit('/base/with_base')
|
208
|
+
@session.click_link('Title page')
|
209
|
+
expect(@session).to have_current_path('/with_title')
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should use base href with bare queries' do
|
213
|
+
@session.visit('/base/with_base')
|
214
|
+
@session.click_link('Bare query')
|
215
|
+
expect(@session).to have_current_path('/?a=3')
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should not use the base href with a new visit call' do
|
219
|
+
@session.visit('/base/with_other_base')
|
220
|
+
@session.visit('with_html')
|
221
|
+
expect(@session).to have_current_path('/with_html')
|
222
|
+
end
|
223
|
+
end
|
204
224
|
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
|
|
11
|
+
before do
|
12
|
+
@session.visit('/with_windows')
|
13
|
+
end
|
14
|
+
|
12
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(
|
73
|
+
expect(other_window).not_to become_closed
|
71
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,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
|
4
4
|
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
|
5
5
|
# using Capybara provided assertions with builtin waiting behavior.
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
|
4
4
|
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
|
5
5
|
# using Capybara provided assertions with builtin waiting behavior.
|
6
6
|
|