capybara 3.31.0 → 3.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +93 -13
  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 +215 -141
  10. data/lib/capybara/minitest/spec.rb +156 -97
  11. data/lib/capybara/node/actions.rb +16 -21
  12. data/lib/capybara/node/element.rb +3 -5
  13. data/lib/capybara/node/finders.rb +7 -6
  14. data/lib/capybara/node/matchers.rb +11 -11
  15. data/lib/capybara/node/simple.rb +5 -1
  16. data/lib/capybara/queries/ancestor_query.rb +1 -1
  17. data/lib/capybara/queries/current_path_query.rb +14 -4
  18. data/lib/capybara/queries/selector_query.rb +16 -10
  19. data/lib/capybara/queries/sibling_query.rb +1 -1
  20. data/lib/capybara/queries/style_query.rb +1 -1
  21. data/lib/capybara/queries/text_query.rb +7 -1
  22. data/lib/capybara/rack_test/browser.rb +9 -3
  23. data/lib/capybara/rack_test/driver.rb +1 -0
  24. data/lib/capybara/rack_test/form.rb +1 -1
  25. data/lib/capybara/rack_test/node.rb +1 -1
  26. data/lib/capybara/registration_container.rb +44 -0
  27. data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
  28. data/lib/capybara/registrations/servers.rb +2 -1
  29. data/lib/capybara/result.rb +8 -8
  30. data/lib/capybara/rspec.rb +2 -0
  31. data/lib/capybara/rspec/matcher_proxies.rb +5 -5
  32. data/lib/capybara/rspec/matchers.rb +7 -6
  33. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  34. data/lib/capybara/rspec/matchers/have_text.rb +1 -1
  35. data/lib/capybara/rspec/matchers/match_style.rb +5 -0
  36. data/lib/capybara/selector.rb +10 -1
  37. data/lib/capybara/selector/definition.rb +11 -9
  38. data/lib/capybara/selector/definition/button.rb +8 -5
  39. data/lib/capybara/selector/definition/css.rb +1 -1
  40. data/lib/capybara/selector/definition/datalist_input.rb +1 -1
  41. data/lib/capybara/selector/definition/element.rb +2 -1
  42. data/lib/capybara/selector/definition/fillable_field.rb +1 -1
  43. data/lib/capybara/selector/definition/label.rb +1 -1
  44. data/lib/capybara/selector/definition/link.rb +8 -0
  45. data/lib/capybara/selector/definition/select.rb +1 -1
  46. data/lib/capybara/selector/definition/table.rb +1 -1
  47. data/lib/capybara/selector/definition/table_row.rb +1 -1
  48. data/lib/capybara/selector/filter_set.rb +2 -2
  49. data/lib/capybara/selector/selector.rb +9 -1
  50. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  51. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  52. data/lib/capybara/selenium/driver.rb +35 -6
  53. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +9 -11
  54. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -11
  55. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +3 -3
  56. data/lib/capybara/selenium/extensions/find.rb +3 -3
  57. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  58. data/lib/capybara/selenium/node.rb +75 -12
  59. data/lib/capybara/selenium/nodes/chrome_node.rb +20 -11
  60. data/lib/capybara/selenium/nodes/firefox_node.rb +2 -2
  61. data/lib/capybara/selenium/nodes/safari_node.rb +1 -1
  62. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  63. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  64. data/lib/capybara/selenium/patches/logs.rb +7 -9
  65. data/lib/capybara/server/animation_disabler.rb +3 -2
  66. data/lib/capybara/server/middleware.rb +4 -2
  67. data/lib/capybara/session.rb +23 -14
  68. data/lib/capybara/session/config.rb +3 -1
  69. data/lib/capybara/session/matchers.rb +11 -11
  70. data/lib/capybara/spec/public/test.js +24 -1
  71. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  72. data/lib/capybara/spec/session/check_spec.rb +6 -0
  73. data/lib/capybara/spec/session/click_button_spec.rb +11 -0
  74. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  75. data/lib/capybara/spec/session/fill_in_spec.rb +9 -0
  76. data/lib/capybara/spec/session/find_spec.rb +11 -8
  77. data/lib/capybara/spec/session/has_button_spec.rb +18 -0
  78. data/lib/capybara/spec/session/has_css_spec.rb +11 -7
  79. data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
  80. data/lib/capybara/spec/session/has_field_spec.rb +16 -0
  81. data/lib/capybara/spec/session/has_select_spec.rb +4 -4
  82. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  83. data/lib/capybara/spec/session/has_text_spec.rb +0 -11
  84. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  85. data/lib/capybara/spec/session/node_spec.rb +76 -29
  86. data/lib/capybara/spec/session/refresh_spec.rb +1 -0
  87. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  88. data/lib/capybara/spec/session/window/window_spec.rb +7 -7
  89. data/lib/capybara/spec/spec_helper.rb +13 -14
  90. data/lib/capybara/spec/test_app.rb +22 -21
  91. data/lib/capybara/spec/views/form.erb +25 -1
  92. data/lib/capybara/spec/views/with_animation.erb +8 -0
  93. data/lib/capybara/spec/views/with_dragula.erb +3 -1
  94. data/lib/capybara/spec/views/with_html.erb +2 -2
  95. data/lib/capybara/spec/views/with_js.erb +2 -0
  96. data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
  97. data/lib/capybara/version.rb +1 -1
  98. data/lib/capybara/window.rb +3 -7
  99. data/spec/basic_node_spec.rb +9 -8
  100. data/spec/capybara_spec.rb +1 -1
  101. data/spec/dsl_spec.rb +14 -1
  102. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  103. data/spec/minitest_spec.rb +3 -2
  104. data/spec/rack_test_spec.rb +28 -5
  105. data/spec/regexp_dissassembler_spec.rb +0 -4
  106. data/spec/result_spec.rb +38 -31
  107. data/spec/rspec/features_spec.rb +3 -1
  108. data/spec/rspec/scenarios_spec.rb +4 -0
  109. data/spec/rspec/shared_spec_matchers.rb +63 -51
  110. data/spec/rspec_spec.rb +4 -0
  111. data/spec/selector_spec.rb +2 -1
  112. data/spec/selenium_spec_chrome.rb +4 -2
  113. data/spec/selenium_spec_chrome_remote.rb +2 -0
  114. data/spec/server_spec.rb +56 -49
  115. data/spec/shared_selenium_node.rb +18 -0
  116. data/spec/shared_selenium_session.rb +84 -7
  117. data/spec/spec_helper.rb +1 -1
  118. metadata +25 -24
  119. 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: dd31d35629d475d7fdaba1d6e415599d995a08f27b28fa619a3a4449b61b91d8
