capybara 2.7.0 → 3.35.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.yardopts +1 -0
- data/History.md +1147 -11
- data/License.txt +1 -1
- data/README.md +252 -131
- data/lib/capybara/config.rb +92 -0
- data/lib/capybara/cucumber.rb +3 -3
- data/lib/capybara/driver/base.rb +52 -21
- data/lib/capybara/driver/node.rb +48 -14
- data/lib/capybara/dsl.rb +16 -9
- data/lib/capybara/helpers.rb +72 -81
- data/lib/capybara/minitest/spec.rb +267 -0
- data/lib/capybara/minitest.rb +385 -0
- data/lib/capybara/node/actions.rb +337 -89
- data/lib/capybara/node/base.rb +50 -32
- data/lib/capybara/node/document.rb +19 -3
- data/lib/capybara/node/document_matchers.rb +22 -24
- data/lib/capybara/node/element.rb +388 -125
- data/lib/capybara/node/finders.rb +231 -121
- data/lib/capybara/node/matchers.rb +503 -217
- data/lib/capybara/node/simple.rb +64 -27
- data/lib/capybara/queries/ancestor_query.rb +27 -0
- data/lib/capybara/queries/base_query.rb +87 -11
- data/lib/capybara/queries/current_path_query.rb +24 -24
- data/lib/capybara/queries/match_query.rb +15 -10
- data/lib/capybara/queries/selector_query.rb +675 -81
- data/lib/capybara/queries/sibling_query.rb +26 -0
- data/lib/capybara/queries/style_query.rb +45 -0
- data/lib/capybara/queries/text_query.rb +88 -20
- data/lib/capybara/queries/title_query.rb +9 -11
- data/lib/capybara/rack_test/browser.rb +63 -39
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +26 -16
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +73 -58
- data/lib/capybara/rack_test/node.rb +187 -67
- data/lib/capybara/rails.rb +4 -8
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +42 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
- data/lib/capybara/registrations/servers.rb +45 -0
- data/lib/capybara/result.rb +142 -14
- data/lib/capybara/rspec/features.rb +17 -42
- data/lib/capybara/rspec/matcher_proxies.rb +82 -0
- data/lib/capybara/rspec/matchers/base.rb +111 -0
- data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
- data/lib/capybara/rspec/matchers/compound.rb +88 -0
- data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
- data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
- data/lib/capybara/rspec/matchers/have_selector.rb +77 -0
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +33 -0
- data/lib/capybara/rspec/matchers/have_title.rb +29 -0
- data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
- data/lib/capybara/rspec/matchers/match_style.rb +43 -0
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +143 -244
- data/lib/capybara/rspec.rb +10 -12
- data/lib/capybara/selector/builders/css_builder.rb +84 -0
- data/lib/capybara/selector/builders/xpath_builder.rb +71 -0
- data/lib/capybara/selector/css.rb +102 -0
- data/lib/capybara/selector/definition/button.rb +63 -0
- data/lib/capybara/selector/definition/checkbox.rb +26 -0
- data/lib/capybara/selector/definition/css.rb +10 -0
- data/lib/capybara/selector/definition/datalist_input.rb +35 -0
- data/lib/capybara/selector/definition/datalist_option.rb +25 -0
- data/lib/capybara/selector/definition/element.rb +28 -0
- data/lib/capybara/selector/definition/field.rb +40 -0
- data/lib/capybara/selector/definition/fieldset.rb +14 -0
- data/lib/capybara/selector/definition/file_field.rb +13 -0
- data/lib/capybara/selector/definition/fillable_field.rb +33 -0
- data/lib/capybara/selector/definition/frame.rb +17 -0
- data/lib/capybara/selector/definition/id.rb +6 -0
- data/lib/capybara/selector/definition/label.rb +62 -0
- data/lib/capybara/selector/definition/link.rb +54 -0
- data/lib/capybara/selector/definition/link_or_button.rb +16 -0
- data/lib/capybara/selector/definition/option.rb +27 -0
- data/lib/capybara/selector/definition/radio_button.rb +27 -0
- data/lib/capybara/selector/definition/select.rb +81 -0
- data/lib/capybara/selector/definition/table.rb +109 -0
- data/lib/capybara/selector/definition/table_row.rb +21 -0
- data/lib/capybara/selector/definition/xpath.rb +5 -0
- data/lib/capybara/selector/definition.rb +278 -0
- data/lib/capybara/selector/filter.rb +3 -46
- data/lib/capybara/selector/filter_set.rb +124 -0
- data/lib/capybara/selector/filters/base.rb +77 -0
- data/lib/capybara/selector/filters/expression_filter.rb +22 -0
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +31 -0
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +155 -0
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +232 -369
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
- data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
- data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
- data/lib/capybara/selenium/driver.rb +380 -142
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +117 -0
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +89 -0
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +110 -0
- data/lib/capybara/selenium/extensions/html5_drag.rb +228 -0
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +76 -0
- data/lib/capybara/selenium/logger_suppressor.rb +40 -0
- data/lib/capybara/selenium/node.rb +528 -97
- data/lib/capybara/selenium/nodes/chrome_node.rb +137 -0
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +136 -0
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +18 -0
- data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
- data/lib/capybara/selenium/patches/logs.rb +45 -0
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +9 -0
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +63 -0
- data/lib/capybara/server/checker.rb +44 -0
- data/lib/capybara/server/middleware.rb +71 -0
- data/lib/capybara/server.rb +74 -71
- data/lib/capybara/session/config.rb +126 -0
- data/lib/capybara/session/matchers.rb +44 -27
- data/lib/capybara/session.rb +500 -297
- data/lib/capybara/spec/fixtures/no_extension +1 -0
- data/lib/capybara/spec/public/jquery.js +5 -5
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +168 -14
- data/lib/capybara/spec/session/accept_alert_spec.rb +37 -14
- data/lib/capybara/spec/session/accept_confirm_spec.rb +7 -6
- data/lib/capybara/spec/session/accept_prompt_spec.rb +38 -10
- data/lib/capybara/spec/session/all_spec.rb +179 -59
- data/lib/capybara/spec/session/ancestor_spec.rb +88 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +140 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +75 -0
- data/lib/capybara/spec/session/assert_selector_spec.rb +143 -0
- data/lib/capybara/spec/session/assert_style_spec.rb +26 -0
- data/lib/capybara/spec/session/assert_text_spec.rb +258 -0
- data/lib/capybara/spec/session/assert_title_spec.rb +93 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +154 -48
- data/lib/capybara/spec/session/body_spec.rb +12 -13
- data/lib/capybara/spec/session/check_spec.rb +168 -41
- data/lib/capybara/spec/session/choose_spec.rb +75 -23
- data/lib/capybara/spec/session/click_button_spec.rb +243 -175
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +57 -32
- data/lib/capybara/spec/session/click_link_spec.rb +100 -53
- data/lib/capybara/spec/session/current_scope_spec.rb +11 -10
- data/lib/capybara/spec/session/current_url_spec.rb +61 -35
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +7 -7
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +5 -4
- data/lib/capybara/spec/session/element/{assert_match_selector.rb → assert_match_selector_spec.rb} +13 -6
- data/lib/capybara/spec/session/element/match_css_spec.rb +21 -7
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +9 -7
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +91 -34
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +45 -3
- data/lib/capybara/spec/session/execute_script_spec.rb +24 -4
- data/lib/capybara/spec/session/fill_in_spec.rb +166 -64
- data/lib/capybara/spec/session/find_button_spec.rb +37 -18
- data/lib/capybara/spec/session/find_by_id_spec.rb +10 -9
- data/lib/capybara/spec/session/find_field_spec.rb +57 -34
- data/lib/capybara/spec/session/find_link_spec.rb +47 -10
- data/lib/capybara/spec/session/find_spec.rb +290 -144
- data/lib/capybara/spec/session/first_spec.rb +91 -48
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +116 -0
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +112 -0
- data/lib/capybara/spec/session/go_back_spec.rb +3 -2
- data/lib/capybara/spec/session/go_forward_spec.rb +3 -2
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +25 -0
- data/lib/capybara/spec/session/has_button_spec.rb +76 -19
- data/lib/capybara/spec/session/has_css_spec.rb +277 -131
- data/lib/capybara/spec/session/has_current_path_spec.rb +98 -26
- data/lib/capybara/spec/session/has_field_spec.rb +177 -107
- data/lib/capybara/spec/session/has_link_spec.rb +13 -12
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +78 -0
- data/lib/capybara/spec/session/has_select_spec.rb +191 -95
- data/lib/capybara/spec/session/has_selector_spec.rb +128 -64
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +172 -5
- data/lib/capybara/spec/session/has_text_spec.rb +126 -60
- data/lib/capybara/spec/session/has_title_spec.rb +35 -12
- data/lib/capybara/spec/session/has_xpath_spec.rb +74 -53
- data/lib/capybara/spec/session/{headers.rb → headers_spec.rb} +3 -2
- data/lib/capybara/spec/session/html_spec.rb +14 -6
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +1028 -131
- data/lib/capybara/spec/session/node_wrapper_spec.rb +39 -0
- data/lib/capybara/spec/session/refresh_spec.rb +34 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +75 -34
- data/lib/capybara/spec/session/{response_code.rb → response_code_spec.rb} +2 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +3 -2
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +11 -15
- data/lib/capybara/spec/session/save_page_spec.rb +42 -55
- data/lib/capybara/spec/session/save_screenshot_spec.rb +16 -14
- data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/scroll_spec.rb +117 -0
- data/lib/capybara/spec/session/select_spec.rb +112 -85
- data/lib/capybara/spec/session/selectors_spec.rb +71 -8
- data/lib/capybara/spec/session/sibling_spec.rb +52 -0
- data/lib/capybara/spec/session/text_spec.rb +38 -23
- data/lib/capybara/spec/session/title_spec.rb +17 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +71 -12
- data/lib/capybara/spec/session/unselect_spec.rb +44 -43
- data/lib/capybara/spec/session/visit_spec.rb +99 -32
- data/lib/capybara/spec/session/window/become_closed_spec.rb +33 -29
- data/lib/capybara/spec/session/window/current_window_spec.rb +5 -3
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +5 -3
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +39 -30
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +17 -10
- data/lib/capybara/spec/session/window/window_spec.rb +121 -73
- data/lib/capybara/spec/session/window/windows_spec.rb +12 -10
- data/lib/capybara/spec/session/window/within_window_spec.rb +52 -82
- data/lib/capybara/spec/session/within_spec.rb +76 -43
- data/lib/capybara/spec/spec_helper.rb +67 -33
- data/lib/capybara/spec/test_app.rb +85 -36
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/buttons.erb +1 -1
- data/lib/capybara/spec/views/fieldsets.erb +1 -1
- data/lib/capybara/spec/views/form.erb +227 -20
- data/lib/capybara/spec/views/frame_child.erb +10 -2
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +2 -2
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/header_links.erb +1 -1
- data/lib/capybara/spec/views/host_links.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +47 -0
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/path.erb +1 -1
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/postback.erb +1 -1
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/scroll.erb +20 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/tables.erb +69 -2
- data/lib/capybara/spec/views/with_animation.erb +82 -0
- data/lib/capybara/spec/views/with_base_tag.erb +1 -1
- data/lib/capybara/spec/views/with_count.erb +1 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
- data/lib/capybara/spec/views/with_hover.erb +7 -1
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +100 -10
- data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
- data/lib/capybara/spec/views/with_html_entities.erb +1 -1
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +49 -3
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_namespace.erb +20 -0
- data/lib/capybara/spec/views/with_scope.erb +1 -1
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_simple_html.erb +1 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/spec/views/with_title.erb +1 -1
- data/lib/capybara/spec/views/with_unload_alert.erb +3 -1
- data/lib/capybara/spec/views/with_windows.erb +7 -1
- data/lib/capybara/spec/views/within_frames.erb +6 -3
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +39 -21
- data/lib/capybara.rb +208 -186
- data/spec/basic_node_spec.rb +52 -39
- data/spec/capybara_spec.rb +72 -50
- data/spec/css_builder_spec.rb +101 -0
- data/spec/css_splitter_spec.rb +38 -0
- data/spec/dsl_spec.rb +81 -61
- data/spec/filter_set_spec.rb +46 -0
- data/spec/fixtures/capybara.csv +1 -0
- data/spec/fixtures/certificate.pem +25 -0
- data/spec/fixtures/key.pem +27 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +7 -3
- data/spec/fixtures/selenium_driver_rspec_success.rb +7 -3
- data/spec/minitest_spec.rb +164 -0
- data/spec/minitest_spec_spec.rb +162 -0
- data/spec/per_session_config_spec.rb +68 -0
- data/spec/rack_test_spec.rb +189 -96
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +143 -13
- data/spec/rspec/features_spec.rb +38 -32
- data/spec/rspec/scenarios_spec.rb +9 -7
- data/spec/rspec/shared_spec_matchers.rb +959 -0
- data/spec/rspec/views_spec.rb +9 -3
- data/spec/rspec_matchers_spec.rb +62 -0
- data/spec/rspec_spec.rb +127 -30
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +458 -37
- data/spec/selenium_spec_chrome.rb +196 -9
- data/spec/selenium_spec_chrome_remote.rb +100 -0
- data/spec/selenium_spec_edge.rb +47 -0
- data/spec/selenium_spec_firefox.rb +210 -0
- data/spec/selenium_spec_firefox_remote.rb +80 -0
- data/spec/selenium_spec_ie.rb +150 -0
- data/spec/selenium_spec_safari.rb +148 -0
- data/spec/server_spec.rb +200 -101
- data/spec/session_spec.rb +91 -0
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +558 -0
- data/spec/spec_helper.rb +94 -2
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +420 -60
- data/lib/capybara/query.rb +0 -7
- data/lib/capybara/spec/session/assert_current_path.rb +0 -60
- data/lib/capybara/spec/session/assert_selector.rb +0 -148
- data/lib/capybara/spec/session/assert_text.rb +0 -196
- data/lib/capybara/spec/session/assert_title.rb +0 -70
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +0 -53
- data/spec/rspec/matchers_spec.rb +0 -827
- data/spec/selenium_spec.rb +0 -151
@@ -1,69 +1,121 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#choose' do
|
3
4
|
before do
|
4
5
|
@session.visit('/form')
|
5
6
|
end
|
6
7
|
|
7
|
-
it
|
8
|
-
@session.choose(
|
8
|
+
it 'should choose a radio button by id' do
|
9
|
+
@session.choose('gender_male')
|
9
10
|
@session.click_button('awesome')
|
10
11
|
expect(extract_results(@session)['gender']).to eq('male')
|
11
12
|
end
|
12
13
|
|
13
|
-
it
|
14
|
-
@session.choose(
|
14
|
+
it 'should choose a radio button by label' do
|
15
|
+
@session.choose('Both')
|
15
16
|
@session.click_button('awesome')
|
16
17
|
expect(extract_results(@session)['gender']).to eq('both')
|
17
18
|
end
|
18
19
|
|
19
|
-
it
|
20
|
-
@session.choose(
|
21
|
-
@session.click_button(
|
20
|
+
it 'should work without a locator string' do
|
21
|
+
@session.choose(id: 'gender_male')
|
22
|
+
@session.click_button('awesome')
|
23
|
+
expect(extract_results(@session)['gender']).to eq('male')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should be able to choose self when no locator string specified' do
|
27
|
+
rb = @session.find(:id, 'gender_male')
|
28
|
+
rb.choose
|
29
|
+
@session.click_button('awesome')
|
30
|
+
expect(extract_results(@session)['gender']).to eq('male')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'casts to string' do
|
34
|
+
@session.choose('Both')
|
35
|
+
@session.click_button(:awesome)
|
22
36
|
expect(extract_results(@session)['gender']).to eq('both')
|
23
37
|
end
|
24
38
|
|
25
39
|
context "with a locator that doesn't exist" do
|
26
|
-
it
|
27
|
-
msg =
|
40
|
+
it 'should raise an error' do
|
41
|
+
msg = /Unable to find radio button "does not exist"/
|
28
42
|
expect do
|
29
43
|
@session.choose('does not exist')
|
30
44
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
34
|
-
context
|
35
|
-
it
|
48
|
+
context 'with a disabled radio button' do
|
49
|
+
it 'should raise an error' do
|
36
50
|
expect do
|
37
51
|
@session.choose('Disabled Radio')
|
38
52
|
end.to raise_error(Capybara::ElementNotFound)
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
42
|
-
context
|
43
|
-
it
|
44
|
-
@session.choose(
|
56
|
+
context 'with :exact option' do
|
57
|
+
it 'should accept partial matches when false' do
|
58
|
+
@session.choose('Mal', exact: false)
|
45
59
|
@session.click_button('awesome')
|
46
60
|
expect(extract_results(@session)['gender']).to eq('male')
|
47
61
|
end
|
48
62
|
|
49
|
-
it
|
63
|
+
it 'should not accept partial matches when true' do
|
50
64
|
expect do
|
51
|
-
@session.choose(
|
65
|
+
@session.choose('Mal', exact: true)
|
52
66
|
end.to raise_error(Capybara::ElementNotFound)
|
53
67
|
end
|
54
68
|
end
|
55
69
|
|
56
|
-
context
|
57
|
-
it
|
58
|
-
@session.choose('form[gender]', :
|
70
|
+
context 'with `option` option' do
|
71
|
+
it 'can check radio buttons by their value' do
|
72
|
+
@session.choose('form[gender]', option: 'male')
|
73
|
+
@session.click_button('awesome')
|
74
|
+
expect(extract_results(@session)['gender']).to eq('male')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should alias `:with` option' do
|
78
|
+
@session.choose('form[gender]', with: 'male')
|
59
79
|
@session.click_button('awesome')
|
60
|
-
expect(extract_results(@session)['gender']).to eq(
|
80
|
+
expect(extract_results(@session)['gender']).to eq('male')
|
61
81
|
end
|
62
82
|
|
63
|
-
it
|
83
|
+
it 'should raise an error if option not found' do
|
64
84
|
expect do
|
65
|
-
@session.choose('form[gender]', :
|
85
|
+
@session.choose('form[gender]', option: 'hermaphrodite')
|
66
86
|
end.to raise_error(Capybara::ElementNotFound)
|
67
87
|
end
|
68
88
|
end
|
89
|
+
|
90
|
+
context 'with hidden radio buttons' do
|
91
|
+
context 'with Capybara.automatic_label_click == true' do
|
92
|
+
around do |spec|
|
93
|
+
old_click_label, Capybara.automatic_label_click = Capybara.automatic_label_click, true
|
94
|
+
spec.run
|
95
|
+
Capybara.automatic_label_click = old_click_label
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should select by clicking the label if available' do
|
99
|
+
@session.choose('party_democrat')
|
100
|
+
@session.click_button('awesome')
|
101
|
+
expect(extract_results(@session)['party']).to eq('democrat')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should select self by clicking the label if no locator specified' do
|
105
|
+
cb = @session.find(:id, 'party_democrat', visible: :hidden)
|
106
|
+
cb.choose
|
107
|
+
@session.click_button('awesome')
|
108
|
+
expect(extract_results(@session)['party']).to eq('democrat')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should raise error if not allowed to click label' do
|
112
|
+
expect { @session.choose('party_democrat', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, /Unable to find visible radio button "party_democrat"/)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should return the chosen radio button' do
|
118
|
+
el = @session.find(:radio_button, 'gender_male')
|
119
|
+
expect(@session.choose('gender_male')).to eq el
|
120
|
+
end
|
69
121
|
end
|
@@ -1,448 +1,516 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#click_button' do
|
3
4
|
before do
|
4
5
|
@session.visit('/form')
|
5
6
|
end
|
6
7
|
|
7
|
-
it
|
8
|
+
it 'should wait for asynchronous load', requires: [:js] do
|
8
9
|
@session.visit('/with_js')
|
9
|
-
@session.
|
10
|
-
|
10
|
+
@session.using_wait_time(1.5) do
|
11
|
+
@session.click_link('Click me')
|
12
|
+
@session.click_button('New Here')
|
13
|
+
end
|
11
14
|
end
|
12
15
|
|
13
|
-
it
|
16
|
+
it 'casts to string' do
|
14
17
|
@session.click_button(:'Relative Action')
|
15
18
|
expect(extract_results(@session)['relative']).to eq('Relative Action')
|
16
19
|
expect(@session.current_path).to eq('/relative')
|
17
20
|
end
|
18
21
|
|
19
|
-
context
|
20
|
-
it
|
22
|
+
context 'with multiple values with the same name' do
|
23
|
+
it 'should use the latest given value' do
|
21
24
|
@session.check('Terms of Use')
|
22
25
|
@session.click_button('awesome')
|
23
26
|
expect(extract_results(@session)['terms_of_use']).to eq('1')
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
context
|
28
|
-
it
|
30
|
+
context 'with a form that has a relative url as an action' do
|
31
|
+
it 'should post to the correct url' do
|
29
32
|
@session.click_button('Relative Action')
|
30
33
|
expect(extract_results(@session)['relative']).to eq('Relative Action')
|
31
34
|
expect(@session.current_path).to eq('/relative')
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
context
|
36
|
-
it
|
38
|
+
context 'with a form that has no action specified' do
|
39
|
+
it 'should post to the correct url' do
|
37
40
|
@session.click_button('No Action')
|
38
41
|
expect(extract_results(@session)['no_action']).to eq('No Action')
|
39
42
|
expect(@session.current_path).to eq('/form')
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
|
-
context
|
44
|
-
context
|
46
|
+
context 'with value given on a submit button' do
|
47
|
+
context 'on a form with HTML5 fields' do
|
48
|
+
let(:results) { extract_results(@session) }
|
49
|
+
|
45
50
|
before do
|
46
51
|
@session.click_button('html5_submit')
|
47
|
-
@results = extract_results(@session)
|
48
52
|
end
|
49
53
|
|
50
|
-
it
|
51
|
-
expect(
|
54
|
+
it 'should serialise and submit search fields' do
|
55
|
+
expect(results['html5_search']).to eq('what are you looking for')
|
52
56
|
end
|
53
57
|
|
54
|
-
it
|
55
|
-
expect(
|
58
|
+
it 'should serialise and submit email fields' do
|
59
|
+
expect(results['html5_email']).to eq('person@email.com')
|
56
60
|
end
|
57
61
|
|
58
|
-
it
|
59
|
-
expect(
|
62
|
+
it 'should serialise and submit url fields' do
|
63
|
+
expect(results['html5_url']).to eq('http://www.example.com')
|
60
64
|
end
|
61
65
|
|
62
|
-
it
|
63
|
-
expect(
|
66
|
+
it 'should serialise and submit tel fields' do
|
67
|
+
expect(results['html5_tel']).to eq('911')
|
64
68
|
end
|
65
69
|
|
66
|
-
it
|
67
|
-
expect(
|
70
|
+
it 'should serialise and submit color fields' do
|
71
|
+
expect(results['html5_color'].upcase).to eq('#FFFFFF')
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
71
|
-
context
|
75
|
+
context 'on an HTML4 form' do
|
76
|
+
let(:results) { extract_results(@session) }
|
77
|
+
|
72
78
|
before do
|
73
79
|
@session.click_button('awesome')
|
74
|
-
@results = extract_results(@session)
|
75
80
|
end
|
76
81
|
|
77
|
-
it
|
78
|
-
expect(
|
82
|
+
it 'should serialize and submit text fields' do
|
83
|
+
expect(results['first_name']).to eq('John')
|
79
84
|
end
|
80
85
|
|
81
|
-
it
|
82
|
-
expect(
|
86
|
+
it 'should escape fields when submitting' do
|
87
|
+
expect(results['phone']).to eq('+1 555 7021')
|
83
88
|
end
|
84
89
|
|
85
|
-
it
|
86
|
-
expect(
|
90
|
+
it 'should serialize and submit password fields' do
|
91
|
+
expect(results['password']).to eq('seeekrit')
|
87
92
|
end
|
88
93
|
|
89
|
-
it
|
90
|
-
expect(
|
94
|
+
it 'should serialize and submit hidden fields' do
|
95
|
+
expect(results['token']).to eq('12345')
|
91
96
|
end
|
92
97
|
|
93
|
-
it
|
94
|
-
expect(
|
98
|
+
it 'should not serialize fields from other forms' do
|
99
|
+
expect(results['middle_name']).to be_nil
|
95
100
|
end
|
96
101
|
|
97
|
-
it
|
98
|
-
expect(
|
99
|
-
expect(
|
102
|
+
it 'should submit the button that was clicked, but not other buttons' do
|
103
|
+
expect(results['awesome']).to eq('awesome')
|
104
|
+
expect(results['crappy']).to be_nil
|
100
105
|
end
|
101
106
|
|
102
|
-
it
|
103
|
-
expect(
|
107
|
+
it 'should serialize radio buttons' do
|
108
|
+
expect(results['gender']).to eq('female')
|
104
109
|
end
|
105
110
|
|
106
111
|
it "should default radio value to 'on' if none specified" do
|
107
|
-
expect(
|
112
|
+
expect(results['valueless_radio']).to eq('on')
|
108
113
|
end
|
109
114
|
|
110
|
-
it
|
111
|
-
expect(
|
112
|
-
expect(
|
115
|
+
it 'should serialize check boxes' do
|
116
|
+
expect(results['pets']).to include('dog', 'hamster')
|
117
|
+
expect(results['pets']).not_to include('cat')
|
113
118
|
end
|
114
119
|
|
115
120
|
it "should default checkbox value to 'on' if none specififed" do
|
116
|
-
expect(
|
121
|
+
expect(results['valueless_checkbox']).to eq('on')
|
117
122
|
end
|
118
123
|
|
119
|
-
it
|
120
|
-
expect(
|
124
|
+
it 'should serialize text areas' do
|
125
|
+
expect(results['description']).to eq('Descriptive text goes here')
|
121
126
|
end
|
122
127
|
|
123
|
-
it
|
124
|
-
expect(
|
128
|
+
it 'should serialize select tag with values' do
|
129
|
+
expect(results['locale']).to eq('en')
|
125
130
|
end
|
126
131
|
|
127
|
-
it
|
128
|
-
expect(
|
132
|
+
it 'should serialize select tag without values' do
|
133
|
+
expect(results['region']).to eq('Norway')
|
129
134
|
end
|
130
135
|
|
131
|
-
it
|
132
|
-
expect(
|
136
|
+
it 'should serialize first option for select tag with no selection' do
|
137
|
+
expect(results['city']).to eq('London')
|
133
138
|
end
|
134
139
|
|
135
|
-
it
|
136
|
-
expect(
|
140
|
+
it 'should not serialize a select tag without options' do
|
141
|
+
expect(results['tendency']).to be_nil
|
137
142
|
end
|
138
143
|
|
139
|
-
it
|
140
|
-
expect(
|
144
|
+
it 'should convert lf to cr/lf in submitted textareas' do
|
145
|
+
expect(results['newline']).to eq("\r\nNew line after and before textarea tag\r\n")
|
141
146
|
end
|
142
147
|
|
143
|
-
it
|
144
|
-
expect(
|
145
|
-
expect(
|
146
|
-
expect(
|
147
|
-
expect(
|
148
|
-
expect(
|
149
|
-
expect(
|
148
|
+
it 'should not submit disabled fields' do
|
149
|
+
expect(results['disabled_text_field']).to be_nil
|
150
|
+
expect(results['disabled_textarea']).to be_nil
|
151
|
+
expect(results['disabled_checkbox']).to be_nil
|
152
|
+
expect(results['disabled_radio']).to be_nil
|
153
|
+
expect(results['disabled_select']).to be_nil
|
154
|
+
expect(results['disabled_file']).to be_nil
|
150
155
|
end
|
151
156
|
end
|
152
157
|
end
|
153
158
|
|
154
|
-
context
|
155
|
-
it
|
159
|
+
context 'input type=submit button' do
|
160
|
+
it 'should submit by button id' do
|
156
161
|
@session.click_button('awe123')
|
157
162
|
expect(extract_results(@session)['first_name']).to eq('John')
|
158
163
|
end
|
159
164
|
|
160
|
-
it
|
161
|
-
@session.click_button('
|
162
|
-
expect(@session).to
|
165
|
+
it 'should submit by specific button id' do
|
166
|
+
@session.click_button(id: 'awe123')
|
167
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
163
168
|
end
|
164
|
-
end
|
165
169
|
|
166
|
-
|
167
|
-
it "should submit the associated form" do
|
170
|
+
it 'should submit by button title' do
|
168
171
|
@session.click_button('What an Awesome Button')
|
169
172
|
expect(extract_results(@session)['first_name']).to eq('John')
|
170
173
|
end
|
171
174
|
|
172
|
-
it
|
175
|
+
it 'should submit by partial title', :exact_false do
|
173
176
|
@session.click_button('What an Awesome')
|
174
177
|
expect(extract_results(@session)['first_name']).to eq('John')
|
175
178
|
end
|
179
|
+
|
180
|
+
it 'should submit by button name' do
|
181
|
+
@session.click_button('form[awesome]')
|
182
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should submit by specific button name' do
|
186
|
+
@session.click_button(name: 'form[awesome]')
|
187
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should submit by specific button name regex' do
|
191
|
+
@session.click_button(name: /form\[awes.*\]/)
|
192
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
193
|
+
end
|
176
194
|
end
|
177
195
|
|
178
|
-
context
|
196
|
+
context 'when Capybara.enable_aria_role = true' do
|
197
|
+
it 'should click on a button role', requires: [:js] do
|
198
|
+
Capybara.enable_aria_role = true
|
199
|
+
@session.using_wait_time(1.5) do
|
200
|
+
@session.visit('/with_js')
|
201
|
+
@session.click_button('ARIA button')
|
202
|
+
expect(@session).to have_button('ARIA button has been clicked')
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'with fields associated with the form using the form attribute', requires: [:form_attribute] do
|
208
|
+
let(:results) { extract_results(@session) }
|
209
|
+
|
179
210
|
before do
|
180
211
|
@session.click_button('submit_form1')
|
181
|
-
@results = extract_results(@session)
|
182
212
|
end
|
183
213
|
|
184
|
-
it
|
185
|
-
expect(
|
214
|
+
it 'should serialize and submit text fields' do
|
215
|
+
expect(results['outside_input']).to eq('outside_input')
|
186
216
|
end
|
187
217
|
|
188
|
-
it
|
189
|
-
expect(
|
218
|
+
it 'should serialize text areas' do
|
219
|
+
expect(results['outside_textarea']).to eq('Some text here')
|
190
220
|
end
|
191
221
|
|
192
|
-
it
|
193
|
-
expect(
|
222
|
+
it 'should serialize select tags' do
|
223
|
+
expect(results['outside_select']).to eq('Ruby')
|
194
224
|
end
|
195
225
|
|
196
|
-
it
|
197
|
-
expect(
|
226
|
+
it 'should not serliaze fields associated with a different form' do
|
227
|
+
expect(results['for_form2']).to be_nil
|
198
228
|
end
|
199
229
|
end
|
200
230
|
|
231
|
+
context 'with submit button outside the form defined by <button> tag', requires: [:form_attribute] do
|
232
|
+
let(:results) { extract_results(@session) }
|
201
233
|
|
202
|
-
context "with submit button outside the form defined by <button> tag" do
|
203
234
|
before do
|
204
235
|
@session.click_button('outside_button')
|
205
|
-
@results = extract_results(@session)
|
206
236
|
end
|
207
237
|
|
208
|
-
it
|
209
|
-
expect(
|
238
|
+
it 'should submit the associated form' do
|
239
|
+
expect(results['which_form']).to eq('form2')
|
210
240
|
end
|
211
241
|
|
212
|
-
it
|
213
|
-
expect(
|
214
|
-
expect(
|
242
|
+
it 'should submit the button that was clicked, but not other buttons' do
|
243
|
+
expect(results['outside_button']).to eq('outside_button')
|
244
|
+
expect(results['unused']).to be_nil
|
215
245
|
end
|
216
246
|
end
|
217
247
|
|
218
|
-
context "with submit button outside the form defined by <input type='submit'> tag" do
|
248
|
+
context "with submit button outside the form defined by <input type='submit'> tag", requires: [:form_attribute] do
|
249
|
+
let(:results) { extract_results(@session) }
|
250
|
+
|
219
251
|
before do
|
220
252
|
@session.click_button('outside_submit')
|
221
|
-
@results = extract_results(@session)
|
222
253
|
end
|
223
254
|
|
224
|
-
it
|
225
|
-
expect(
|
255
|
+
it 'should submit the associated form' do
|
256
|
+
expect(results['which_form']).to eq('form1')
|
226
257
|
end
|
227
258
|
|
228
|
-
it
|
229
|
-
expect(
|
230
|
-
expect(
|
259
|
+
it 'should submit the button that was clicked, but not other buttons' do
|
260
|
+
expect(results['outside_submit']).to eq('outside_submit')
|
261
|
+
expect(results['submit_form1']).to be_nil
|
231
262
|
end
|
232
263
|
end
|
233
264
|
|
234
|
-
context
|
235
|
-
it
|
265
|
+
context 'with submit button for form1 located within form2', requires: [:form_attribute] do
|
266
|
+
it 'should submit the form associated with the button' do
|
236
267
|
@session.click_button('other_form_button')
|
237
|
-
expect(extract_results(@session)['which_form']).to eq(
|
268
|
+
expect(extract_results(@session)['which_form']).to eq('form1')
|
238
269
|
end
|
239
270
|
end
|
240
271
|
|
241
|
-
context
|
242
|
-
it
|
272
|
+
context 'with submit button not associated with any form' do
|
273
|
+
it 'should not error when clicked' do
|
243
274
|
expect { @session.click_button('no_form_button') }.not_to raise_error
|
244
275
|
end
|
245
276
|
end
|
246
277
|
|
247
|
-
context
|
248
|
-
it
|
278
|
+
context 'with alt given on an image button' do
|
279
|
+
it 'should submit the associated form' do
|
249
280
|
@session.click_button('oh hai thar')
|
250
281
|
expect(extract_results(@session)['first_name']).to eq('John')
|
251
282
|
end
|
252
283
|
|
253
|
-
it
|
284
|
+
it 'should work with partial matches', :exact_false do
|
254
285
|
@session.click_button('hai')
|
255
286
|
expect(extract_results(@session)['first_name']).to eq('John')
|
256
287
|
end
|
257
288
|
end
|
258
289
|
|
259
|
-
|
260
|
-
|
261
|
-
it "should submit the associated form" do
|
290
|
+
context 'with value given on an image button' do
|
291
|
+
it 'should submit the associated form' do
|
262
292
|
@session.click_button('okay')
|
263
293
|
expect(extract_results(@session)['first_name']).to eq('John')
|
264
294
|
end
|
265
295
|
|
266
|
-
it
|
296
|
+
it 'should work with partial matches', :exact_false do
|
267
297
|
@session.click_button('kay')
|
268
298
|
expect(extract_results(@session)['first_name']).to eq('John')
|
269
299
|
end
|
270
300
|
end
|
271
301
|
|
272
|
-
context
|
273
|
-
it
|
302
|
+
context 'with id given on an image button' do
|
303
|
+
it 'should submit the associated form' do
|
274
304
|
@session.click_button('okay556')
|
275
305
|
expect(extract_results(@session)['first_name']).to eq('John')
|
276
306
|
end
|
277
307
|
end
|
278
308
|
|
279
|
-
context
|
280
|
-
it
|
309
|
+
context 'with title given on an image button' do
|
310
|
+
it 'should submit the associated form' do
|
281
311
|
@session.click_button('Okay 556 Image')
|
282
312
|
expect(extract_results(@session)['first_name']).to eq('John')
|
283
313
|
end
|
284
314
|
|
285
|
-
it
|
315
|
+
it 'should work with partial matches', :exact_false do
|
286
316
|
@session.click_button('Okay 556')
|
287
317
|
expect(extract_results(@session)['first_name']).to eq('John')
|
288
318
|
end
|
289
319
|
end
|
290
320
|
|
291
|
-
context
|
292
|
-
it
|
293
|
-
@session.click_button('Click me')
|
321
|
+
context 'with text given on a button defined by <button> tag' do
|
322
|
+
it 'should submit the associated form' do
|
323
|
+
@session.click_button('Click me!')
|
294
324
|
expect(extract_results(@session)['first_name']).to eq('John')
|
295
325
|
end
|
296
326
|
|
297
|
-
it
|
327
|
+
it 'should work with partial matches', :exact_false do
|
298
328
|
@session.click_button('Click')
|
299
329
|
expect(extract_results(@session)['first_name']).to eq('John')
|
300
330
|
end
|
301
331
|
end
|
302
332
|
|
303
|
-
|
304
|
-
it
|
333
|
+
context 'with id given on a button defined by <button> tag' do
|
334
|
+
it 'should submit the associated form' do
|
305
335
|
@session.click_button('click_me_123')
|
306
336
|
expect(extract_results(@session)['first_name']).to eq('John')
|
307
337
|
end
|
308
338
|
|
309
|
-
it
|
339
|
+
it 'should serialize and send GET forms' do
|
310
340
|
@session.visit('/form')
|
311
341
|
@session.click_button('med')
|
312
|
-
|
313
|
-
expect(
|
314
|
-
expect(
|
342
|
+
results = extract_results(@session)
|
343
|
+
expect(results['middle_name']).to eq('Darren')
|
344
|
+
expect(results['foo']).to be_nil
|
315
345
|
end
|
316
346
|
end
|
317
347
|
|
318
|
-
|
319
|
-
it
|
348
|
+
context 'with name given on a button defined by <button> tag' do
|
349
|
+
it 'should submit the associated form when name is locator' do
|
350
|
+
@session.click_button('form[no_value]')
|
351
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'should submit the associated form when name is specific' do
|
355
|
+
@session.click_button(name: 'form[no_value]')
|
356
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context 'with value given on a button defined by <button> tag' do
|
361
|
+
it 'should submit the associated form' do
|
320
362
|
@session.click_button('click_me')
|
321
363
|
expect(extract_results(@session)['first_name']).to eq('John')
|
322
364
|
end
|
323
365
|
|
324
|
-
it
|
366
|
+
it 'should work with partial matches', :exact_false do
|
325
367
|
@session.click_button('ck_me')
|
326
368
|
expect(extract_results(@session)['first_name']).to eq('John')
|
327
369
|
end
|
328
370
|
end
|
329
371
|
|
330
|
-
context
|
331
|
-
it
|
372
|
+
context 'with title given on a button defined by <button> tag' do
|
373
|
+
it 'should submit the associated form' do
|
332
374
|
@session.click_button('Click Title button')
|
333
375
|
expect(extract_results(@session)['first_name']).to eq('John')
|
334
376
|
end
|
335
377
|
|
336
|
-
it
|
378
|
+
it 'should work with partial matches', :exact_false do
|
337
379
|
@session.click_button('Click Title')
|
338
380
|
expect(extract_results(@session)['first_name']).to eq('John')
|
339
381
|
end
|
340
382
|
end
|
383
|
+
|
384
|
+
context 'with descendant image alt given on a button defined by <button> tag' do
|
385
|
+
it 'should submit the associated form' do
|
386
|
+
@session.click_button('A horse eating hay')
|
387
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'should work with partial matches', :exact_false do
|
391
|
+
@session.click_button('se eating h')
|
392
|
+
expect(extract_results(@session)['first_name']).to eq('John')
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
341
396
|
context "with a locator that doesn't exist" do
|
342
|
-
it
|
343
|
-
msg =
|
397
|
+
it 'should raise an error' do
|
398
|
+
msg = /Unable to find button "does not exist"/
|
344
399
|
expect do
|
345
400
|
@session.click_button('does not exist')
|
346
401
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
347
402
|
end
|
348
403
|
end
|
349
404
|
|
350
|
-
context
|
351
|
-
it
|
405
|
+
context 'with formaction attribute on button' do
|
406
|
+
it 'should submit to the formaction attribute' do
|
352
407
|
@session.click_button('Formaction button')
|
353
|
-
|
408
|
+
results = extract_results(@session)
|
354
409
|
expect(@session.current_path).to eq '/form'
|
355
|
-
expect(
|
410
|
+
expect(results['which_form']).to eq 'formaction form'
|
356
411
|
end
|
357
412
|
end
|
358
413
|
|
359
|
-
context
|
360
|
-
it
|
414
|
+
context 'with formmethod attribute on button' do
|
415
|
+
it 'should submit to the formethod attribute' do
|
361
416
|
@session.click_button('Formmethod button')
|
362
|
-
|
417
|
+
results = extract_results(@session)
|
363
418
|
expect(@session.current_path).to eq '/form/get'
|
364
|
-
expect(
|
419
|
+
expect(results['which_form']).to eq 'formaction form'
|
365
420
|
end
|
366
421
|
end
|
367
422
|
|
368
|
-
it
|
423
|
+
it 'should serialize and send valueless buttons that were clicked' do
|
369
424
|
@session.click_button('No Value!')
|
370
|
-
|
371
|
-
expect(
|
425
|
+
results = extract_results(@session)
|
426
|
+
expect(results['no_value']).not_to be_nil
|
427
|
+
end
|
428
|
+
|
429
|
+
it 'should send button in document order' do
|
430
|
+
@session.click_button('outside_button')
|
431
|
+
results = extract_results(@session)
|
432
|
+
expect(results.keys).to eq %w[for_form2 outside_button which_form post_count]
|
372
433
|
end
|
373
434
|
|
374
|
-
it
|
435
|
+
it 'should not send image buttons that were not clicked' do
|
375
436
|
@session.click_button('Click me!')
|
376
|
-
|
377
|
-
expect(
|
437
|
+
results = extract_results(@session)
|
438
|
+
expect(results['okay']).to be_nil
|
378
439
|
end
|
379
440
|
|
380
|
-
it
|
441
|
+
it 'should serialize and send GET forms' do
|
381
442
|
@session.visit('/form')
|
382
443
|
@session.click_button('med')
|
383
|
-
|
384
|
-
expect(
|
385
|
-
expect(
|
444
|
+
results = extract_results(@session)
|
445
|
+
expect(results['middle_name']).to eq('Darren')
|
446
|
+
expect(results['foo']).to be_nil
|
386
447
|
end
|
387
448
|
|
388
|
-
it
|
449
|
+
it 'should follow redirects' do
|
389
450
|
@session.click_button('Go FAR')
|
390
451
|
expect(@session).to have_content('You landed')
|
391
452
|
expect(@session.current_url).to match(%r{/landed$})
|
392
453
|
end
|
393
454
|
|
394
|
-
it
|
455
|
+
it 'should follow temporary redirects that maintain method' do
|
456
|
+
@session.click_button('Go 307')
|
457
|
+
expect(@session).to have_content('You post landed: TWTW')
|
458
|
+
end
|
459
|
+
|
460
|
+
it 'should follow permanent redirects that maintain method' do
|
461
|
+
@session.click_button('Go 308')
|
462
|
+
expect(@session).to have_content('You post landed: TWTW')
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'should post pack to the same URL when no action given' do
|
395
466
|
@session.visit('/postback')
|
396
467
|
@session.click_button('With no action')
|
397
468
|
expect(@session).to have_content('Postback')
|
398
469
|
end
|
399
470
|
|
400
|
-
it
|
471
|
+
it 'should post pack to the same URL when blank action given' do
|
401
472
|
@session.visit('/postback')
|
402
473
|
@session.click_button('With blank action')
|
403
474
|
expect(@session).to have_content('Postback')
|
404
475
|
end
|
405
476
|
|
406
|
-
it
|
477
|
+
it 'ignores disabled buttons' do
|
407
478
|
expect do
|
408
479
|
@session.click_button('Disabled button')
|
409
480
|
end.to raise_error(Capybara::ElementNotFound)
|
410
481
|
end
|
411
482
|
|
412
|
-
it
|
483
|
+
it 'should encode complex field names, like array[][value]' do
|
413
484
|
@session.visit('/form')
|
414
|
-
@session.fill_in('address1_city', :
|
415
|
-
@session.fill_in('address1_street', :
|
416
|
-
@session.fill_in('address1_street', :with =>'CDG')
|
417
|
-
@session.select("France", :from => 'address1_country')
|
485
|
+
@session.fill_in('address1_city', with: 'Paris')
|
486
|
+
@session.fill_in('address1_street', with: 'CDG')
|
418
487
|
|
419
|
-
@session.fill_in('address2_city', :
|
420
|
-
@session.fill_in('address2_street', :
|
421
|
-
@session.select("Ukraine", :from => 'address2_country')
|
488
|
+
@session.fill_in('address2_city', with: 'Mikolaiv')
|
489
|
+
@session.fill_in('address2_street', with: 'PGS')
|
422
490
|
|
423
|
-
@session.click_button
|
491
|
+
@session.click_button 'awesome'
|
424
492
|
|
425
|
-
addresses=extract_results(@session)[
|
493
|
+
addresses = extract_results(@session)['addresses']
|
426
494
|
expect(addresses.size).to eq(2)
|
427
495
|
|
428
|
-
expect(addresses[0][
|
429
|
-
expect(addresses[0][
|
430
|
-
expect(addresses[0][
|
496
|
+
expect(addresses[0]['street']).to eq('CDG')
|
497
|
+
expect(addresses[0]['city']).to eq('Paris')
|
498
|
+
expect(addresses[0]['country']).to eq('France')
|
431
499
|
|
432
|
-
expect(addresses[1][
|
433
|
-
expect(addresses[1][
|
434
|
-
expect(addresses[1][
|
500
|
+
expect(addresses[1]['street']).to eq('PGS')
|
501
|
+
expect(addresses[1]['city']).to eq('Mikolaiv')
|
502
|
+
expect(addresses[1]['country']).to eq('Ukraine')
|
435
503
|
end
|
436
504
|
|
437
|
-
context
|
438
|
-
it
|
439
|
-
@session.click_button('What an Awesome', :
|
505
|
+
context 'with :exact option' do
|
506
|
+
it 'should accept partial matches when false' do
|
507
|
+
@session.click_button('What an Awesome', exact: false)
|
440
508
|
expect(extract_results(@session)['first_name']).to eq('John')
|
441
509
|
end
|
442
510
|
|
443
|
-
it
|
511
|
+
it 'should not accept partial matches when true' do
|
444
512
|
expect do
|
445
|
-
@session.click_button('What an Awesome', :
|
513
|
+
@session.click_button('What an Awesome', exact: true)
|
446
514
|
end.to raise_error(Capybara::ElementNotFound)
|
447
515
|
end
|
448
516
|
end
|