capybara 3.32.0 → 3.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +99 -15
  3. data/README.md +9 -4
  4. data/lib/capybara.rb +18 -8
  5. data/lib/capybara/config.rb +4 -6
  6. data/lib/capybara/cucumber.rb +1 -1
  7. data/lib/capybara/driver/base.rb +4 -0
  8. data/lib/capybara/helpers.rb +25 -1
  9. data/lib/capybara/minitest.rb +2 -3
  10. data/lib/capybara/minitest/spec.rb +14 -11
  11. data/lib/capybara/node/actions.rb +16 -21
  12. data/lib/capybara/node/base.rb +6 -6
  13. data/lib/capybara/node/element.rb +1 -5
  14. data/lib/capybara/node/finders.rb +7 -6
  15. data/lib/capybara/node/matchers.rb +12 -12
  16. data/lib/capybara/node/simple.rb +5 -1
  17. data/lib/capybara/queries/ancestor_query.rb +1 -1
  18. data/lib/capybara/queries/current_path_query.rb +14 -4
  19. data/lib/capybara/queries/selector_query.rb +40 -18
  20. data/lib/capybara/queries/sibling_query.rb +1 -1
  21. data/lib/capybara/queries/style_query.rb +1 -1
  22. data/lib/capybara/queries/text_query.rb +7 -1
  23. data/lib/capybara/rack_test/browser.rb +7 -3
  24. data/lib/capybara/rack_test/driver.rb +1 -0
  25. data/lib/capybara/rack_test/form.rb +1 -1
  26. data/lib/capybara/rack_test/node.rb +1 -1
  27. data/lib/capybara/registration_container.rb +44 -0
  28. data/lib/capybara/registrations/drivers.rb +18 -12
  29. data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
  30. data/lib/capybara/registrations/servers.rb +3 -2
  31. data/lib/capybara/result.rb +10 -11
  32. data/lib/capybara/rspec.rb +2 -0
  33. data/lib/capybara/rspec/matcher_proxies.rb +1 -1
  34. data/lib/capybara/rspec/matchers.rb +7 -6
  35. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  36. data/lib/capybara/rspec/matchers/have_text.rb +1 -1
  37. data/lib/capybara/rspec/matchers/match_style.rb +5 -0
  38. data/lib/capybara/selector.rb +12 -3
  39. data/lib/capybara/selector/builders/css_builder.rb +1 -1
  40. data/lib/capybara/selector/builders/xpath_builder.rb +3 -1
  41. data/lib/capybara/selector/definition.rb +11 -9
  42. data/lib/capybara/selector/definition/button.rb +26 -14
  43. data/lib/capybara/selector/definition/css.rb +1 -1
  44. data/lib/capybara/selector/definition/datalist_input.rb +1 -1
  45. data/lib/capybara/selector/definition/element.rb +2 -1
  46. data/lib/capybara/selector/definition/fillable_field.rb +1 -1
  47. data/lib/capybara/selector/definition/label.rb +1 -1
  48. data/lib/capybara/selector/definition/link.rb +8 -0
  49. data/lib/capybara/selector/definition/select.rb +1 -1
  50. data/lib/capybara/selector/definition/table.rb +1 -1
  51. data/lib/capybara/selector/definition/table_row.rb +2 -2
  52. data/lib/capybara/selector/filter_set.rb +2 -2
  53. data/lib/capybara/selector/selector.rb +9 -1
  54. data/lib/capybara/selenium/atoms/src/isDisplayed.js +1 -1
  55. data/lib/capybara/selenium/driver.rb +51 -7
  56. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +9 -11
  57. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -11
  58. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +3 -3
  59. data/lib/capybara/selenium/extensions/find.rb +4 -4
  60. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  61. data/lib/capybara/selenium/logger_suppressor.rb +1 -1
  62. data/lib/capybara/selenium/node.rb +23 -6
  63. data/lib/capybara/selenium/nodes/chrome_node.rb +23 -5
  64. data/lib/capybara/selenium/nodes/firefox_node.rb +7 -2
  65. data/lib/capybara/selenium/nodes/safari_node.rb +1 -1
  66. data/lib/capybara/selenium/patches/action_pauser.rb +4 -1
  67. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  68. data/lib/capybara/selenium/patches/logs.rb +7 -9
  69. data/lib/capybara/server/animation_disabler.rb +8 -3
  70. data/lib/capybara/server/middleware.rb +4 -2
  71. data/lib/capybara/session.rb +23 -14
  72. data/lib/capybara/session/config.rb +3 -1
  73. data/lib/capybara/session/matchers.rb +11 -11
  74. data/lib/capybara/spec/public/test.js +13 -1
  75. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  76. data/lib/capybara/spec/session/check_spec.rb +6 -0
  77. data/lib/capybara/spec/session/click_button_spec.rb +11 -0
  78. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  79. data/lib/capybara/spec/session/has_button_spec.rb +51 -0
  80. data/lib/capybara/spec/session/has_css_spec.rb +2 -1
  81. data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
  82. data/lib/capybara/spec/session/has_field_spec.rb +16 -0
  83. data/lib/capybara/spec/session/has_select_spec.rb +4 -4
  84. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  85. data/lib/capybara/spec/session/has_text_spec.rb +0 -11
  86. data/lib/capybara/spec/session/html_spec.rb +1 -1
  87. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  88. data/lib/capybara/spec/session/node_spec.rb +29 -9
  89. data/lib/capybara/spec/session/refresh_spec.rb +2 -1
  90. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  91. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
  92. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  93. data/lib/capybara/spec/session/window/window_spec.rb +1 -1
  94. data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
  95. data/lib/capybara/spec/spec_helper.rb +12 -12
  96. data/lib/capybara/spec/test_app.rb +23 -21
  97. data/lib/capybara/spec/views/form.erb +28 -1
  98. data/lib/capybara/spec/views/with_animation.erb +8 -0
  99. data/lib/capybara/spec/views/with_dragula.erb +3 -1
  100. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  101. data/lib/capybara/spec/views/with_js.erb +3 -0
  102. data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
  103. data/lib/capybara/version.rb +1 -1
  104. data/lib/capybara/window.rb +3 -7
  105. data/spec/basic_node_spec.rb +9 -8
  106. data/spec/capybara_spec.rb +1 -1
  107. data/spec/dsl_spec.rb +14 -1
  108. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  109. data/spec/minitest_spec.rb +3 -2
  110. data/spec/rack_test_spec.rb +16 -5
  111. data/spec/result_spec.rb +1 -17
  112. data/spec/rspec/features_spec.rb +3 -1
  113. data/spec/rspec/scenarios_spec.rb +4 -0
  114. data/spec/rspec/shared_spec_matchers.rb +63 -51
  115. data/spec/rspec_spec.rb +4 -0
  116. data/spec/selector_spec.rb +17 -2
  117. data/spec/selenium_spec_chrome.rb +39 -20
  118. data/spec/selenium_spec_chrome_remote.rb +5 -1
  119. data/spec/selenium_spec_firefox.rb +15 -13
  120. data/spec/server_spec.rb +60 -49
  121. data/spec/shared_selenium_node.rb +10 -0
  122. data/spec/shared_selenium_session.rb +98 -7
  123. data/spec/spec_helper.rb +1 -1
  124. metadata +50 -15
  125. data/lib/capybara/spec/session/source_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f60918220b590a4a64f3bb1a42b7e8c5dac86dddcec48d46c0f92c1ac6c491f
