capybara 2.15.1 → 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 -1
- data/History.md +871 -9
- data/License.txt +1 -1
- data/README.md +99 -75
- data/lib/capybara/config.rb +20 -59
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +35 -18
- data/lib/capybara/driver/node.rb +35 -9
- data/lib/capybara/dsl.rb +15 -6
- data/lib/capybara/helpers.rb +72 -28
- data/lib/capybara/minitest/spec.rb +173 -81
- data/lib/capybara/minitest.rb +220 -111
- data/lib/capybara/node/actions.rb +270 -172
- data/lib/capybara/node/base.rb +41 -34
- data/lib/capybara/node/document.rb +15 -3
- data/lib/capybara/node/document_matchers.rb +19 -21
- data/lib/capybara/node/element.rb +353 -137
- data/lib/capybara/node/finders.rb +144 -138
- data/lib/capybara/node/matchers.rb +369 -209
- data/lib/capybara/node/simple.rb +55 -26
- data/lib/capybara/queries/ancestor_query.rb +11 -9
- data/lib/capybara/queries/base_query.rb +39 -28
- data/lib/capybara/queries/current_path_query.rb +22 -25
- data/lib/capybara/queries/match_query.rb +14 -7
- data/lib/capybara/queries/selector_query.rb +633 -145
- data/lib/capybara/queries/sibling_query.rb +10 -9
- data/lib/capybara/queries/style_query.rb +45 -0
- data/lib/capybara/queries/text_query.rb +56 -38
- data/lib/capybara/queries/title_query.rb +8 -11
- data/lib/capybara/rack_test/browser.rb +57 -41
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +18 -13
- 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 +182 -78
- data/lib/capybara/rails.rb +3 -7
- 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 +96 -62
- data/lib/capybara/rspec/features.rb +17 -50
- data/lib/capybara/rspec/matcher_proxies.rb +51 -14
- 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 +144 -264
- data/lib/capybara/rspec.rb +7 -11
- 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 +89 -17
- 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 +2 -17
- data/lib/capybara/selector/filter_set.rb +83 -33
- data/lib/capybara/selector/filters/base.rb +50 -6
- data/lib/capybara/selector/filters/expression_filter.rb +8 -26
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +16 -12
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +89 -210
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +226 -526
- 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 +334 -277
- 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 +506 -124
- 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 +59 -67
- data/lib/capybara/session/config.rb +79 -59
- data/lib/capybara/session/matchers.rb +41 -25
- data/lib/capybara/session.rb +360 -356
- 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 +159 -13
- data/lib/capybara/spec/session/accept_alert_spec.rb +12 -11
- data/lib/capybara/spec/session/accept_confirm_spec.rb +6 -5
- data/lib/capybara/spec/session/accept_prompt_spec.rb +34 -6
- data/lib/capybara/spec/session/all_spec.rb +163 -55
- data/lib/capybara/spec/session/ancestor_spec.rb +27 -24
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +68 -38
- 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.rb → assert_text_spec.rb} +91 -59
- data/lib/capybara/spec/session/{assert_title.rb → assert_title_spec.rb} +22 -12
- data/lib/capybara/spec/session/attach_file_spec.rb +138 -69
- data/lib/capybara/spec/session/body_spec.rb +12 -13
- data/lib/capybara/spec/session/check_spec.rb +107 -55
- data/lib/capybara/spec/session/choose_spec.rb +58 -31
- data/lib/capybara/spec/session/click_button_spec.rb +231 -173
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +55 -35
- data/lib/capybara/spec/session/click_link_spec.rb +82 -58
- data/lib/capybara/spec/session/current_scope_spec.rb +11 -10
- data/lib/capybara/spec/session/current_url_spec.rb +57 -39
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +4 -4
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +3 -2
- data/lib/capybara/spec/session/element/{assert_match_selector.rb → assert_match_selector_spec.rb} +11 -9
- data/lib/capybara/spec/session/element/match_css_spec.rb +18 -10
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +9 -7
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +71 -57
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +30 -9
- data/lib/capybara/spec/session/execute_script_spec.rb +10 -8
- data/lib/capybara/spec/session/fill_in_spec.rb +128 -43
- data/lib/capybara/spec/session/find_button_spec.rb +25 -24
- data/lib/capybara/spec/session/find_by_id_spec.rb +10 -9
- data/lib/capybara/spec/session/find_field_spec.rb +37 -41
- data/lib/capybara/spec/session/find_link_spec.rb +36 -17
- data/lib/capybara/spec/session/find_spec.rb +245 -144
- data/lib/capybara/spec/session/first_spec.rb +79 -51
- 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 +33 -20
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +50 -32
- data/lib/capybara/spec/session/go_back_spec.rb +2 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +2 -1
- 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 +70 -13
- data/lib/capybara/spec/session/has_css_spec.rb +272 -137
- data/lib/capybara/spec/session/has_current_path_spec.rb +87 -45
- data/lib/capybara/spec/session/has_field_spec.rb +115 -59
- data/lib/capybara/spec/session/has_link_spec.rb +10 -9
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +78 -0
- data/lib/capybara/spec/session/has_select_spec.rb +103 -74
- data/lib/capybara/spec/session/has_selector_spec.rb +105 -71
- 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 +113 -61
- data/lib/capybara/spec/session/has_title_spec.rb +20 -14
- data/lib/capybara/spec/session/has_xpath_spec.rb +57 -38
- 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 +950 -152
- data/lib/capybara/spec/session/node_wrapper_spec.rb +39 -0
- data/lib/capybara/spec/session/refresh_spec.rb +12 -6
- data/lib/capybara/spec/session/reset_session_spec.rb +69 -35
- 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 +8 -12
- 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 +107 -80
- data/lib/capybara/spec/session/selectors_spec.rb +52 -19
- data/lib/capybara/spec/session/sibling_spec.rb +10 -10
- data/lib/capybara/spec/session/text_spec.rb +37 -21
- data/lib/capybara/spec/session/title_spec.rb +17 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +42 -22
- data/lib/capybara/spec/session/unselect_spec.rb +39 -38
- data/lib/capybara/spec/session/visit_spec.rb +99 -32
- data/lib/capybara/spec/session/window/become_closed_spec.rb +24 -20
- 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 +27 -22
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +12 -6
- data/lib/capybara/spec/session/window/window_spec.rb +97 -63
- data/lib/capybara/spec/session/window/windows_spec.rb +12 -10
- data/lib/capybara/spec/session/window/within_window_spec.rb +31 -86
- data/lib/capybara/spec/session/within_spec.rb +70 -44
- data/lib/capybara/spec/spec_helper.rb +48 -43
- data/lib/capybara/spec/test_app.rb +78 -40
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +130 -39
- 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/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/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 +68 -1
- data/lib/capybara/spec/views/with_animation.erb +82 -0
- 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 +6 -0
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +69 -10
- data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +37 -0
- 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_other.erb +6 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/spec/views/within_frames.erb +4 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +35 -33
- data/lib/capybara.rb +131 -104
- data/spec/basic_node_spec.rb +47 -34
- data/spec/capybara_spec.rb +53 -104
- data/spec/css_builder_spec.rb +101 -0
- data/spec/css_splitter_spec.rb +38 -0
- data/spec/dsl_spec.rb +81 -62
- data/spec/filter_set_spec.rb +27 -9
- data/spec/fixtures/certificate.pem +25 -0
- data/spec/fixtures/key.pem +27 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +5 -4
- data/spec/fixtures/selenium_driver_rspec_success.rb +5 -4
- data/spec/minitest_spec.rb +49 -7
- data/spec/minitest_spec_spec.rb +94 -59
- data/spec/per_session_config_spec.rb +14 -13
- data/spec/rack_test_spec.rb +176 -125
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +101 -46
- data/spec/rspec/features_spec.rb +37 -31
- data/spec/rspec/scenarios_spec.rb +9 -7
- data/spec/rspec/shared_spec_matchers.rb +448 -421
- data/spec/rspec/views_spec.rb +5 -3
- data/spec/rspec_matchers_spec.rb +27 -11
- data/spec/rspec_spec.rb +109 -89
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +396 -67
- data/spec/selenium_spec_chrome.rb +184 -35
- data/spec/selenium_spec_chrome_remote.rb +100 -0
- data/spec/selenium_spec_edge.rb +47 -0
- data/spec/selenium_spec_firefox.rb +183 -41
- 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 +198 -99
- data/spec/session_spec.rb +53 -16
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +486 -97
- data/spec/spec_helper.rb +93 -7
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +338 -64
- data/.yard/templates_custom/default/class/html/selectors.erb +0 -38
- data/.yard/templates_custom/default/class/html/setup.rb +0 -17
- data/.yard/yard_extensions.rb +0 -78
- data/lib/capybara/query.rb +0 -7
- data/lib/capybara/rspec/compound.rb +0 -95
- data/lib/capybara/spec/session/assert_current_path.rb +0 -72
- data/lib/capybara/spec/session/assert_selector.rb +0 -148
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/spec/selenium_spec_marionette.rb +0 -117
data/License.txt
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
# Capybara
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/teamcapybara/capybara.svg)](https://travis-ci.org/teamcapybara/capybara)
|
4
|
-
[![
|
4
|
+
[![Build Status](https://ci.appveyor.com/api/projects/status/github/teamcapybara/capybara?svg=true)](https://ci.appveyor.com/api/projects/github/teamcapybara/capybara)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/teamcapybara/capybara.svg)](https://codeclimate.com/github/teamcapybara/capybara)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/teamcapybara/capybara/badge.svg?branch=master)](https://coveralls.io/github/teamcapybara/capybara?branch=master)
|
6
7
|
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jnicklas/capybara?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
8
|
+
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=capybara&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=capybara&package-manager=bundler&version-scheme=semver)
|
7
9
|
|
8
10
|
Capybara helps you test web applications by simulating how a real user would
|
9
11
|
interact with your app. It is agnostic about the driver running your tests and
|
10
12
|
comes with Rack::Test and Selenium support built in. WebKit is supported
|
11
13
|
through an external gem.
|
12
14
|
|
15
|
+
## Support Capybara
|
16
|
+
|
17
|
+
If you and/or your company find value in Capybara and would like to contribute financially to its ongoing maintenance and development, please visit
|
18
|
+
<a href="https://www.patreon.com/capybara">Patreon</a>
|
19
|
+
|
20
|
+
|
13
21
|
**Need help?** Ask on the mailing list (please do not open an issue on
|
14
22
|
GitHub): http://groups.google.com/group/ruby-capybara
|
15
23
|
|
@@ -26,8 +34,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
|
|
26
34
|
- [Selecting the Driver](#selecting-the-driver)
|
27
35
|
- [RackTest](#racktest)
|
28
36
|
- [Selenium](#selenium)
|
29
|
-
- [
|
30
|
-
- [Poltergeist](#poltergeist)
|
37
|
+
- [Apparition](#apparition)
|
31
38
|
- [The DSL](#the-dsl)
|
32
39
|
- [Navigating](#navigating)
|
33
40
|
- [Clicking links and buttons](#clicking-links-and-buttons)
|
@@ -47,11 +54,13 @@ GitHub): http://groups.google.com/group/ruby-capybara
|
|
47
54
|
- [Using the DSL elsewhere](#using-the-dsl-elsewhere)
|
48
55
|
- [Calling remote servers](#calling-remote-servers)
|
49
56
|
- [Using sessions](#using-sessions)
|
57
|
+
- [Named sessions](#named-sessions)
|
58
|
+
- [Using sessions manually](#using-sessions-manually)
|
50
59
|
- [XPath, CSS and selectors](#xpath-css-and-selectors)
|
51
60
|
- [Beware the XPath // trap](#beware-the-xpath--trap)
|
52
61
|
- [Configuring and adding drivers](#configuring-and-adding-drivers)
|
53
62
|
- [Gotchas:](#gotchas)
|
54
|
-
- ["Threadsafe" mode](#threadsafe)
|
63
|
+
- ["Threadsafe" mode](#threadsafe-mode)
|
55
64
|
- [Development](#development)
|
56
65
|
|
57
66
|
## <a name="key-benefits"></a>Key benefits
|
@@ -65,24 +74,19 @@ GitHub): http://groups.google.com/group/ruby-capybara
|
|
65
74
|
|
66
75
|
## <a name="setup"></a>Setup
|
67
76
|
|
68
|
-
Capybara requires Ruby
|
77
|
+
Capybara requires Ruby 2.5.0 or later. To install, add this line to your
|
69
78
|
`Gemfile` and run `bundle install`:
|
70
79
|
|
71
80
|
```ruby
|
72
81
|
gem 'capybara'
|
73
82
|
```
|
74
83
|
|
75
|
-
**Note:** If using Ruby < 2.0 you will also need to limit the version of rack to < 2.0
|
76
|
-
|
77
84
|
If the application that you are testing is a Rails app, add this line to your test helper file:
|
78
85
|
|
79
86
|
```ruby
|
80
87
|
require 'capybara/rails'
|
81
88
|
```
|
82
89
|
|
83
|
-
**Note:** In Rails 4.0/4.1 the default test environment (`config/environments/test.rb`) is [not threadsafe](https://github.com/rails/rails/issues/15089).
|
84
|
-
If you experience random errors about missing constants, add `config.allow_concurrency = false` to `config/environments/test.rb`.
|
85
|
-
|
86
90
|
If the application that you are testing is a Rack app, but not Rails, set Capybara.app to your Rack app:
|
87
91
|
|
88
92
|
```ruby
|
@@ -134,26 +138,26 @@ There are also explicit tags for each registered driver set up for you (`@seleni
|
|
134
138
|
|
135
139
|
## <a name="using-capybara-with-rspec"></a>Using Capybara with RSpec
|
136
140
|
|
137
|
-
Load RSpec
|
141
|
+
Load RSpec 3.5+ support by adding the following line (typically to your
|
138
142
|
`spec_helper.rb` file):
|
139
143
|
|
140
144
|
```ruby
|
141
145
|
require 'capybara/rspec'
|
142
146
|
```
|
143
147
|
|
144
|
-
If you are using Rails, put your Capybara specs in `spec/features` (only works
|
148
|
+
If you are using Rails, put your Capybara specs in `spec/features` or `spec/system` (only works
|
145
149
|
if [you have it configured in
|
146
|
-
RSpec](https://
|
150
|
+
RSpec](https://relishapp.com/rspec/rspec-rails/v/4-0/docs/directory-structure))
|
147
151
|
and if you have your Capybara specs in a different directory, then tag the
|
148
|
-
example groups with
|
152
|
+
example groups with `type: :feature` or `type: :system` depending on which type of test you're writing.
|
149
153
|
|
150
154
|
If you are not using Rails, tag all the example groups in which you want to use
|
151
|
-
Capybara with
|
155
|
+
Capybara with `type: :feature`.
|
152
156
|
|
153
157
|
You can now write your specs like so:
|
154
158
|
|
155
159
|
```ruby
|
156
|
-
describe "the signin process", :
|
160
|
+
describe "the signin process", type: :feature do
|
157
161
|
before :each do
|
158
162
|
User.make(email: 'user@example.com', password: 'password')
|
159
163
|
end
|
@@ -177,7 +181,7 @@ to one specific driver. For example:
|
|
177
181
|
```ruby
|
178
182
|
describe 'some stuff which requires js', js: true do
|
179
183
|
it 'will use the default js driver'
|
180
|
-
it 'will switch to one specific driver', :
|
184
|
+
it 'will switch to one specific driver', driver: :apparition
|
181
185
|
end
|
182
186
|
```
|
183
187
|
|
@@ -213,11 +217,11 @@ feature "Signing in" do
|
|
213
217
|
end
|
214
218
|
```
|
215
219
|
|
216
|
-
`feature` is in fact just an alias for `describe ..., :
|
220
|
+
`feature` is in fact just an alias for `describe ..., type: :feature`,
|
217
221
|
`background` is an alias for `before`, `scenario` for `it`, and
|
218
222
|
`given`/`given!` aliases for `let`/`let!`, respectively.
|
219
223
|
|
220
|
-
Finally, Capybara matchers are supported in view specs:
|
224
|
+
Finally, Capybara matchers are also supported in view specs:
|
221
225
|
|
222
226
|
```ruby
|
223
227
|
RSpec.describe "todos/show.html.erb", type: :view do
|
@@ -254,7 +258,7 @@ end
|
|
254
258
|
|
255
259
|
## <a name="using-capybara-with-minitest"></a>Using Capybara with Minitest
|
256
260
|
|
257
|
-
* If you are using Rails, add the following code in your `test_helper.rb`
|
261
|
+
* If you are using Rails, but not using Rails system tests, add the following code in your `test_helper.rb`
|
258
262
|
file to make Capybara available in all test cases deriving from
|
259
263
|
`ActionDispatch::IntegrationTest`:
|
260
264
|
|
@@ -269,8 +273,7 @@ end
|
|
269
273
|
include Capybara::Minitest::Assertions
|
270
274
|
|
271
275
|
# Reset sessions and driver between tests
|
272
|
-
|
273
|
-
def teardown
|
276
|
+
teardown do
|
274
277
|
Capybara.reset_sessions!
|
275
278
|
Capybara.use_default_driver
|
276
279
|
end
|
@@ -335,9 +338,9 @@ For example if you'd prefer to run everything in Selenium, you could do:
|
|
335
338
|
Capybara.default_driver = :selenium # :selenium_chrome and :selenium_chrome_headless are also registered
|
336
339
|
```
|
337
340
|
|
338
|
-
However, if you are using RSpec or Cucumber
|
339
|
-
leaving the faster `:rack_test` as the __default_driver__, and
|
340
|
-
tests that require a JavaScript-capable driver using `js: true` or
|
341
|
+
However, if you are using RSpec or Cucumber (and your app runs correctly without JS),
|
342
|
+
you may instead want to consider leaving the faster `:rack_test` as the __default_driver__, and
|
343
|
+
marking only those tests that require a JavaScript-capable driver using `js: true` or
|
341
344
|
`@javascript`, respectively. By default, JavaScript tests are run using the
|
342
345
|
`:selenium` driver. You can change this by setting
|
343
346
|
`Capybara.javascript_driver`.
|
@@ -346,7 +349,7 @@ You can also change the driver temporarily (typically in the Before/setup and
|
|
346
349
|
After/teardown blocks):
|
347
350
|
|
348
351
|
```ruby
|
349
|
-
Capybara.current_driver = :
|
352
|
+
Capybara.current_driver = :apparition # temporarily select different driver
|
350
353
|
# tests here
|
351
354
|
Capybara.use_default_driver # switch back to default driver
|
352
355
|
```
|
@@ -381,42 +384,35 @@ See the section on adding and configuring drivers.
|
|
381
384
|
|
382
385
|
### <a name="selenium"></a>Selenium
|
383
386
|
|
384
|
-
|
385
|
-
(Webdriver)](
|
386
|
-
|
387
|
-
|
388
|
-
Provided Firefox is installed, everything is set up for you, and you should be
|
389
|
-
able to start using Selenium right away.
|
390
|
-
|
391
|
-
**Note**: drivers which run the server in a different thread may not share the
|
392
|
-
same transaction as your tests, causing data not to be shared between your test
|
393
|
-
and test server, see "Transactions and database setup" below.
|
387
|
+
Capybara supports [Selenium 3.5+
|
388
|
+
(Webdriver)](https://www.seleniumhq.org/projects/webdriver/).
|
389
|
+
In order to use Selenium, you'll need to install the `selenium-webdriver` gem,
|
390
|
+
and add it to your Gemfile if you're using bundler.
|
394
391
|
|
395
|
-
|
392
|
+
Capybara pre-registers a number of named drivers that use Selenium - they are:
|
396
393
|
|
397
|
-
|
398
|
-
|
399
|
-
|
394
|
+
* :selenium => Selenium driving Firefox
|
395
|
+
* :selenium_headless => Selenium driving Firefox in a headless configuration
|
396
|
+
* :selenium_chrome => Selenium driving Chrome
|
397
|
+
* :selenium_chrome_headless => Selenium driving Chrome in a headless configuration
|
400
398
|
|
401
|
-
|
399
|
+
These should work (with relevant software installation) in a local desktop configuration but you may
|
400
|
+
need to customize them if using in a CI environment where additional options may need to be passed
|
401
|
+
to the browsers. See the section on adding and configuring drivers.
|
402
402
|
|
403
|
-
```bash
|
404
|
-
gem install capybara-webkit
|
405
|
-
```
|
406
403
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
Capybara.javascript_driver = :webkit
|
411
|
-
```
|
404
|
+
**Note**: drivers which run the server in a different thread may not share the
|
405
|
+
same transaction as your tests, causing data not to be shared between your test
|
406
|
+
and test server, see [Transactions and database setup](#transactions-and-database-setup) below.
|
412
407
|
|
413
|
-
### <a name="
|
408
|
+
### <a name="apparition"></a>Apparition
|
414
409
|
|
415
|
-
[
|
416
|
-
|
417
|
-
[
|
418
|
-
|
419
|
-
|
410
|
+
The [apparition driver](https://github.com/twalpole/apparition) is a new driver that allows you to run tests using Chrome in a headless
|
411
|
+
or headed configuration. It attempts to provide backwards compatibility with the [Poltergeist driver API](https://github.com/teampoltergeist/poltergeist)
|
412
|
+
and [capybara-webkit API](https://github.com/thoughtbot/capybara-webkit) while allowing for the use of modern JS/CSS. It
|
413
|
+
uses CDP to communicate with Chrome, thereby obviating the need for chromedriver. This driver is being developed by the
|
414
|
+
current developer of Capybara and will attempt to keep up to date with new Capybara releases. It will probably be moved into the
|
415
|
+
teamcapybara repo once it reaches v1.0.
|
420
416
|
|
421
417
|
## <a name="the-dsl"></a>The DSL
|
422
418
|
|
@@ -543,7 +539,7 @@ If you find yourself needing to use this a lot you may be better off adding a [c
|
|
543
539
|
```ruby
|
544
540
|
find_field('First Name'){ |el| el['data-xyz'] == '123' }
|
545
541
|
find("#img_loading"){ |img| img['complete'] == true }
|
546
|
-
|
542
|
+
```
|
547
543
|
|
548
544
|
**Note**: `find` will wait for an element to appear on the page, as explained in the
|
549
545
|
Ajax section. If the element does not appear it will raise an error.
|
@@ -611,13 +607,23 @@ In drivers which support it, you can easily execute JavaScript:
|
|
611
607
|
page.execute_script("$('body').empty()")
|
612
608
|
```
|
613
609
|
|
614
|
-
For simple expressions, you can return the result of the script.
|
615
|
-
that this may break with more complicated expressions:
|
610
|
+
For simple expressions, you can return the result of the script.
|
616
611
|
|
617
612
|
```ruby
|
618
613
|
result = page.evaluate_script('4 + 4');
|
619
614
|
```
|
620
615
|
|
616
|
+
For more complicated scripts you'll need to write them as one expression.
|
617
|
+
|
618
|
+
```ruby
|
619
|
+
result = page.evaluate_script(<<~JS, 3, element)
|
620
|
+
(function(n, el){
|
621
|
+
var val = parseInt(el.value, 10);
|
622
|
+
return n+val;
|
623
|
+
})(arguments[0], arguments[1])
|
624
|
+
JS
|
625
|
+
```
|
626
|
+
|
621
627
|
### <a name="modals"></a>Modals
|
622
628
|
|
623
629
|
In drivers which support it, you can accept, dismiss and respond to alerts, confirms and prompts.
|
@@ -736,7 +742,7 @@ Capybara 1.x, set `Capybara.match` to `:prefer_exact`.
|
|
736
742
|
|
737
743
|
## <a name="transactions-and-database-setup"></a>Transactions and database setup
|
738
744
|
|
739
|
-
**Note:** Rails 5.1+
|
745
|
+
**Note:** Rails 5.1+ "safely" shares the database connection between the app and test threads. Therefore,
|
740
746
|
if using Rails 5.1+ you SHOULD be able to ignore this section.
|
741
747
|
|
742
748
|
Some Capybara drivers need to run against an actual HTTP server. Capybara takes
|
@@ -888,7 +894,7 @@ To permanently switch the current session to a different session
|
|
888
894
|
|
889
895
|
```ruby
|
890
896
|
Capybara.session_name = "some other session"
|
891
|
-
|
897
|
+
```
|
892
898
|
|
893
899
|
### <a name="using-sessions-manually"></a>Using sessions manually
|
894
900
|
|
@@ -926,12 +932,17 @@ Capybara.default_selector = :xpath
|
|
926
932
|
find('.//ul/li').text
|
927
933
|
```
|
928
934
|
|
929
|
-
Capybara
|
930
|
-
|
935
|
+
Capybara provides a number of other built-in selector types. The full list, along
|
936
|
+
with applicable filters, can be seen at [built-in selectors](https://www.rubydoc.info/github/teamcapybara/capybara/Capybara/Selector)
|
937
|
+
|
938
|
+
Capybara also allows you to add custom selectors, which can be very useful if you
|
939
|
+
find yourself using the same kinds of selectors very often. The examples below are very
|
940
|
+
simple, and there are many available features not demonstrated. For more in-depth examples
|
941
|
+
please see Capybaras built-in selector definitions.
|
931
942
|
|
932
943
|
```ruby
|
933
|
-
Capybara.add_selector(:
|
934
|
-
xpath { |id| XPath.descendant[XPath.attr(:
|
944
|
+
Capybara.add_selector(:my_attribute) do
|
945
|
+
xpath { |id| XPath.descendant[XPath.attr(:my_attribute) == id.to_s] }
|
935
946
|
end
|
936
947
|
|
937
948
|
Capybara.add_selector(:row) do
|
@@ -948,9 +959,9 @@ an XPath expression generated through the XPath gem. You can now use these
|
|
948
959
|
selectors like this:
|
949
960
|
|
950
961
|
```ruby
|
951
|
-
find(:
|
952
|
-
find(:row, 3)
|
953
|
-
find(:flash_type, :notice)
|
962
|
+
find(:my_attribute, 'post_123') # find element with matching attribute
|
963
|
+
find(:row, 3) # find 3rd row in table body
|
964
|
+
find(:flash_type, :notice) # find element with id of 'flash' and class of 'notice'
|
954
965
|
```
|
955
966
|
|
956
967
|
## <a name="beware-the-xpath--trap"></a>Beware the XPath // trap
|
@@ -996,6 +1007,7 @@ end
|
|
996
1007
|
However, it's also possible to give this configuration a different name.
|
997
1008
|
|
998
1009
|
```ruby
|
1010
|
+
# Note: Capybara registers this by default
|
999
1011
|
Capybara.register_driver :selenium_chrome do |app|
|
1000
1012
|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
|
1001
1013
|
end
|
@@ -1041,13 +1053,22 @@ additional info about how the underlying driver can be configured.
|
|
1041
1053
|
are testing for specific server errors and using multiple sessions make sure to test for the
|
1042
1054
|
errors using the initial session (usually :default)
|
1043
1055
|
|
1044
|
-
|
1056
|
+
* If WebMock is enabled, you may encounter a "Too many open files"
|
1057
|
+
error. A simple `page.find` call may cause thousands of HTTP requests
|
1058
|
+
until the timeout occurs. By default, WebMock will cause each of these
|
1059
|
+
requests to spawn a new connection. To work around this problem, you
|
1060
|
+
may need to [enable WebMock's `net_http_connect_on_start: true`
|
1061
|
+
parameter](https://github.com/bblimke/webmock/blob/master/README.md#connecting-on-nethttpstart).
|
1062
|
+
|
1063
|
+
## <a name="threadsafe"></a>"Threadsafe" mode
|
1045
1064
|
|
1046
1065
|
In normal mode most of Capybara's configuration options are global settings which can cause issues
|
1047
1066
|
if using multiple sessions and wanting to change a setting for only one of the sessions. To provide
|
1048
1067
|
support for this type of usage Capybara now provides a "threadsafe" mode which can be enabled by setting
|
1049
1068
|
|
1050
|
-
|
1069
|
+
```ruby
|
1070
|
+
Capybara.threadsafe = true
|
1071
|
+
```
|
1051
1072
|
|
1052
1073
|
This setting can only be changed before any sessions have been created. In "threadsafe" mode the following
|
1053
1074
|
behaviors of Capybara change
|
@@ -1057,11 +1078,13 @@ behaviors of Capybara change
|
|
1057
1078
|
`app`, `reuse_server`, `default_driver`, `javascript_driver`, and (obviously) `threadsafe`. Any drivers and servers
|
1058
1079
|
registered through `register_driver` and `register_server` are also global.
|
1059
1080
|
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1081
|
+
```ruby
|
1082
|
+
my_session = Capybara::Session.new(:driver, some_app) do |config|
|
1083
|
+
config.automatic_label_click = true # only set for my_session
|
1084
|
+
end
|
1085
|
+
my_session.config.default_max_wait_time = 10 # only set for my_session
|
1086
|
+
Capybara.default_max_wait_time = 2 # will not change the default_max_wait in my_session
|
1087
|
+
```
|
1065
1088
|
|
1066
1089
|
* `current_driver` and `session_name` are thread specific. This means that `using_session` and
|
1067
1090
|
`using_driver` also only affect the current thread.
|
@@ -1072,7 +1095,8 @@ To set up a development environment, simply do:
|
|
1072
1095
|
|
1073
1096
|
```bash
|
1074
1097
|
bundle install
|
1075
|
-
bundle exec rake # run the test suite
|
1098
|
+
bundle exec rake # run the test suite with Firefox - requires `geckodriver` to be installed
|
1099
|
+
bundle exec rake spec_chrome # run the test suite with Chrome - require `chromedriver` to be installed
|
1076
1100
|
```
|
1077
1101
|
|
1078
1102
|
See
|
data/lib/capybara/config.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'forwardable'
|
3
4
|
require 'capybara/session/config'
|
4
5
|
|
@@ -6,11 +7,10 @@ module Capybara
|
|
6
7
|
class Config
|
7
8
|
extend Forwardable
|
8
9
|
|
9
|
-
OPTIONS = [
|
10
|
+
OPTIONS = %i[app reuse_server threadsafe server default_driver javascript_driver allow_gumbo].freeze
|
10
11
|
|
11
|
-
attr_accessor :app
|
12
|
-
attr_reader :reuse_server, :threadsafe
|
13
|
-
attr_reader :session_options
|
12
|
+
attr_accessor :app, :allow_gumbo
|
13
|
+
attr_reader :reuse_server, :threadsafe, :session_options
|
14
14
|
attr_writer :default_driver, :javascript_driver
|
15
15
|
|
16
16
|
SessionConfig::OPTIONS.each do |method|
|
@@ -19,15 +19,16 @@ module Capybara
|
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
@session_options = Capybara::SessionConfig.new
|
22
|
+
@javascript_driver = nil
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
-
@reuse_server = bool
|
26
|
-
end
|
25
|
+
attr_writer :reuse_server
|
27
26
|
|
28
27
|
def threadsafe=(bool)
|
29
|
-
|
30
|
-
|
28
|
+
if (bool != threadsafe) && Session.instance_created?
|
29
|
+
raise 'Threadsafe setting cannot be changed once a session is created'
|
30
|
+
end
|
31
|
+
|
31
32
|
@threadsafe = bool
|
32
33
|
end
|
33
34
|
|
@@ -35,16 +36,9 @@ module Capybara
|
|
35
36
|
#
|
36
37
|
# Return the proc that Capybara will call to run the Rack application.
|
37
38
|
# The block returned receives a rack app, port, and host/ip and should run a Rack handler
|
38
|
-
# By default, Capybara will try to
|
39
|
+
# By default, Capybara will try to use puma.
|
39
40
|
#
|
40
|
-
|
41
|
-
if block_given?
|
42
|
-
warn "DEPRECATED: Passing a block to Capybara::server is deprecated, please use Capybara::register_server instead"
|
43
|
-
@server = block
|
44
|
-
else
|
45
|
-
@server
|
46
|
-
end
|
47
|
-
end
|
41
|
+
attr_reader :server
|
48
42
|
|
49
43
|
##
|
50
44
|
#
|
@@ -64,12 +58,10 @@ module Capybara
|
|
64
58
|
name, options = *name if name.is_a? Array
|
65
59
|
@server = if name.respond_to? :call
|
66
60
|
name
|
61
|
+
elsif options
|
62
|
+
proc { |app, port, host| Capybara.servers[name.to_sym].call(app, port, host, **options) }
|
67
63
|
else
|
68
|
-
|
69
|
-
Proc.new { |app, port, host| Capybara.servers[name.to_sym].call(app,port,host,options) }
|
70
|
-
else
|
71
|
-
Capybara.servers[name.to_sym]
|
72
|
-
end
|
64
|
+
Capybara.servers[name.to_sym]
|
73
65
|
end
|
74
66
|
end
|
75
67
|
|
@@ -89,43 +81,12 @@ module Capybara
|
|
89
81
|
@javascript_driver || :selenium
|
90
82
|
end
|
91
83
|
|
92
|
-
|
93
|
-
def default_wait_time
|
94
|
-
deprecate('default_wait_time', 'default_max_wait_time', true)
|
95
|
-
default_max_wait_time
|
96
|
-
end
|
97
|
-
|
98
|
-
# @deprecated Use default_max_wait_time= instead
|
99
|
-
def default_wait_time=(t)
|
100
|
-
deprecate('default_wait_time=', 'default_max_wait_time=')
|
101
|
-
self.default_max_wait_time = t
|
102
|
-
end
|
103
|
-
|
104
|
-
def deprecate(method, alternate_method, once=false)
|
84
|
+
def deprecate(method, alternate_method, once: false)
|
105
85
|
@deprecation_notified ||= {}
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class ConfigureDeprecator
|
112
|
-
def initialize(config)
|
113
|
-
@config = config
|
114
|
-
end
|
115
|
-
|
116
|
-
def method_missing(m, *args, &block)
|
117
|
-
if @config.respond_to?(m)
|
118
|
-
@config.public_send(m, *args, &block)
|
119
|
-
elsif Capybara.respond_to?(m)
|
120
|
-
warn "Calling #{m} from Capybara.configure is deprecated - please call it on Capybara directly ( Capybara.#{m}(...) )"
|
121
|
-
Capybara.public_send(m, *args, &block)
|
122
|
-
else
|
123
|
-
super
|
86
|
+
unless once && @deprecation_notified[method]
|
87
|
+
Capybara::Helpers.warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead: #{Capybara::Helpers.filter_backtrace(caller)}"
|
124
88
|
end
|
125
|
-
|
126
|
-
|
127
|
-
def respond_to_missing?(m, include_private = false)
|
128
|
-
@config.respond_to_missing?(m, include_private) || Capybara.respond_to_missing?(m, include_private)
|
89
|
+
@deprecation_notified[method] = true
|
129
90
|
end
|
130
91
|
end
|
131
|
-
end
|
92
|
+
end
|