capybara 3.8.1 → 3.33.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 +465 -0
- data/License.txt +1 -1
- data/README.md +58 -57
- data/lib/capybara/config.rb +10 -4
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +2 -2
- data/lib/capybara/driver/node.rb +26 -5
- data/lib/capybara/dsl.rb +12 -4
- data/lib/capybara/helpers.rb +8 -4
- data/lib/capybara/minitest/spec.rb +162 -85
- data/lib/capybara/minitest.rb +248 -148
- data/lib/capybara/node/actions.rb +149 -96
- data/lib/capybara/node/base.rb +27 -10
- data/lib/capybara/node/document.rb +12 -0
- data/lib/capybara/node/document_matchers.rb +9 -5
- data/lib/capybara/node/element.rb +254 -109
- data/lib/capybara/node/finders.rb +83 -76
- data/lib/capybara/node/matchers.rb +279 -141
- data/lib/capybara/node/simple.rb +25 -6
- data/lib/capybara/queries/ancestor_query.rb +5 -7
- data/lib/capybara/queries/base_query.rb +11 -5
- data/lib/capybara/queries/current_path_query.rb +3 -3
- data/lib/capybara/queries/match_query.rb +1 -0
- data/lib/capybara/queries/selector_query.rb +467 -103
- data/lib/capybara/queries/sibling_query.rb +5 -4
- data/lib/capybara/queries/style_query.rb +6 -2
- data/lib/capybara/queries/text_query.rb +17 -3
- data/lib/capybara/queries/title_query.rb +2 -2
- data/lib/capybara/rack_test/browser.rb +22 -15
- data/lib/capybara/rack_test/driver.rb +10 -1
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +33 -28
- data/lib/capybara/rack_test/node.rb +74 -6
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +36 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
- data/lib/capybara/registrations/servers.rb +44 -0
- data/lib/capybara/result.rb +55 -23
- data/lib/capybara/rspec/features.rb +4 -4
- data/lib/capybara/rspec/matcher_proxies.rb +36 -15
- 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 +38 -0
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +117 -311
- data/lib/capybara/selector/builders/css_builder.rb +84 -0
- data/lib/capybara/selector/builders/xpath_builder.rb +69 -0
- data/lib/capybara/selector/css.rb +17 -15
- data/lib/capybara/selector/definition/button.rb +52 -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 +27 -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 +277 -0
- data/lib/capybara/selector/filter.rb +1 -0
- data/lib/capybara/selector/filter_set.rb +26 -19
- 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 +214 -0
- data/lib/capybara/selector/selector.rb +73 -367
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +221 -480
- 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 +203 -86
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +88 -14
- 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 +191 -22
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +78 -0
- data/lib/capybara/selenium/logger_suppressor.rb +34 -0
- data/lib/capybara/selenium/node.rb +298 -93
- data/lib/capybara/selenium/nodes/chrome_node.rb +100 -8
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +131 -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 +1 -3
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +4 -3
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +23 -13
- data/lib/capybara/server.rb +30 -7
- data/lib/capybara/session/config.rb +14 -10
- data/lib/capybara/session/matchers.rb +11 -7
- data/lib/capybara/session.rb +152 -111
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +101 -10
- data/lib/capybara/spec/session/all_spec.rb +96 -6
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +29 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_selector_spec.rb +0 -10
- data/lib/capybara/spec/session/assert_style_spec.rb +4 -4
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/attach_file_spec.rb +63 -36
- data/lib/capybara/spec/session/check_spec.rb +10 -4
- data/lib/capybara/spec/session/choose_spec.rb +8 -2
- data/lib/capybara/spec/session/click_button_spec.rb +117 -61
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +16 -0
- data/lib/capybara/spec/session/click_link_spec.rb +17 -6
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
- data/lib/capybara/spec/session/evaluate_script_spec.rb +13 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +47 -6
- data/lib/capybara/spec/session/find_field_spec.rb +1 -1
- data/lib/capybara/spec/session/find_spec.rb +74 -4
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +13 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +1 -1
- 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 +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +122 -12
- data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
- data/lib/capybara/spec/session/has_field_spec.rb +55 -0
- data/lib/capybara/spec/session/has_select_spec.rb +34 -6
- data/lib/capybara/spec/session/has_selector_spec.rb +11 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +166 -0
- data/lib/capybara/spec/session/has_text_spec.rb +48 -1
- data/lib/capybara/spec/session/has_xpath_spec.rb +17 -0
- data/lib/capybara/spec/session/html_spec.rb +7 -0
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +643 -18
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/refresh_spec.rb +4 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +23 -8
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +117 -0
- data/lib/capybara/spec/session/select_spec.rb +10 -10
- data/lib/capybara/spec/session/selectors_spec.rb +36 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +4 -0
- data/lib/capybara/spec/session/window/window_spec.rb +59 -58
- data/lib/capybara/spec/session/window/windows_spec.rb +4 -0
- data/lib/capybara/spec/session/within_spec.rb +23 -0
- data/lib/capybara/spec/spec_helper.rb +16 -6
- data/lib/capybara/spec/test_app.rb +28 -23
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +48 -7
- data/lib/capybara/spec/views/frame_child.erb +3 -2
- data/lib/capybara/spec/views/frame_one.erb +1 -0
- data/lib/capybara/spec/views/obscured.erb +47 -0
- data/lib/capybara/spec/views/offset.erb +32 -0
- 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 +67 -0
- data/lib/capybara/spec/views/with_animation.erb +29 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_hover.erb +1 -0
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +32 -6
- data/lib/capybara/spec/views/with_js.erb +3 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +11 -11
- data/lib/capybara.rb +118 -111
- data/spec/basic_node_spec.rb +14 -3
- data/spec/capybara_spec.rb +29 -29
- data/spec/css_builder_spec.rb +101 -0
- data/spec/dsl_spec.rb +46 -21
- data/spec/filter_set_spec.rb +5 -5
- data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +18 -4
- data/spec/minitest_spec_spec.rb +59 -44
- data/spec/rack_test_spec.rb +117 -89
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +51 -49
- data/spec/rspec/features_spec.rb +3 -0
- data/spec/rspec/shared_spec_matchers.rb +112 -97
- data/spec/rspec_spec.rb +35 -17
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +244 -28
- data/spec/selenium_spec_chrome.rb +125 -54
- data/spec/selenium_spec_chrome_remote.rb +26 -12
- data/spec/selenium_spec_edge.rb +23 -8
- data/spec/selenium_spec_firefox.rb +208 -0
- data/spec/selenium_spec_firefox_remote.rb +15 -18
- data/spec/selenium_spec_ie.rb +82 -13
- data/spec/selenium_spec_safari.rb +148 -0
- data/spec/server_spec.rb +118 -77
- data/spec/session_spec.rb +19 -3
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +110 -65
- data/spec/spec_helper.rb +57 -9
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +257 -17
- data/lib/capybara/rspec/compound.rb +0 -94
- data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -49
- data/lib/capybara/selenium/nodes/marionette_node.rb +0 -121
- data/lib/capybara/spec/session/has_style_spec.rb +0 -25
- data/spec/selenium_spec_marionette.rb +0 -172
@@ -110,4 +110,20 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|
110
110
|
link = @session.find(:link, 'Blank Anchor')
|
111
111
|
expect(@session.click_link_or_button('Blank Anchor')).to eq link
|
112
112
|
end
|
113
|
+
|
114
|
+
context 'with enable_aria_label' do
|
115
|
+
it 'should click on link' do
|
116
|
+
@session.visit('/with_html')
|
117
|
+
expect do
|
118
|
+
@session.click_link_or_button('Go to simple', enable_aria_label: true)
|
119
|
+
end.not_to raise_error
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should click on button' do
|
123
|
+
@session.visit('/form')
|
124
|
+
expect do
|
125
|
+
@session.click_link_or_button('Aria button', enable_aria_label: true)
|
126
|
+
end.not_to raise_error
|
127
|
+
end
|
128
|
+
end
|
113
129
|
end
|
@@ -83,7 +83,7 @@ Capybara::SpecHelper.spec '#click_link' do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should raise error if link wasn't found" do
|
86
|
-
expect { @session.click_link('labore', href: 'invalid_href') }.to raise_error(Capybara::ElementNotFound)
|
86
|
+
expect { @session.click_link('labore', href: 'invalid_href') }.to raise_error(Capybara::ElementNotFound, /with href "invalid_href/)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -104,8 +104,8 @@ Capybara::SpecHelper.spec '#click_link' do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should raise an error if no link's href matched the pattern" do
|
107
|
-
expect { @session.click_link('labore', href: /invalid_pattern/) }.to raise_error(Capybara::ElementNotFound)
|
108
|
-
expect { @session.click_link('labore', href: /.+d+/) }.to raise_error(Capybara::ElementNotFound)
|
107
|
+
expect { @session.click_link('labore', href: /invalid_pattern/) }.to raise_error(Capybara::ElementNotFound, %r{with href matching /invalid_pattern/})
|
108
|
+
expect { @session.click_link('labore', href: /.+d+/) }.to raise_error(Capybara::ElementNotFound, /#{Regexp.quote "with href matching /.+d+/"}/)
|
109
109
|
end
|
110
110
|
|
111
111
|
context 'href: nil' do
|
@@ -114,8 +114,19 @@ Capybara::SpecHelper.spec '#click_link' do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'should raise an error if href attribute exists' do
|
117
|
-
expect { @session.click_link('Blank Href', href: nil) }.to raise_error(Capybara::ElementNotFound)
|
118
|
-
expect { @session.click_link('Normal Anchor', href: nil) }.to raise_error(Capybara::ElementNotFound)
|
117
|
+
expect { @session.click_link('Blank Href', href: nil) }.to raise_error(Capybara::ElementNotFound, /with no href attribute/)
|
118
|
+
expect { @session.click_link('Normal Anchor', href: nil) }.to raise_error(Capybara::ElementNotFound, /with no href attribute/)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'href: false' do
|
123
|
+
it 'should not raise an error on links with no href attribute' do
|
124
|
+
expect { @session.click_link('No Href', href: false) }.not_to raise_error
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should not raise an error if href attribute exists' do
|
128
|
+
expect { @session.click_link('Blank Href', href: false) }.not_to raise_error
|
129
|
+
expect { @session.click_link('Normal Anchor', href: false) }.not_to raise_error
|
119
130
|
end
|
120
131
|
end
|
121
132
|
end
|
@@ -211,7 +222,7 @@ Capybara::SpecHelper.spec '#click_link' do
|
|
211
222
|
download_file = File.join(Capybara.save_path, 'download.csv')
|
212
223
|
expect(File).not_to exist(download_file)
|
213
224
|
@session.click_link('Download Me')
|
214
|
-
sleep 2
|
225
|
+
sleep 2 # allow time for file to download
|
215
226
|
expect(File).to exist(download_file)
|
216
227
|
FileUtils.rm_rf download_file
|
217
228
|
end
|
@@ -1,31 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#match_selector?' do
|
4
|
+
let(:element) { @session.find(:xpath, '//span', text: '42') }
|
5
|
+
|
4
6
|
before do
|
5
7
|
@session.visit('/with_html')
|
6
|
-
@element = @session.find('//span', text: '42')
|
7
8
|
end
|
8
9
|
|
9
10
|
it 'should be true if the element matches the given selector' do
|
10
|
-
expect(
|
11
|
-
expect(
|
12
|
-
expect(
|
11
|
+
expect(element).to match_selector(:xpath, '//span')
|
12
|
+
expect(element).to match_selector(:css, 'span.number')
|
13
|
+
expect(element.matches_selector?(:css, 'span.number')).to be true
|
13
14
|
end
|
14
15
|
|
15
16
|
it 'should be false if the element does not match the given selector' do
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
expect(
|
17
|
+
expect(element).not_to match_selector(:xpath, '//div')
|
18
|
+
expect(element).not_to match_selector(:css, 'span.not_a_number')
|
19
|
+
expect(element.matches_selector?(:css, 'span.not_a_number')).to be false
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'should use default selector' do
|
22
23
|
Capybara.default_selector = :css
|
23
|
-
expect(
|
24
|
-
expect(
|
24
|
+
expect(element).not_to match_selector('span.not_a_number')
|
25
|
+
expect(element).to match_selector('span.number')
|
25
26
|
end
|
26
27
|
|
27
28
|
it 'should work with elements located via a sibling selector' do
|
28
|
-
sibling =
|
29
|
+
sibling = element.sibling(:css, 'span', text: 'Other span')
|
29
30
|
expect(sibling).to match_selector(:xpath, '//span')
|
30
31
|
expect(sibling).to match_selector(:css, 'span')
|
31
32
|
end
|
@@ -37,23 +38,23 @@ Capybara::SpecHelper.spec '#match_selector?' do
|
|
37
38
|
|
38
39
|
context 'with text' do
|
39
40
|
it 'should discard all matches where the given string is not contained' do
|
40
|
-
expect(
|
41
|
-
expect(
|
41
|
+
expect(element).to match_selector('//span', text: '42')
|
42
|
+
expect(element).not_to match_selector('//span', text: 'Doesnotexist')
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
46
|
it 'should have css sugar' do
|
46
|
-
expect(
|
47
|
-
expect(
|
48
|
-
expect(
|
49
|
-
expect(
|
47
|
+
expect(element.matches_css?('span.number')).to be true
|
48
|
+
expect(element.matches_css?('span.not_a_number')).to be false
|
49
|
+
expect(element.matches_css?('span.number', text: '42')).to be true
|
50
|
+
expect(element.matches_css?('span.number', text: 'Nope')).to be false
|
50
51
|
end
|
51
52
|
|
52
53
|
it 'should have xpath sugar' do
|
53
|
-
expect(
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
54
|
+
expect(element.matches_xpath?('//span')).to be true
|
55
|
+
expect(element.matches_xpath?('//div')).to be false
|
56
|
+
expect(element.matches_xpath?('//span', text: '42')).to be true
|
57
|
+
expect(element.matches_xpath?('//span', text: 'Nope')).to be false
|
57
58
|
end
|
58
59
|
|
59
60
|
it 'should accept selector filters' do
|
@@ -73,47 +74,47 @@ Capybara::SpecHelper.spec '#match_selector?' do
|
|
73
74
|
end
|
74
75
|
|
75
76
|
Capybara::SpecHelper.spec '#not_matches_selector?' do
|
77
|
+
let(:element) { @session.find(:css, 'span', text: 42) }
|
76
78
|
before do
|
77
79
|
@session.visit('/with_html')
|
78
|
-
@element = @session.find(:css, 'span', text: 42)
|
79
80
|
end
|
80
81
|
|
81
82
|
it 'should be false if the given selector matches the element' do
|
82
|
-
expect(
|
83
|
-
expect(
|
84
|
-
expect(
|
83
|
+
expect(element).not_to not_match_selector(:xpath, '//span')
|
84
|
+
expect(element).not_to not_match_selector(:css, 'span.number')
|
85
|
+
expect(element.not_matches_selector?(:css, 'span.number')).to be false
|
85
86
|
end
|
86
87
|
|
87
88
|
it 'should be true if the given selector does not match the element' do
|
88
|
-
expect(
|
89
|
-
expect(
|
90
|
-
expect(
|
89
|
+
expect(element).to not_match_selector(:xpath, '//abbr')
|
90
|
+
expect(element).to not_match_selector(:css, 'p a#doesnotexist')
|
91
|
+
expect(element.not_matches_selector?(:css, 'p a#doesnotexist')).to be true
|
91
92
|
end
|
92
93
|
|
93
94
|
it 'should use default selector' do
|
94
95
|
Capybara.default_selector = :css
|
95
|
-
expect(
|
96
|
-
expect(
|
96
|
+
expect(element).to not_match_selector('p a#doesnotexist')
|
97
|
+
expect(element).not_to not_match_selector('span.number')
|
97
98
|
end
|
98
99
|
|
99
100
|
context 'with text' do
|
100
101
|
it 'should discard all matches where the given string is contained' do
|
101
|
-
expect(
|
102
|
-
expect(
|
102
|
+
expect(element).not_to not_match_selector(:css, 'span.number', text: '42')
|
103
|
+
expect(element).to not_match_selector(:css, 'span.number', text: 'Doesnotexist')
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
107
|
it 'should have CSS sugar' do
|
107
|
-
expect(
|
108
|
-
expect(
|
109
|
-
expect(
|
110
|
-
expect(
|
108
|
+
expect(element.not_matches_css?('span.number')).to be false
|
109
|
+
expect(element.not_matches_css?('p a#doesnotexist')).to be true
|
110
|
+
expect(element.not_matches_css?('span.number', text: '42')).to be false
|
111
|
+
expect(element.not_matches_css?('span.number', text: 'Doesnotexist')).to be true
|
111
112
|
end
|
112
113
|
|
113
114
|
it 'should have xpath sugar' do
|
114
|
-
expect(
|
115
|
-
expect(
|
116
|
-
expect(
|
117
|
-
expect(
|
115
|
+
expect(element.not_matches_xpath?('//span')).to be false
|
116
|
+
expect(element.not_matches_xpath?('//div')).to be true
|
117
|
+
expect(element.not_matches_xpath?('//span', text: '42')).to be false
|
118
|
+
expect(element.not_matches_xpath?('//span', text: 'Doesnotexist')).to be true
|
118
119
|
end
|
119
120
|
end
|
@@ -15,6 +15,7 @@ Capybara::SpecHelper.spec '#evaluate_script', requires: [:js] do
|
|
15
15
|
|
16
16
|
it 'should pass arguments to the script', requires: %i[js es_args] do
|
17
17
|
@session.visit('/with_js')
|
18
|
+
expect(@session).to have_css('#change')
|
18
19
|
@session.evaluate_script("document.getElementById('change').textContent = arguments[0]", 'Doodle Funk')
|
19
20
|
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
20
21
|
end
|
@@ -33,4 +34,16 @@ Capybara::SpecHelper.spec '#evaluate_script', requires: [:js] do
|
|
33
34
|
expect(el).to be_instance_of(Capybara::Node::Element)
|
34
35
|
expect(el).to eq(@session.find(:css, '#change'))
|
35
36
|
end
|
37
|
+
|
38
|
+
it 'should support multi statement via IIFE' do
|
39
|
+
@session.visit('/with_js')
|
40
|
+
@session.find(:css, '#change')
|
41
|
+
el = @session.evaluate_script(<<~JS)
|
42
|
+
(function(){
|
43
|
+
var el = document.getElementById('change');
|
44
|
+
return el;
|
45
|
+
})()
|
46
|
+
JS
|
47
|
+
expect(el).to eq(@session.find(:css, '#change'))
|
48
|
+
end
|
36
49
|
end
|
@@ -14,6 +14,7 @@ Capybara::SpecHelper.spec '#execute_script', requires: [:js] do
|
|
14
14
|
|
15
15
|
it 'should pass arguments to the script', requires: %i[js es_args] do
|
16
16
|
@session.visit('/with_js')
|
17
|
+
expect(@session).to have_css('#change')
|
17
18
|
@session.execute_script("document.getElementById('change').textContent = arguments[0]", 'Doodle Funk')
|
18
19
|
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
19
20
|
end
|
@@ -47,6 +47,15 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
47
47
|
expect(extract_results(@session)['description']).to eq('Texty text')
|
48
48
|
end
|
49
49
|
|
50
|
+
it 'should fill in a textarea in a reasonable time by default' do
|
51
|
+
textarea = @session.find(:fillable_field, 'form[description]')
|
52
|
+
value = 'a' * 4000
|
53
|
+
start = Time.now
|
54
|
+
textarea.fill_in(with: value)
|
55
|
+
expect(Time.now.to_f).to be_within(0.25).of start.to_f
|
56
|
+
expect(textarea.value).to eq value
|
57
|
+
end
|
58
|
+
|
50
59
|
it 'should fill in a password field by id' do
|
51
60
|
@session.fill_in('form_password', with: 'supasikrit')
|
52
61
|
@session.click_button('awesome')
|
@@ -89,6 +98,32 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
89
98
|
expect(extract_results(@session)['description']).to eq("\r\nSome text\r\n")
|
90
99
|
end
|
91
100
|
|
101
|
+
it 'should fill in a color field' do
|
102
|
+
@session.fill_in('Html5 Color', with: '#112233')
|
103
|
+
@session.click_button('html5_submit')
|
104
|
+
expect(extract_results(@session)['html5_color']).to eq('#112233')
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'with input[type="range"]' do
|
108
|
+
it 'should set the range slider correctly' do
|
109
|
+
@session.fill_in('form_age', with: 51)
|
110
|
+
@session.click_button('awesome')
|
111
|
+
expect(extract_results(@session)['age'].to_f).to eq 51
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should set the range slider to valid values' do
|
115
|
+
@session.fill_in('form_age', with: '37.6')
|
116
|
+
@session.click_button('awesome')
|
117
|
+
expect(extract_results(@session)['age'].to_f).to eq 37.5
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should respect the range slider limits' do
|
121
|
+
@session.fill_in('form_age', with: '3')
|
122
|
+
@session.click_button('awesome')
|
123
|
+
expect(extract_results(@session)['age'].to_f).to eq 13
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
92
127
|
it 'should fill in a field with a custom type' do
|
93
128
|
@session.fill_in('Schmooo', with: 'Schmooo is the game')
|
94
129
|
@session.click_button('awesome')
|
@@ -126,7 +161,7 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
126
161
|
end
|
127
162
|
|
128
163
|
it 'should fill in a field based on current value' do
|
129
|
-
@session.fill_in(currently_with: 'John', with: 'Thomas')
|
164
|
+
@session.fill_in(id: /form.*name/, currently_with: 'John', with: 'Thomas')
|
130
165
|
@session.click_button('awesome')
|
131
166
|
expect(extract_results(@session)['first_name']).to eq('Thomas')
|
132
167
|
end
|
@@ -178,10 +213,10 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
178
213
|
it 'should only trigger onchange once' do
|
179
214
|
@session.visit('/with_js')
|
180
215
|
# Click somewhere on the page to ensure focus is acquired. Without this FF won't generate change events for some reason???
|
181
|
-
@session.find(:css, '
|
216
|
+
@session.find(:css, 'h1', text: 'FooBar').click
|
182
217
|
@session.fill_in('with_change_event', with: 'some value')
|
183
218
|
# click outside the field to trigger the change event
|
184
|
-
@session.find(:css, '
|
219
|
+
@session.find(:css, 'h1', text: 'FooBar').click
|
185
220
|
expect(@session.find(:css, '.change_event_triggered', match: :one)).to have_text 'some value'
|
186
221
|
end
|
187
222
|
|
@@ -189,7 +224,7 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
189
224
|
@session.visit('/with_js')
|
190
225
|
@session.fill_in('with_change_event', with: '')
|
191
226
|
# click outside the field to trigger the change event
|
192
|
-
@session.find(:css, '
|
227
|
+
@session.find(:css, 'h1', text: 'FooBar').click
|
193
228
|
expect(@session).to have_selector(:css, '.change_event_triggered', match: :one)
|
194
229
|
end
|
195
230
|
end
|
@@ -200,7 +235,7 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
200
235
|
after { Capybara.ignore_hidden_elements = false }
|
201
236
|
|
202
237
|
it 'should not find a hidden field' do
|
203
|
-
msg =
|
238
|
+
msg = /Unable to find visible field "Super Secret"/
|
204
239
|
expect do
|
205
240
|
@session.fill_in('Super Secret', with: '777')
|
206
241
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
@@ -209,7 +244,7 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
209
244
|
|
210
245
|
context "with a locator that doesn't exist" do
|
211
246
|
it 'should raise an error' do
|
212
|
-
msg =
|
247
|
+
msg = /Unable to find field "does not exist"/
|
213
248
|
expect do
|
214
249
|
@session.fill_in('does not exist', with: 'Blah blah')
|
215
250
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
@@ -242,4 +277,10 @@ Capybara::SpecHelper.spec '#fill_in' do
|
|
242
277
|
el = @session.find(:fillable_field, 'form_first_name')
|
243
278
|
expect(@session.fill_in('form_first_name', with: 'Harry')).to eq el
|
244
279
|
end
|
280
|
+
|
281
|
+
it 'should warn if passed what looks like a CSS id selector' do
|
282
|
+
expect do
|
283
|
+
@session.fill_in('#form_first_name', with: 'Harry')
|
284
|
+
end.to raise_error(/you may be passing a CSS selector or XPath expression rather than a locator/)
|
285
|
+
end
|
245
286
|
end
|
@@ -102,7 +102,7 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
102
102
|
|
103
103
|
context 'with no locator' do
|
104
104
|
it 'should use options to find the field' do
|
105
|
-
expect(@session.find_field(with: 'dog')['id']).to eq 'form_pets_dog'
|
105
|
+
expect(@session.find_field(type: 'checkbox', with: 'dog')['id']).to eq 'form_pets_dog'
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -92,6 +92,12 @@ Capybara::SpecHelper.spec '#find' do
|
|
92
92
|
expect(@session.find(:css, '#\31 escape\.me').text).to eq('needs escaping')
|
93
93
|
expect(@session.find(:css, '.\32 escape').text).to eq('needs escaping')
|
94
94
|
end
|
95
|
+
|
96
|
+
it 'should not warn about locator' do
|
97
|
+
expect { @session.find(:css, '#not_on_page') }.to raise_error Capybara::ElementNotFound do |e|
|
98
|
+
expect(e.message).not_to match(/you may be passing a CSS selector or XPath expression/)
|
99
|
+
end
|
100
|
+
end
|
95
101
|
end
|
96
102
|
|
97
103
|
context 'with xpath selectors' do
|
@@ -99,6 +105,11 @@ Capybara::SpecHelper.spec '#find' do
|
|
99
105
|
expect(@session.find(:xpath, '//h1').text).to eq('This is a test')
|
100
106
|
expect(@session.find(:xpath, "//input[@id='test_field']").value).to eq('monkey')
|
101
107
|
end
|
108
|
+
|
109
|
+
it 'should warn if passed a non-valid locator type' do
|
110
|
+
expect { @session.find(:xpath, 123) }.to raise_error(Exception) # The exact error is not yet well defined
|
111
|
+
.and output(/must respond to to_xpath or be an instance of String/).to_stderr
|
112
|
+
end
|
102
113
|
end
|
103
114
|
|
104
115
|
context 'with custom selector' do
|
@@ -224,7 +235,7 @@ Capybara::SpecHelper.spec '#find' do
|
|
224
235
|
|
225
236
|
it 'should accept an XPath instance' do
|
226
237
|
@session.visit('/form')
|
227
|
-
@xpath = Capybara::Selector.
|
238
|
+
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('First Name')
|
228
239
|
expect(@xpath).to be_a(::XPath::Union)
|
229
240
|
expect(@session.find(@xpath).value).to eq('John')
|
230
241
|
end
|
@@ -252,9 +263,8 @@ Capybara::SpecHelper.spec '#find' do
|
|
252
263
|
end
|
253
264
|
|
254
265
|
it 'warns when the option has no effect' do
|
255
|
-
|
256
|
-
|
257
|
-
@session.find(:css, '#test_field', exact: true)
|
266
|
+
expect { @session.find(:css, '#test_field', exact: true) }.to \
|
267
|
+
output(/^The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect/).to_stderr
|
258
268
|
end
|
259
269
|
end
|
260
270
|
|
@@ -265,14 +275,17 @@ Capybara::SpecHelper.spec '#find' do
|
|
265
275
|
@session.find(:css, '.multiple', match: :one)
|
266
276
|
end.to raise_error(Capybara::Ambiguous)
|
267
277
|
end
|
278
|
+
|
268
279
|
it 'raises an error even if there the match is exact and the others are inexact' do
|
269
280
|
expect do
|
270
281
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], exact: false, match: :one)
|
271
282
|
end.to raise_error(Capybara::Ambiguous)
|
272
283
|
end
|
284
|
+
|
273
285
|
it 'returns the element if there is only one' do
|
274
286
|
expect(@session.find(:css, '.singular', match: :one).text).to eq('singular')
|
275
287
|
end
|
288
|
+
|
276
289
|
it 'raises an error if there is no match' do
|
277
290
|
expect do
|
278
291
|
@session.find(:css, '.does-not-exist', match: :one)
|
@@ -284,6 +297,7 @@ Capybara::SpecHelper.spec '#find' do
|
|
284
297
|
it 'returns the first matched element' do
|
285
298
|
expect(@session.find(:css, '.multiple', match: :first).text).to eq('multiple one')
|
286
299
|
end
|
300
|
+
|
287
301
|
it 'raises an error if there is no match' do
|
288
302
|
expect do
|
289
303
|
@session.find(:css, '.does-not-exist', match: :first)
|
@@ -298,19 +312,23 @@ Capybara::SpecHelper.spec '#find' do
|
|
298
312
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :smart, exact: false)
|
299
313
|
end.to raise_error(Capybara::Ambiguous)
|
300
314
|
end
|
315
|
+
|
301
316
|
it 'finds a single exact match when there also are inexact matches' do
|
302
317
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :smart, exact: false)
|
303
318
|
expect(result.text).to eq('almost singular')
|
304
319
|
end
|
320
|
+
|
305
321
|
it 'raises an error when there are multiple inexact matches' do
|
306
322
|
expect do
|
307
323
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :smart, exact: false)
|
308
324
|
end.to raise_error(Capybara::Ambiguous)
|
309
325
|
end
|
326
|
+
|
310
327
|
it 'finds a single inexact match' do
|
311
328
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :smart, exact: false)
|
312
329
|
expect(result.text).to eq('almost singular but not quite')
|
313
330
|
end
|
331
|
+
|
314
332
|
it 'raises an error if there is no match' do
|
315
333
|
expect do
|
316
334
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :smart, exact: false)
|
@@ -324,20 +342,24 @@ Capybara::SpecHelper.spec '#find' do
|
|
324
342
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :smart, exact: true)
|
325
343
|
end.to raise_error(Capybara::Ambiguous)
|
326
344
|
end
|
345
|
+
|
327
346
|
it 'finds a single exact match when there also are inexact matches' do
|
328
347
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :smart, exact: true)
|
329
348
|
expect(result.text).to eq('almost singular')
|
330
349
|
end
|
350
|
+
|
331
351
|
it 'raises an error when there are multiple inexact matches' do
|
332
352
|
expect do
|
333
353
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :smart, exact: true)
|
334
354
|
end.to raise_error(Capybara::ElementNotFound)
|
335
355
|
end
|
356
|
+
|
336
357
|
it 'raises an error when there is a single inexact matches' do
|
337
358
|
expect do
|
338
359
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :smart, exact: true)
|
339
360
|
end.to raise_error(Capybara::ElementNotFound)
|
340
361
|
end
|
362
|
+
|
341
363
|
it 'raises an error if there is no match' do
|
342
364
|
expect do
|
343
365
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :smart, exact: true)
|
@@ -352,18 +374,22 @@ Capybara::SpecHelper.spec '#find' do
|
|
352
374
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :prefer_exact, exact: false)
|
353
375
|
expect(result.text).to eq('multiple one')
|
354
376
|
end
|
377
|
+
|
355
378
|
it 'finds a single exact match when there also are inexact matches' do
|
356
379
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :prefer_exact, exact: false)
|
357
380
|
expect(result.text).to eq('almost singular')
|
358
381
|
end
|
382
|
+
|
359
383
|
it 'picks the first one when there are multiple inexact matches' do
|
360
384
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :prefer_exact, exact: false)
|
361
385
|
expect(result.text).to eq('almost singular but not quite')
|
362
386
|
end
|
387
|
+
|
363
388
|
it 'finds a single inexact match' do
|
364
389
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :prefer_exact, exact: false)
|
365
390
|
expect(result.text).to eq('almost singular but not quite')
|
366
391
|
end
|
392
|
+
|
367
393
|
it 'raises an error if there is no match' do
|
368
394
|
expect do
|
369
395
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :prefer_exact, exact: false)
|
@@ -376,20 +402,24 @@ Capybara::SpecHelper.spec '#find' do
|
|
376
402
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('multiple')], match: :prefer_exact, exact: true)
|
377
403
|
expect(result.text).to eq('multiple one')
|
378
404
|
end
|
405
|
+
|
379
406
|
it 'finds a single exact match when there also are inexact matches' do
|
380
407
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular')], match: :prefer_exact, exact: true)
|
381
408
|
expect(result.text).to eq('almost singular')
|
382
409
|
end
|
410
|
+
|
383
411
|
it 'raises an error if there are multiple inexact matches' do
|
384
412
|
expect do
|
385
413
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singul')], match: :prefer_exact, exact: true)
|
386
414
|
end.to raise_error(Capybara::ElementNotFound)
|
387
415
|
end
|
416
|
+
|
388
417
|
it 'raises an error if there is a single inexact match' do
|
389
418
|
expect do
|
390
419
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('almost_singular but')], match: :prefer_exact, exact: true)
|
391
420
|
end.to raise_error(Capybara::ElementNotFound)
|
392
421
|
end
|
422
|
+
|
393
423
|
it 'raises an error if there is no match' do
|
394
424
|
expect do
|
395
425
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is('does-not-exist')], match: :prefer_exact, exact: true)
|
@@ -418,6 +448,41 @@ Capybara::SpecHelper.spec '#find' do
|
|
418
448
|
expect(@session.find(:css, 'input', &:disabled?)[:name]).to eq('disabled_text')
|
419
449
|
end
|
420
450
|
|
451
|
+
context 'with spatial filters', requires: [:spatial] do
|
452
|
+
before do
|
453
|
+
@session.visit('/spatial')
|
454
|
+
end
|
455
|
+
|
456
|
+
let :center do
|
457
|
+
@session.find(:css, 'div.center')
|
458
|
+
end
|
459
|
+
|
460
|
+
it 'should find an element above another element' do
|
461
|
+
expect(@session.find(:css, 'div:not(.corner)', above: center).text).to eq('2')
|
462
|
+
end
|
463
|
+
|
464
|
+
it 'should find an element below another element' do
|
465
|
+
expect(@session.find(:css, 'div:not(.corner):not(.footer)', below: center).text).to eq('8')
|
466
|
+
end
|
467
|
+
|
468
|
+
it 'should find an element left of another element' do
|
469
|
+
expect(@session.find(:css, 'div:not(.corner)', left_of: center).text).to eq('4')
|
470
|
+
end
|
471
|
+
|
472
|
+
it 'should find an element right of another element' do
|
473
|
+
expect(@session.find(:css, 'div:not(.corner)', right_of: center).text).to eq('6')
|
474
|
+
end
|
475
|
+
|
476
|
+
it 'should combine spatial filters' do
|
477
|
+
expect(@session.find(:css, 'div', left_of: center, above: center).text).to eq('1')
|
478
|
+
expect(@session.find(:css, 'div', right_of: center, below: center).text).to eq('9')
|
479
|
+
end
|
480
|
+
|
481
|
+
it 'should find an element "near" another element' do
|
482
|
+
expect(@session.find(:css, 'div.distance', near: center).text).to eq('2')
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
421
486
|
context 'within a scope' do
|
422
487
|
before do
|
423
488
|
@session.visit('/with_scope')
|
@@ -457,5 +522,10 @@ Capybara::SpecHelper.spec '#find' do
|
|
457
522
|
Capybara.test_id = 'data-other-test-id'
|
458
523
|
expect(@session.find(:field, 'test_id')[:id]).to eq 'normal'
|
459
524
|
end
|
525
|
+
|
526
|
+
it 'should find a link with the test_id' do
|
527
|
+
Capybara.test_id = 'data-test-id'
|
528
|
+
expect(@session.find(:link, 'test-foo')[:id]).to eq 'foo'
|
529
|
+
end
|
460
530
|
end
|
461
531
|
end
|
@@ -24,7 +24,7 @@ Capybara::SpecHelper.spec '#first' do
|
|
24
24
|
|
25
25
|
it 'should accept an XPath instance' do
|
26
26
|
@session.visit('/form')
|
27
|
-
@xpath = Capybara::Selector.
|
27
|
+
@xpath = Capybara::Selector.new(:fillable_field, config: {}, format: :xpath).call('First Name')
|
28
28
|
expect(@xpath).to be_a(::XPath::Union)
|
29
29
|
expect(@session.first(@xpath).value).to eq('John')
|
30
30
|
end
|
@@ -53,8 +53,20 @@ Capybara::SpecHelper.spec '#switch_to_frame', requires: [:frames] do
|
|
53
53
|
@session.switch_to_frame frame
|
54
54
|
frame = @session.find(:frame, 'childFrame')
|
55
55
|
@session.switch_to_frame frame
|
56
|
+
@session.click_link 'Close Window Now'
|
57
|
+
@session.switch_to_frame :parent # Go back to parentFrame
|
58
|
+
expect(@session).to have_selector(:css, 'body#parentBody')
|
59
|
+
expect(@session).not_to have_selector(:css, '#childFrame')
|
60
|
+
@session.switch_to_frame :parent # Go back to top
|
61
|
+
end
|
56
62
|
|
57
|
-
|
63
|
+
it 'works if the frame is closed with a slight delay', requires: %i[frames js] do
|
64
|
+
frame = @session.find(:frame, 'parentFrame')
|
65
|
+
@session.switch_to_frame frame
|
66
|
+
frame = @session.find(:frame, 'childFrame')
|
67
|
+
@session.switch_to_frame frame
|
68
|
+
@session.click_link 'Close Window Soon'
|
69
|
+
sleep 1
|
58
70
|
@session.switch_to_frame :parent # Go back to parentFrame
|
59
71
|
expect(@session).to have_selector(:css, 'body#parentBody')
|
60
72
|
expect(@session).not_to have_selector(:css, '#childFrame')
|
@@ -92,7 +92,18 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
|
92
92
|
it 'works if the frame is closed', requires: %i[frames js] do
|
93
93
|
@session.within_frame 'parentFrame' do
|
94
94
|
@session.within_frame 'childFrame' do
|
95
|
-
@session.click_link 'Close Window'
|
95
|
+
@session.click_link 'Close Window Now'
|
96
|
+
end
|
97
|
+
expect(@session).to have_selector(:css, 'body#parentBody')
|
98
|
+
expect(@session).not_to have_selector(:css, '#childFrame')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'works if the frame is closed with a slight delay', requires: %i[frames js] do
|
103
|
+
@session.within_frame 'parentFrame' do
|
104
|
+
@session.within_frame 'childFrame' do
|
105
|
+
@session.click_link 'Close Window Soon'
|
106
|
+
sleep 1
|
96
107
|
end
|
97
108
|
expect(@session).to have_selector(:css, 'body#parentBody')
|
98
109
|
expect(@session).not_to have_selector(:css, '#childFrame')
|