4
- data.tar.gz: aab5f09c11d94dc1becdb514d753011cdfad7f2a43f0e59b074ff6e69aa49847
3
+ metadata.gz: 00bf1cfd1e72093422fb61df1dae86d72948e8026d57fb00084d5bedceb0967e
4
+ data.tar.gz: 65a8c6b66d1ef91586ca39f7eabcf800019f853e33e087d1bb65f02a85140c8b
5
5
  SHA512:
6
- metadata.gz: 7adcf8fbe5fe95d42c3c7fe513f62236cf93dd0f95bbccb20d31c1022a5e87bd64514d2fd6f57a263d31b96945a2e1c7a300d6b16db018651b929abd137e8290
7
- data.tar.gz: d28874576cd8613f16b1d455785e4e6fba9cb387b8580ba0bdc0c46f13255661f07e47a51f5d7f2c28afa6691a4c330e094ff9625a89bb4f6f5d9532a3123063
6
+ metadata.gz: f961de052aa75cb3e3a941ea031d40d6d0f1fc2a9a80190c7dbe2f7d8e96b462fa71d4ed96d4dc45687e2baaf151579ca4508a2753a6e2073814857e2dee9bb4
7
+ data.tar.gz: 4b02c84f7bd1d9da419e3f43848da87290ba303541df516e6217fd3fc2e4cf5263e212e9a4a5329c8505b2f6111c0ce6ea17537ea3099b04f12c9b662d364088
data/History.md CHANGED
@@ -1,10 +1,94 @@
1
+ # Version 3.35.0
2
+ Release date: 2020-01-25
3
+
4
+ ### Added
5
+
6
+ * Support Regexp matching for individual class names in :class filter passed an Array
7
+ * Animation disabler now supports JQuery animation disabling when JQuery loaded from body [Chien-Wei Huang]
8
+
9
+ ### Fixed
10
+
11
+ * :button selector type use with `enable_aria_role` [Sean Doyle]
12
+ * <label> elements don't associate with aria-role buttons
13
+ * Ignore Selenium::WebDriver::Error::InvalidSessionIdError when quitting driver [Robin Daugherty]
14
+ * Firefox: Don't click input when sending keys if already focused
15
+ * Miscellaneous issues with selenium-webdriver 4.0.0.alphas
16
+ * Nil return error in node details optimizations
17
+ * Animation disabler now inserts XHTML compliant content [Dale Morgan]
18
+
19
+ # Version 3.34.0
20
+ Release date: 2020-11-26
21
+
22
+ ### Added
23
+
24
+ * Ability to fill in with emoji when using Chrome with selenium driver (Firefox already worked)
25
+ * Current path assertions/expectations accept optional filter block
26
+ * Animation disabler now specifies `scroll-behavior: auto;` [Nathan Broadbent]
27
+ * :button selector can now find elements by label text [Sean Doyle]
28
+ * `Session#send_keys` to send keys to the current element with focus in drivers that support the
29
+ concept of a current element [Sean Doyle]
30
+
31
+ ### Changed
32
+
33
+ * Text query validates the type parameter to prevent undefined behavior
34
+
35
+ ### Fixed
36
+
37
+ * racktest driver better handles fragments and redirection to urls that include fragments
38
+ * Don't error when attempting to get XPath location of a shadow element
39
+ * Missing `readonly?` added to Node::Simple
40
+ * Selenium version detection when loaded via alternate method [Joel Hawksley]
41
+ * Connection count issue if REQUEST_URI value changed by app [Blake Williams]
42
+ * Maintain URI fragment when redirecting in rack-test driver
43
+ * Text query error message [Wojciech Wnętrzak]
44
+ * Checking a checkbox/radio button with `allow_label_click` now works if there are multiple labels (Issue #2421)
45
+ * `drop` with `Pathname` (Issue #2424)[Máximo Mussini]
46
+
47
+ # Version 3.33.0
48
+ Release date: 2020-06-21
49
+
50
+ ### Added
51
+
52
+ * Block passed to `within_session` now receives the new and old session
53
+ * Support for aria-role button when enabled [Seiei Miyagi]
54
+ * Support for aria-role link when enabled
55
+ * Support for `validation_message` filter with :field and :fillable_field selectors
56
+ * Deprecation warnings show source location [Koichi ITO]
57
+
58
+ ### Changed
59
+
60
+ * Ruby 2.5.0+ is now required
61
+ * Deprecated direct manipulation of the driver and server registries
62
+
63
+ ### Fixed
64
+
65
+ * Ruby 2.7 warning in minitest `assert_text` [Eileen M. Uchitelle]
66
+
67
+
68
+ # Version 3.32.2
69
+ Release date: 2020-05-16
70
+
71
+ ### Fixed
72
+
73
+ * Don't use lazy enumerator with JRuby due to leaking threads
74
+ * Ruby 2.7 deprecation warning when registering Webrick [Jon Zeppieri]
75
+ * `have_text` description [Juan Pablo Rinaldi]
76
+
77
+ # Version 3.32.1
78
+ Release date: 2020-04-05
79
+
80
+ ### Fixed
81
+
82
+ * Rapid set now respects field maxlength (Issue #2332)
83
+ * Only patch pause into legacy actions in Selenium < 4 (Issue #2334)
84
+
1
85
  # Version 3.32.0
2
- Relesae date: 2020-03-29
86
+ Release date: 2020-03-29
3
87
 
4
88
  ### Added
5
89
 
6
90
  * Support `delay` setting on click with Selenium
7
- * Implement rapid set for values longer thn 30 characters in text fields with Selenium
91
+ * Implement rapid set for values longer than 30 characters in text fields with Selenium
8
92
 
9
93
  ### Fixed
10
94
 
@@ -125,8 +209,8 @@ Release date: 2019-06-27
125
209
 
126
210
  ### Fixed
127
211
 
128
- * Woraround issue with chromedriver 76/77 in W3C mode losing mouse state during legacy drag. Only fixed if
129
- both source and target are simultaenously inside the viewport - Issue #2223
212
+ * Work around issue with chromedriver 76/77 in W3C mode losing mouse state during legacy drag. Only fixed if
213
+ both source and target are simultaneously inside the viewport - Issue #2223
130
214
  * Negative ancestor expectations/predicates were incorrectly checking siblings rather than ancestors
131
215
 
132
216
  # Version 3.24.0
@@ -405,7 +489,7 @@ Release date: 2018-10-23
405
489
 
406
490
  ### Fixed
407
491
 
408
- * Selector `css` expression definiton declared filters now work again
492
+ * Selector `css` expression definition declared filters now work again
409
493
  * Cleaned up warnings [Yuji Yaginuma]
410
494
  * Workaround installation of rspec matcher proxies under jruby by reverting to the old solution not using prepend, so jruby bugs are not hit - Issue #2115
411
495
 
@@ -522,7 +606,7 @@ Release date: 2018-07-19
522
606
 
523
607
  ### Fixed
524
608
 
525
- * Make selenium driver :backspace clear stategy work even if caret location is in middle of field content [Champier Cyril]
609
+ * Make selenium driver :backspace clear strategy work even if caret location is in middle of field content [Champier Cyril]
526
610
  * Selenium issue with fieldset nested in disabled fieldset not being considered disabled
527
611
  * `Session#evaluate_script` and `Element#evaluate_script` now strip leading/trailing whitespace from scripts [Ian Lesperance]
528
612
 
@@ -621,7 +705,7 @@ Release date: 2018-04-13
621
705
  ### Fixes
622
706
 
623
707
  * Fix expression filter descriptions in some selector failure messages
624
- * Fix compounding of negated matechers - Issue #2010
708
+ * Fix compounding of negated matchers - Issue #2010
625
709
 
626
710
  # Version 3.0.1
627
711
  Release date: 2018-04-06
@@ -895,7 +979,7 @@ Release date: 2016-12-05
895
979
  * Options for clearing session/local storage on reset added to the Selenium driver
896
980
  * Window size changes wait for the size to stabilize
897
981
  * Defined return value for most actions
898
- * Ignore specific error when qutting selenium driver instance - Issue #1773 [Dylan Reichstadt, Thomas Walpole]
982
+ * Ignore specific error when quitting selenium driver instance - Issue #1773 [Dylan Reichstadt, Thomas Walpole]
899
983
  * Warn on selenium unknown errors rather than raising when quitting driver [Adam Pohorecki, Thomas Walpole]
900
984
  * Capybara::Result#each now returns an `Enumerator` when called without a block - Issue #1777 [Thomas Walpole]
901
985
 
@@ -957,7 +1041,7 @@ Release date: 2016-09-19
957
1041
 
958
1042
  ### Fixed
959
1043
 
960
- * Issue with rack-test driver and obselete mime-types when using `#attach_file` - Issue #1756 [Thomas Walpole]
1044
+ * Issue with rack-test driver and obsolete mime-types when using `#attach_file` - Issue #1756 [Thomas Walpole]
961
1045
 
962
1046
  ### Added
963
1047
 
@@ -1024,7 +1108,7 @@ Release date: 2016-04-07
1024
1108
 
1025
1109
  ### Added
1026
1110
 
1027
- * Capybara now waits for requests to Capybaras server to complete while restting the session [John Hawthorn, Thomas Walpole]
1111
+ * Capybara now waits for requests to Capybaras server to complete while resetting the session [John Hawthorn, Thomas Walpole]
1028
1112
  * Capybara.reuse_server option to allow disabling of sharing server instance between sessions [Thomas Walpole]
1029
1113
  * :multiple filter added to relevant selectors [Thomas Walpole]
1030
1114
  * Provided server registrations for :webrick and :puma. Capybara.server = :puma for testing with Rails 5 [Thomas Walpole]
@@ -1038,7 +1122,7 @@ Release date: 2016-04-07
1038
1122
 
1039
1123
  # Version 2.6.2
1040
1124
 
1041
- Relase date: 2016-01-27
1125
+ Release date: 2016-01-27
1042
1126
 
1043
1127
  ### Fixed
1044
1128
 
@@ -1584,8 +1668,8 @@ Release date: 2011-06-14
1584
1668
  * Rack::Test driver honours maxlength on input fields [Guilherme Carvalho]
1585
1669
  * Rack::Test now works as expected with domains and subdomains [Jonas Nicklas]
1586
1670
  * Session is reset more thoroughly between tests. [Jonas Nicklas]
1587
- * Raise error when uploading non-existant file [Jonas Nicklas]
1588
- * Rack reponse body should respond to #each [Piotr Sarnacki]
1671
+ * Raise error when uploading non-existent file [Jonas Nicklas]
1672
+ * Rack response body should respond to #each [Piotr Sarnacki]
1589
1673
  * Deprecation warnings with selenium webdriver 0.2.0 [Aaron Gibraltar]
1590
1674
  * Selenium Chrome no longer YELLS tagname [Carl Jackson & David W. Frank]
1591
1675
  * Capybara no longer strips encoding before sending to Rack [Jonas Nicklas]
@@ -1727,7 +1811,7 @@ Release date: 2010-05-12
1727
1811
 
1728
1812
  Release date: 2010-04-09
1729
1813
 
1730
- This is a drop in compatible maintainance release. It's mostly
1814
+ This is a drop in compatible maintenance release. It's mostly
1731
1815
  important for driver authors.
1732
1816
 
1733
1817
  ### Added
@@ -1746,7 +1830,7 @@ important for driver authors.
1746
1830
 
1747
1831
  Release date: 2010-03-22
1748
1832
 
1749
- This is a maintainance release with minor bug fixes, should be
1833
+ This is a maintenance release with minor bug fixes, should be
1750
1834
  drop in compatible.
1751
1835
 
1752
1836
  ### Added
data/README.md CHANGED
@@ -7,8 +7,6 @@
7
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
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)
9
9
 
10
- **Note** You are viewing the README for the 3.32.x version of Capybara.
11
-
12
10
  Capybara helps you test web applications by simulating how a real user would
13
11
  interact with your app. It is agnostic about the driver running your tests and
14
12
  comes with Rack::Test and Selenium support built in. WebKit is supported
@@ -76,7 +74,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
76
74
 
77
75
  ## <a name="setup"></a>Setup
78
76
 
79
- Capybara requires Ruby 2.4.0 or later. To install, add this line to your
77
+ Capybara requires Ruby 2.5.0 or later. To install, add this line to your
80
78
  `Gemfile` and run `bundle install`:
81
79
 
82
80
  ```ruby
@@ -149,7 +147,7 @@ require 'capybara/rspec'
149
147
 
150
148
  If you are using Rails, put your Capybara specs in `spec/features` or `spec/system` (only works
151
149
  if [you have it configured in
152
- RSpec](https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#file-type-inference-disabled))
150
+ RSpec](https://relishapp.com/rspec/rspec-rails/v/4-0/docs/directory-structure))
153
151
  and if you have your Capybara specs in a different directory, then tag the
154
152
  example groups with `type: :feature` or `type: :system` depending on which type of test you're writing.
155
153
 
@@ -1055,6 +1053,13 @@ additional info about how the underlying driver can be configured.
1055
1053
  are testing for specific server errors and using multiple sessions make sure to test for the
1056
1054
  errors using the initial session (usually :default)
1057
1055
 
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
+
1058
1063
  ## <a name="threadsafe"></a>"Threadsafe" mode
1059
1064
 
1060
1065
  In normal mode most of Capybara's configuration options are global settings which can cause issues
@@ -5,6 +5,7 @@ require 'nokogiri'
5
5
  require 'xpath'
6
6
  require 'forwardable'
7
7
  require 'capybara/config'
8
+ require 'capybara/registration_container'
8
9
 
9
10
  module Capybara
10
11
  class CapybaraError < StandardError; end
@@ -81,6 +82,7 @@ module Capybara
81
82
  # - **default_selector** (`:css`, `:xpath` = `:css`) - Methods which take a selector use the given type by default. See also {Capybara::Selector}.
82
83
  # - **default_set_options** (Hash = `{}`) - The default options passed to {Capybara::Node::Element#set Element#set}.
83
84
  # - **enable_aria_label** (Boolean = `false`) - Whether fields, links, and buttons will match against `aria-label` attribute.
85
+ # - **enable_aria_role** (Boolean = `false`) - Selectors will check for relevant aria role (currently only `button`).
84
86
  # - **exact** (Boolean = `false`) - Whether locators are matched exactly or with substrings. Only affects selector conditions
85
87
  # written using the `XPath#is` method.
86
88
  # - **exact_text** (Boolean = `false`) - Whether the text matchers and `:text` filter match exactly or on substrings.
@@ -93,6 +95,7 @@ module Capybara
93
95
  # - **save_path** (String = `Dir.pwd`) - Where to put pages saved through {Capybara::Session#save_page save_page}, {Capybara::Session#save_screenshot save_screenshot},
94
96
  # {Capybara::Session#save_and_open_page save_and_open_page}, or {Capybara::Session#save_and_open_screenshot save_and_open_screenshot}.
95
97
  # - **server** (Symbol = `:default` (which uses puma)) - The name of the registered server to use when running the app under test.
98
+ # - **server_port** (Integer) - The port Capybara will run the application server on, if not specified a random port will be used.
96
99
  # - **server_errors** (Array\<Class> = `[Exception]`) - Error classes that should be raised in the tests if they are raised in the server
97
100
  # and {configure raise_server_errors} is `true`.
98
101
  # - **test_id** (Symbol, String, `nil` = `nil`) - Optional attribute to match locator against with built-in selectors along with id.
@@ -124,7 +127,7 @@ module Capybara
124
127
  # @yieldreturn [Capybara::Driver::Base] A Capybara driver instance
125
128
  #
126
129
  def register_driver(name, &block)
127
- drivers[name] = block
130
+ drivers.send(:register, name, block)
128
131
  end
129
132
 
130
133
  ##
@@ -143,7 +146,7 @@ module Capybara
143
146
  # @yieldparam host The host/ip to bind to
144
147
  #
145
148
  def register_server(name, &block)
146
- servers[name.to_sym] = block
149
+ servers.send(:register, name.to_sym, block)
147
150
  end
148
151
 
149
152
  ##
@@ -197,11 +200,11 @@ module Capybara
197
200
  end
198
201
 
199
202
  def drivers
200
- @drivers ||= {}
203
+ @drivers ||= RegistrationContainer.new
201
204
  end
202
205
 
203
206
  def servers
204
- @servers ||= {}
207
+ @servers ||= RegistrationContainer.new
205
208
  end
206
209
 
207
210
  # Wraps the given string, which should contain an HTML document or fragment
@@ -349,7 +352,8 @@ module Capybara
349
352
  #
350
353
  # Yield a block using a specific session name or {Capybara::Session} instance.
351
354
  #
352
- def using_session(name_or_session)
355
+ def using_session(name_or_session, &block)
356
+ previous_session = current_session
353
357
  previous_session_info = {
354
358
  specified_session: specified_session,
355
359
  session_name: session_name,
@@ -362,7 +366,12 @@ module Capybara
362
366
  else
363
367
  self.session_name = name_or_session
364
368
  end
365
- yield
369
+
370
+ if block.arity.zero?
371
+ yield
372
+ else
373
+ yield current_session, previous_session
374
+ end
366
375
  ensure
367
376
  self.session_name, self.specified_session = previous_session_info.values_at(:session_name, :specified_session)
368
377
  self.current_driver, self.app = previous_session_info.values_at(:current_driver, :app) if threadsafe
@@ -394,7 +403,7 @@ module Capybara
394
403
  template.inner_html = ''
395
404
  end
396
405
  document.xpath('//textarea').each do |textarea|
397
- textarea['_capybara_raw_value'] = textarea.content.sub(/\A\n/, '')
406
+ textarea['_capybara_raw_value'] = textarea.content.delete_prefix("\n")
398
407
  end
399
408
  end
400
409
  end
@@ -475,7 +484,7 @@ module Capybara
475
484
  require 'capybara/rack_test/node'
476
485
  require 'capybara/rack_test/form'
477
486
  require 'capybara/rack_test/browser'
478
- require 'capybara/rack_test/css_handlers.rb'
487
+ require 'capybara/rack_test/css_handlers'
479
488
 
480
489
  require 'capybara/selenium/node'
481
490
  require 'capybara/selenium/driver'
@@ -501,6 +510,7 @@ Capybara.configure do |config|
501
510
  config.visible_text_only = false
502
511
  config.automatic_label_click = false
503
512
  config.enable_aria_label = false
513
+ config.enable_aria_role = false
504
514
  config.reuse_server = true
505
515
  config.default_set_options = {}
506
516
  config.test_id = nil
@@ -9,11 +9,9 @@ module Capybara
9
9
 
10
10
  OPTIONS = %i[app reuse_server threadsafe server default_driver javascript_driver allow_gumbo].freeze
11
11
 
12
- attr_accessor :app
13
- attr_reader :reuse_server, :threadsafe
14
- attr_reader :session_options
12
+ attr_accessor :app, :allow_gumbo
13
+ attr_reader :reuse_server, :threadsafe, :session_options
15
14
  attr_writer :default_driver, :javascript_driver
16
- attr_accessor :allow_gumbo
17
15
 
18
16
  SessionConfig::OPTIONS.each do |method|
19
17
  def_delegators :session_options, method, "#{method}="
@@ -83,10 +81,10 @@ module Capybara
83
81
  @javascript_driver || :selenium
84
82
  end
85
83
 
86
- def deprecate(method, alternate_method, once = false)
84
+ def deprecate(method, alternate_method, once: false)
87
85
  @deprecation_notified ||= {}
88
86
  unless once && @deprecation_notified[method]
89
- warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead"
87
+ Capybara::Helpers.warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead: #{Capybara::Helpers.filter_backtrace(caller)}"
90
88
  end
91
89
  @deprecation_notified[method] = true
92
90
  end
@@ -22,6 +22,6 @@ end
22
22
  Before do |scenario|
23
23
  scenario.source_tag_names.each do |tag|
24
24
  driver_name = tag.sub(/^@/, '').to_sym
25
- Capybara.current_driver = driver_name if Capybara.drivers.key?(driver_name)
25
+ Capybara.current_driver = driver_name if Capybara.drivers[driver_name]
26
26
  end
27
27
  end
@@ -59,6 +59,10 @@ class Capybara::Driver::Base
59
59
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#status_code'
60
60
  end
61
61
 
62
+ def send_keys(*)
63
+ raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#send_keys'
64
+ end
65
+
62
66
  ##
63
67
  #
64
68
  # @param frame [Capybara::Node::Element, :parent, :top] The iframe element to switch to
@@ -15,7 +15,7 @@ module Capybara
15
15
  # @return [String] Normalized text
16
16
  #
17
17
  def normalize_whitespace(text)
18
- warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
18
+ Capybara::Helpers.warn 'DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver'
19
19
  text.to_s.gsub(/[[:space:]]+/, ' ').strip
20
20
  end
21
21
 
@@ -70,6 +70,30 @@ module Capybara
70
70
  count == 1 ? singular : plural
71
71
  end
72
72
 
73
+ def filter_backtrace(trace)
74
+ return 'No backtrace' unless trace
75
+
76
+ filter = %r{lib/capybara/|lib/rspec/|lib/minitest/}
77
+ new_trace = trace.take_while { |line| line !~ filter }
78
+ new_trace = trace.reject { |line| line =~ filter } if new_trace.empty?
79
+ new_trace = trace.dup if new_trace.empty?
80
+
81
+ new_trace.first.split(/:in /, 2).first
82
+ end
83
+
84
+ def warn(message, uplevel: 1)
85
+ return Kernel.warn(message, uplevel: uplevel) if RUBY_VERSION >= '2.6'
86
+
87
+ # TODO: Remove when we drop support for Ruby 2.5
88
+ # Workaround for emulating `warn '...', uplevel: n` in Ruby 2.5 or lower.
89
+ if (match = /^(?<file>.+?):(?<line>\d+)(?::in `.*')?/.match(caller[uplevel]))
90
+ location = [match[:file], match[:line]].join(':')
91
+ Kernel.warn "#{location}: #{message}"
92
+ else
93
+ Kernel.warn message
94
+ end
95
+ end
96
+
73
97
  if defined?(Process::CLOCK_MONOTONIC)
74
98
  def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end
75
99
  else
@@ -50,15 +50,14 @@ module Capybara
50
50
 
51
51
  %w[text no_text title no_title current_path no_current_path].each do |assertion_name|
52
52
  class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
53
- def assert_#{assertion_name} *args
53
+ def assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
54
54
  self.assertions +=1
55
55
  subject, args = determine_subject(args)
56
- subject.assert_#{assertion_name}(*args)
56
+ subject.assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
57
57
  rescue Capybara::ExpectationNotMet => e
58
58
  raise ::Minitest::Assertion, e.message
59
59
  end
60
60
  ASSERTION
61
- ruby2_keywords "assert_#{assertion_name}" if respond_to?(:ruby2_keywords)
62
61
  end
63
62
 
64
63
  alias_method :refute_title, :assert_no_title