4
- data.tar.gz: 27c812629e2d99e8f4c62fa7961df9b499c5346b1c61092faf487f592356033d
3
+ metadata.gz: 73f13e5f3cec460ee010f53337dcbf2d7e692a3b5c557110331d81c75f5f2897
4
+ data.tar.gz: e137144d97fdb0c47a0464c07c4d12a39c36d62cc3c30aaa9201ed5676b2c66f
5
5
  SHA512:
6
- metadata.gz: 946e3f2de0137ddaa6e3a2febba2c87244997737c54a10024133de110ca41b8aeddcb66e0437bef5d826e9fe21d4c42701674c3864bd578d24c30c7b1f90e2a9
7
- data.tar.gz: f9409de3e2e0ea44e0bb6b6f77cce7e0e8f5a4d95c43fb62af2eb63d11e755d6a8c00b9b9b4d2bbe2729538d0d1038e92468e0a7994d1578b50e05b5227b87f4
6
+ metadata.gz: 8130baab61559c5221035964a776d72ab84a119be31a6b6534de14ca3ebb5ca1cdcd128ad2cd7d004c45d3ff5c7de0103a756cc3fdcf19fb154d874c876883a5
7
+ data.tar.gz: 2379315a8629b50b0681fea69eb603d62d44c058df355f52151e319701d7577e5691fa43283848d0068c769bbd8be0a7890ddac904e7d7aa67e6be0a46261b7d
data/History.md CHANGED
@@ -1,3 +1,83 @@
1
+ # Version 3.34.0
2
+ Release date: 2020-11-26
3
+
4
+ ### Added
5
+
6
+ * Ability to fill in with emoji when using Chrome with selenium driver (Firefox already worked)
7
+ * Current path assetsions/expectations accept optional filter block
8
+ * Animation disabler now specifies `scroll-behavior: auto;` [Nathan Broadbent]
9
+ * :button selector can now find elements by label text [Sean Doyle]
10
+ * `Session#send_keys` to send keys to the current element with focus in drivers that support the
11
+ concept of a current element [Sean Doyle]
12
+
13
+ ### Changed
14
+
15
+ * Text query validates the type parameter to prevent undefined behavior
16
+
17
+ ### Fixed
18
+
19
+ * racktest driver better handles fragments and redirection to urls that include fragments
20
+ * Don't error when attempting to get XPath location of a shadow element
21
+ * Missing `readonly?` added to Node::Simple
22
+ * Selenium version detection when loaded via alternate method [Joel Hawksley]
23
+ * Connection count issue if REQUEST_URI value changed by app [Blake Williams]
24
+ * Maintain URI fragment when redirecting in rack-test driver
25
+ * Text query error message [Wojciech Wnętrzak]
26
+ * Checking a checkbox/radio button with `allow_label_click` now works if there are multiple labels (Issue #2421)
27
+ * `drop` with `Pathname` (Issue #2424)[Máximo Mussini]
28
+
29
+ # Version 3.33.0
30
+ Release date: 2020-06-21
31
+
32
+ ### Added
33
+
34
+ * Block passed to `within_session` now receives the new and old session
35
+ * Support for aria-role button when enabled [Seiei Miyagi]
36
+ * Support for aria-role link when enabled
37
+ * Support for `validation_message` filter with :field and :fillable_field selectors
38
+ * Deprecation warnings show source location [Koichi ITO]
39
+
40
+ ### Changed
41
+
42
+ * Ruby 2.5.0+ is now required
43
+ * Deprecated direct manipulation of the driver and server registries
44
+
45
+ ### Fixed
46
+
47
+ * Ruby 2.7 warning in minitest `assert_text` [Eileen M. Uchitelle]
48
+
49
+
50
+ # Version 3.32.2
51
+ Release date: 2020-05-16
52
+
53
+ ### Fixed
54
+
55
+ * Don't use lazy enumerator with JRuby due to leaking threads
56
+ * Ruby 2.7 deprecation warning when registering Webrick [Jon Zeppieri]
57
+ * `have_text` description [Juan Pablo Rinaldi]
58
+
59
+ # Version 3.32.1
60
+ Release date: 2020-04-05
61
+
62
+ ### Fixed
63
+
64
+ * Rapid set now respects field maxlength (Issue #2332)
65
+ * Only patch pause into legacy actions in Selenium < 4 (Issue #2334)
66
+
67
+ # Version 3.32.0
68
+ Release date: 2020-03-29
69
+
70
+ ### Added
71
+
72
+ * Support `delay` setting on click with Selenium
73
+ * Implement rapid set for values longer than 30 characters in text fields with Selenium
74
+
75
+ ### Fixed
76
+
77
+ * Result#[] and negative max on ranges (Issue #2302/2303) [Jeremy Evans]
78
+ * RackTest form submission rewrites query string when using GET method
79
+ * Ruby 2.7 deprecation warnings in RSpec matcher proxies
80
+
1
81
  # Version 3.31.0
2
82
  Release date: 2020-01-26
3
83
 
@@ -111,8 +191,8 @@ Release date: 2019-06-27
111
191
 
112
192
  ### Fixed
113
193
 
114
- * Woraround issue with chromedriver 76/77 in W3C mode losing mouse state during legacy drag. Only fixed if
115
- both source and target are simultaenously inside the viewport - Issue #2223
194
+ * Work around issue with chromedriver 76/77 in W3C mode losing mouse state during legacy drag. Only fixed if
195
+ both source and target are simultaneously inside the viewport - Issue #2223
116
196
  * Negative ancestor expectations/predicates were incorrectly checking siblings rather than ancestors
117
197
 
118
198
  # Version 3.24.0
@@ -391,7 +471,7 @@ Release date: 2018-10-23
391
471
 
392
472
  ### Fixed
393
473
 
394
- * Selector `css` expression definiton declared filters now work again
474
+ * Selector `css` expression definition declared filters now work again
395
475
  * Cleaned up warnings [Yuji Yaginuma]
396
476
  * 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
397
477
 
@@ -508,7 +588,7 @@ Release date: 2018-07-19
508
588
 
509
589
  ### Fixed
510
590
 
511
- * Make selenium driver :backspace clear stategy work even if caret location is in middle of field content [Champier Cyril]
591
+ * Make selenium driver :backspace clear strategy work even if caret location is in middle of field content [Champier Cyril]
512
592
  * Selenium issue with fieldset nested in disabled fieldset not being considered disabled
513
593
  * `Session#evaluate_script` and `Element#evaluate_script` now strip leading/trailing whitespace from scripts [Ian Lesperance]
514
594
 
@@ -607,7 +687,7 @@ Release date: 2018-04-13
607
687
  ### Fixes
608
688
 
609
689
  * Fix expression filter descriptions in some selector failure messages
610
- * Fix compounding of negated matechers - Issue #2010
690
+ * Fix compounding of negated matchers - Issue #2010
611
691
 
612
692
  # Version 3.0.1
613
693
  Release date: 2018-04-06
@@ -881,7 +961,7 @@ Release date: 2016-12-05
881
961
  * Options for clearing session/local storage on reset added to the Selenium driver
882
962
  * Window size changes wait for the size to stabilize
883
963
  * Defined return value for most actions
884
- * Ignore specific error when qutting selenium driver instance - Issue #1773 [Dylan Reichstadt, Thomas Walpole]
964
+ * Ignore specific error when quitting selenium driver instance - Issue #1773 [Dylan Reichstadt, Thomas Walpole]
885
965
  * Warn on selenium unknown errors rather than raising when quitting driver [Adam Pohorecki, Thomas Walpole]
886
966
  * Capybara::Result#each now returns an `Enumerator` when called without a block - Issue #1777 [Thomas Walpole]
887
967
 
@@ -943,7 +1023,7 @@ Release date: 2016-09-19
943
1023
 
944
1024
  ### Fixed
945
1025
 
946
- * Issue with rack-test driver and obselete mime-types when using `#attach_file` - Issue #1756 [Thomas Walpole]
1026
+ * Issue with rack-test driver and obsolete mime-types when using `#attach_file` - Issue #1756 [Thomas Walpole]
947
1027
 
948
1028
  ### Added
949
1029
 
@@ -1010,7 +1090,7 @@ Release date: 2016-04-07
1010
1090
 
1011
1091
  ### Added
1012
1092
 
1013
- * Capybara now waits for requests to Capybaras server to complete while restting the session [John Hawthorn, Thomas Walpole]
1093
+ * Capybara now waits for requests to Capybaras server to complete while resetting the session [John Hawthorn, Thomas Walpole]
1014
1094
  * Capybara.reuse_server option to allow disabling of sharing server instance between sessions [Thomas Walpole]
1015
1095
  * :multiple filter added to relevant selectors [Thomas Walpole]
1016
1096
  * Provided server registrations for :webrick and :puma. Capybara.server = :puma for testing with Rails 5 [Thomas Walpole]
@@ -1024,7 +1104,7 @@ Release date: 2016-04-07
1024
1104
 
1025
1105
  # Version 2.6.2
1026
1106
 
1027
- Relase date: 2016-01-27
1107
+ Release date: 2016-01-27
1028
1108
 
1029
1109
  ### Fixed
1030
1110
 
@@ -1570,8 +1650,8 @@ Release date: 2011-06-14
1570
1650
  * Rack::Test driver honours maxlength on input fields [Guilherme Carvalho]
1571
1651
  * Rack::Test now works as expected with domains and subdomains [Jonas Nicklas]
1572
1652
  * Session is reset more thoroughly between tests. [Jonas Nicklas]
1573
- * Raise error when uploading non-existant file [Jonas Nicklas]
1574
- * Rack reponse body should respond to #each [Piotr Sarnacki]
1653
+ * Raise error when uploading non-existent file [Jonas Nicklas]
1654
+ * Rack response body should respond to #each [Piotr Sarnacki]
1575
1655
  * Deprecation warnings with selenium webdriver 0.2.0 [Aaron Gibraltar]
1576
1656
  * Selenium Chrome no longer YELLS tagname [Carl Jackson & David W. Frank]
1577
1657
  * Capybara no longer strips encoding before sending to Rack [Jonas Nicklas]
@@ -1713,7 +1793,7 @@ Release date: 2010-05-12
1713
1793
 
1714
1794
  Release date: 2010-04-09
1715
1795
 
1716
- This is a drop in compatible maintainance release. It's mostly
1796
+ This is a drop in compatible maintenance release. It's mostly
1717
1797
  important for driver authors.
1718
1798
 
1719
1799
  ### Added
@@ -1732,7 +1812,7 @@ important for driver authors.
1732
1812
 
1733
1813
  Release date: 2010-03-22
1734
1814
 
1735
- This is a maintainance release with minor bug fixes, should be
1815
+ This is a maintenance release with minor bug fixes, should be
1736
1816
  drop in compatible.
1737
1817
 
1738
1818
  ### 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.31.x stable branch 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
@@ -6,53 +6,58 @@ require 'capybara/dsl'
6
6
  module Capybara
7
7
  module Minitest
8
8
  module Assertions
9
- ## Assert text exists
9
+ ##
10
+ # Assert text exists
10
11
  #
12
+ # @!method assert_content
11
13
  # @!method assert_text
12
- # @see Capybara::Node::Matchers#assert_text
14
+ # See {Capybara::Node::Matchers#assert_text}
13
15
 
14
- ## Assert text does not exist
16
+ ##
17
+ # Assert text does not exist
15
18
  #
19
+ # @!method refute_content
20
+ # @!method assert_no_content
21
+ # @!method refute_text
16
22
  # @!method assert_no_text
17
- # @see Capybara::Node::Matchers#assert_no_text
23
+ # See {Capybara::Node::Matchers#assert_no_text}
18
24
 
19
25
  ##
20
26
  # Assertion that page title does match
21
27
  #
22
28
  # @!method assert_title
23
- # @see Capybara::Node::DocumentMatchers#assert_title
29
+ # See {Capybara::Node::DocumentMatchers#assert_title}
24
30
 
25
31
  ##
26
32
  # Assertion that page title does not match
27
33
  #
28
34
  # @!method refute_title
29
35
  # @!method assert_no_title
30
- # @see Capybara::Node::DocumentMatchers#assert_no_title
36
+ # See {Capybara::Node::DocumentMatchers#assert_no_title}
31
37
 
32
38
  ##
33
39
  # Assertion that current path matches
34
40
  #
35
41
  # @!method assert_current_path
36
- # @see Capybara::SessionMatchers#assert_current_path
42
+ # See {Capybara::SessionMatchers#assert_current_path}
37
43
 
38
44
  ##
39
45
  # Assertion that current page does not match
40
46
  #
41
47
  # @!method refute_current_path
42
48
  # @!method assert_no_current_path
43
- # @see Capybara::SessionMatchers#assert_no_current_path
49
+ # See {Capybara::SessionMatchers#assert_no_current_path}
44
50
 
45
51
  %w[text no_text title no_title current_path no_current_path].each do |assertion_name|
46
52
  class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
47
- def assert_#{assertion_name} *args
53
+ def assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
48
54
  self.assertions +=1
49
55
  subject, args = determine_subject(args)
50
- subject.assert_#{assertion_name}(*args)
56
+ subject.assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
51
57
  rescue Capybara::ExpectationNotMet => e
52
58
  raise ::Minitest::Assertion, e.message
53
59
  end
54
60
  ASSERTION
55
- ruby2_keywords "assert_#{assertion_name}" if respond_to?(:ruby2_keywords)
56
61
  end
57
62
 
58
63
  alias_method :refute_title, :assert_no_title
@@ -62,40 +67,81 @@ module Capybara
62
67
  alias_method :assert_content, :assert_text
63
68
  alias_method :assert_no_content, :refute_text
64
69
 
65
- ## Assert selector exists on page
70
+ ##
71
+ # Assert selector exists on page
66
72
  #
67
73
  # @!method assert_selector
68
- # @see Capybara::Node::Matchers#assert_selector
74
+ # See {Capybara::Node::Matchers#assert_selector}
69
75
 
70
- ## Assert selector does not exist on page
76
+ ##
77
+ # Assert selector does not exist on page
71
78
  #
79
+ # @!method refute_selector
72
80
  # @!method assert_no_selector
73
- # @see Capybara::Node::Matchers#assert_no_selector
81
+ # See {Capybara::Node::Matchers#assert_no_selector}
74
82
 
75
- ## Assert element matches selector
83
+ ##
84
+ # Assert element matches selector
76
85
  #
77
86
  # @!method assert_matches_selector
78
- # @see Capybara::Node::Matchers#assert_matches_selector
87
+ # See {Capybara::Node::Matchers#assert_matches_selector}
79
88
 
80
- ## Assert element does not match selector
89
+ ##
90
+ # Assert element does not match selector
81
91
  #
82
- # @!method assert_xpath
83
- # @see Capybara::Node::Matchers#assert_not_matches_selector
92
+ # @!method refute_matches_selector
93
+ # @!method assert_not_matches_selector
94
+ # See {Capybara::Node::Matchers#assert_not_matches_selector}
95
+
96
+ ##
97
+ # Assert all of the provided selectors exist on page
98
+ #
99
+ # @!method assert_all_of_selectors
100
+ # See {Capybara::Node::Matchers#assert_all_of_selectors}
101
+
102
+ ##
103
+ # Assert none of the provided selectors exist on page
104
+ #
105
+ # @!method assert_none_of_selectors
106
+ # See {Capybara::Node::Matchers#assert_none_of_selectors}
107
+
108
+ ##
109
+ # Assert any of the provided selectors exist on page
110
+ #
111
+ # @!method assert_any_of_selectors
112
+ # See {Capybara::Node::Matchers#assert_any_of_selectors}
84
113
 
85
- ## Assert element has the provided CSS styles
114
+ ##
115
+ # Assert element has the provided CSS styles
86
116
  #
87
117
  # @!method assert_matches_style
88
- # @see Capybara::Node::Matchers#assert_matches_style
118
+ # See {Capybara::Node::Matchers#assert_matches_style}
89
119
 
90
- ## Assert element has a matching sibling
120
+ ##
121
+ # Assert element has a matching sibling
91
122
  #
92
123
  # @!method assert_sibling
93
- # @see Capybara::Node::Matchers#assert_sibling
124
+ # See {Capybara::Node::Matchers#assert_sibling}
125
+
126
+ ##
127
+ # Assert element does not have a matching sibling
128
+ #
129
+ # @!method refute_sibling
130
+ # @!method assert_no_sibling
131
+ # See {Capybara::Node::Matchers#assert_no_sibling}
94
132
 
95
- ## Assert element has a matching ancestor
133
+ ##
134
+ # Assert element has a matching ancestor
96
135
  #
97
136
  # @!method assert_ancestor
98
- # @see Capybara::Node::Matchers#assert_ancestor
137
+ # See {Capybara::Node::Matchers#assert_ancestor}
138
+
139
+ ##
140
+ # Assert element does not have a matching ancestor
141
+ #
142
+ # @!method refute_ancestor
143
+ # @!method assert_no_ancestor
144
+ # See {Capybara::Node::Matchers#assert_no_ancestor}
99
145
 
100
146
  %w[selector no_selector matches_style
101
147
  all_of_selectors none_of_selectors any_of_selectors
@@ -118,6 +164,123 @@ module Capybara
118
164
  alias_method :refute_ancestor, :assert_no_ancestor
119
165
  alias_method :refute_sibling, :assert_no_sibling
120
166
 
167
+ ##
168
+ # Assert that provided xpath exists
169
+ #
170
+ # @!method assert_xpath
171
+ # See {Capybara::Node::Matchers#has_xpath?}
172
+
173
+ ##
174
+ # Assert that provide xpath does not exist
175
+ #
176
+ # @!method refute_xpath
177
+ # @!method assert_no_xpath
178
+ # See {Capybara::Node::Matchers#has_no_xpath?}
179
+
180
+ ##
181
+ # Assert that provided css exists
182
+ #
183
+ # @!method assert_css
184
+ # See {Capybara::Node::Matchers#has_css?}
185
+
186
+ ##
187
+ # Assert that provided css does not exist
188
+ #
189
+ # @!method refute_css
190
+ # @!method assert_no_css
191
+ # See {Capybara::Node::Matchers#has_no_css?}
192
+
193
+ ##
194
+ # Assert that provided link exists
195
+ #
196
+ # @!method assert_link
197
+ # See {Capybara::Node::Matchers#has_link?}
198
+
199
+ ##
200
+ # Assert that provided link does not exist
201
+ #
202
+ # @!method assert_no_link
203
+ # @!method refute_link
204
+ # See {Capybara::Node::Matchers#has_no_link?}
205
+
206
+ ##
207
+ # Assert that provided button exists
208
+ #
209
+ # @!method assert_button
210
+ # See {Capybara::Node::Matchers#has_button?}
211
+
212
+ ##
213
+ # Assert that provided button does not exist
214
+ #
215
+ # @!method refute_button
216
+ # @!method assert_no_button
217
+ # See {Capybara::Node::Matchers#has_no_button?}
218
+
219
+ ##
220
+ # Assert that provided field exists
221
+ #
222
+ # @!method assert_field
223
+ # See {Capybara::Node::Matchers#has_field?}
224
+
225
+ ##
226
+ # Assert that provided field does not exist
227
+ #
228
+ # @!method refute_field
229
+ # @!method assert_no_field
230
+ # See {Capybara::Node::Matchers#has_no_field?}
231
+
232
+ ##
233
+ # Assert that provided checked field exists
234
+ #
235
+ # @!method assert_checked_field
236
+ # See {Capybara::Node::Matchers#has_checked_field?}
237
+
238
+ ##
239
+ # Assert that provided checked_field does not exist
240
+ #
241
+ # @!method assert_no_checked_field
242
+ # @!method refute_checked_field
243
+ # See {Capybara::Node::Matchers#has_no_checked_field?}
244
+
245
+ ##
246
+ # Assert that provided unchecked field exists
247
+ #
248
+ # @!method assert_unchecked_field
249
+ # See {Capybara::Node::Matchers#has_unchecked_field?}
250
+
251
+ ##
252
+ # Assert that provided unchecked field does not exist
253
+ #
254
+ # @!method assert_no_unchecked_field
255
+ # @!method refute_unchecked_field
256
+ # See {Capybara::Node::Matchers#has_no_unchecked_field?}
257
+
258
+ ##
259
+ # Assert that provided select exists
260
+ #
261
+ # @!method assert_select
262
+ # See {Capybara::Node::Matchers#has_select?}
263
+
264
+ ##
265
+ # Assert that provided select does not exist
266
+ #
267
+ # @!method refute_select
268
+ # @!method assert_no_select
269
+ # See {Capybara::Node::Matchers#has_no_select?}
270
+
271
+ ##
272
+ # Assert that provided table exists
273
+ #
274
+ # @!method assert_table
275
+ # See {Capybara::Node::Matchers#has_table?}
276
+
277
+ ##
278
+ # Assert that provided table does not exist
279
+ #
280
+ # @!method refute_table
281
+ # @!method assert_no_table
282
+ # See {Capybara::Node::Matchers#has_no_table?}
283
+
121
284
  %w[xpath css link button field select table].each do |selector_type|
122
285
  define_method "assert_#{selector_type}" do |*args, &optional_filter_block|
123
286
  subject, args = determine_subject(args)
@@ -158,6 +321,32 @@ module Capybara
158
321
  alias_method "refute_#{field_type}_field", "assert_no_#{field_type}_field"
159
322
  end
160
323
 
324
+ ##
325
+ # Assert that element matches xpath
326
+ #
327
+ # @!method assert_matches_xpath
328
+ # See {Capybara::Node::Matchers#matches_xpath?}
329
+
330
+ ##
331
+ # Assert that element does not match xpath
332
+ #
333
+ # @!method refute_matches_xpath
334
+ # @!method assert_not_matches_xpath
335
+ # See {Capybara::Node::Matchers#not_matches_xpath?}
336
+
337
+ ##
338
+ # Assert that element matches css
339
+ #
340
+ # @!method assert_matches_css
341
+ # See {Capybara::Node::Matchers#matches_css?}
342
+
343
+ ##
344
+ # Assert that element matches css
345
+ #
346
+ # @!method refute_matches_css
347
+ # @!method assert_not_matches_css
348
+ # See {Capybara::Node::Matchers#not_matches_css?}
349
+
161
350
  %w[xpath css].each do |selector_type|
162
351
  define_method "assert_matches_#{selector_type}" do |*args, &optional_filter_block|
163
352
  subject, args = determine_subject(args)
@@ -173,121 +362,6 @@ module Capybara
173
362
  alias_method "refute_matches_#{selector_type}", "assert_not_matches_#{selector_type}"
174
363
  end
175
364
 
176
- ##
177
- # Assertion that there is xpath
178
- #
179
- # @!method assert_xpath
180
- # @see Capybara::Node::Matchers#has_xpath?
181
-
182
- ##
183
- # Assertion that there is no xpath
184
- #
185
- # @!method refute_xpath
186
- # @!method assert_no_xpath
187
- # @see Capybara::Node::Matchers#has_no_xpath?
188
-
189
- ##
190
- # Assertion that there is css
191
- #
192
- # @!method assert_css
193
- # @see Capybara::Node::Matchers#has_css?
194
-
195
- ##
196
- # Assertion that there is no css
197
- #
198
- # @!method refute_css
199
- # @!method assert_no_css
200
- # @see Capybara::Node::Matchers#has_no_css?
201
-
202
- ##
203
- # Assertion that there is link
204
- #
205
- # @!method assert_link
206
- # @see Capybara::Node::Matchers#has_link?
207
-
208
- ##
209
- # Assertion that there is no link
210
- #
211
- # @!method assert_no_link
212
- # @!method refute_link
213
- # @see Capybara::Node::Matchers#has_no_link?
214
-
215
- ##
216
- # Assertion that there is button
217
- #
218
- # @!method assert_button
219
- # @see Capybara::Node::Matchers#has_button?
220
-
221
- ##
222
- # Assertion that there is no button
223
- #
224
- # @!method refute_button
225
- # @!method assert_no_button
226
- # @see Capybara::Node::Matchers#has_no_button?
227
-
228
- ##
229
- # Assertion that there is field
230
- #
231
- # @!method assert_field
232
- # @see Capybara::Node::Matchers#has_field?
233
-
234
- ##
235
- # Assertion that there is no field
236
- #
237
- # @!method refute_field
238
- # @!method assert_no_field
239
- # @see Capybara::Node::Matchers#has_no_field?
240
-
241
- ##
242
- # Assertion that there is checked_field
243
- #
244
- # @!method assert_checked_field
245
- # @see Capybara::Node::Matchers#has_checked_field?
246
-
247
- ##
248
- # Assertion that there is no checked_field
249
- #
250
- # @!method assert_no_checked_field
251
- # @!method refute_checked_field
252
-
253
- ##
254
- # Assertion that there is unchecked_field
255
- #
256
- # @!method assert_unchecked_field
257
- # @see Capybara::Node::Matchers#has_unchecked_field?
258
-
259
- ##
260
- # Assertion that there is no unchecked_field
261
- #
262
- # @!method assert_no_unchecked_field
263
- # @!method refute_unchecked_field
264
-
265
- ##
266
- # Assertion that there is select
267
- #
268
- # @!method assert_select
269
- # @see Capybara::Node::Matchers#has_select?
270
-
271
- ##
272
- # Assertion that there is no select
273
- #
274
- # @!method refute_select
275
- # @!method assert_no_select
276
- # @see Capybara::Node::Matchers#has_no_select?
277
-
278
- ##
279
- # Assertion that there is table
280
- #
281
- # @!method assert_table
282
- # @see Capybara::Node::Matchers#has_table?
283
-
284
- ##
285
- # Assertion that there is no table
286
- #
287
- # @!method refute_table
288
- # @!method assert_no_table
289
- # @see Capybara::Node::Matchers#has_no_table?
290
-
291
365
  private
292
366
 
293
367
  def determine_subject(args)