capybara 3.8.1 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/History.md +465 -0
  4. data/License.txt +1 -1
  5. data/README.md +58 -57
  6. data/lib/capybara/config.rb +10 -4
  7. data/lib/capybara/cucumber.rb +1 -1
  8. data/lib/capybara/driver/base.rb +2 -2
  9. data/lib/capybara/driver/node.rb +26 -5
  10. data/lib/capybara/dsl.rb +12 -4
  11. data/lib/capybara/helpers.rb +8 -4
  12. data/lib/capybara/minitest/spec.rb +162 -85
  13. data/lib/capybara/minitest.rb +248 -148
  14. data/lib/capybara/node/actions.rb +149 -96
  15. data/lib/capybara/node/base.rb +27 -10
  16. data/lib/capybara/node/document.rb +12 -0
  17. data/lib/capybara/node/document_matchers.rb +9 -5
  18. data/lib/capybara/node/element.rb +254 -109
  19. data/lib/capybara/node/finders.rb +83 -76
  20. data/lib/capybara/node/matchers.rb +279 -141
  21. data/lib/capybara/node/simple.rb +25 -6
  22. data/lib/capybara/queries/ancestor_query.rb +5 -7
  23. data/lib/capybara/queries/base_query.rb +11 -5
  24. data/lib/capybara/queries/current_path_query.rb +3 -3
  25. data/lib/capybara/queries/match_query.rb +1 -0
  26. data/lib/capybara/queries/selector_query.rb +467 -103
  27. data/lib/capybara/queries/sibling_query.rb +5 -4
  28. data/lib/capybara/queries/style_query.rb +6 -2
  29. data/lib/capybara/queries/text_query.rb +17 -3
  30. data/lib/capybara/queries/title_query.rb +2 -2
  31. data/lib/capybara/rack_test/browser.rb +22 -15
  32. data/lib/capybara/rack_test/driver.rb +10 -1
  33. data/lib/capybara/rack_test/errors.rb +6 -0
  34. data/lib/capybara/rack_test/form.rb +33 -28
  35. data/lib/capybara/rack_test/node.rb +74 -6
  36. data/lib/capybara/registration_container.rb +44 -0
  37. data/lib/capybara/registrations/drivers.rb +36 -0
  38. data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
  39. data/lib/capybara/registrations/servers.rb +44 -0
  40. data/lib/capybara/result.rb +55 -23
  41. data/lib/capybara/rspec/features.rb +4 -4
  42. data/lib/capybara/rspec/matcher_proxies.rb +36 -15
  43. data/lib/capybara/rspec/matchers/base.rb +111 -0
  44. data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
  45. data/lib/capybara/rspec/matchers/compound.rb +88 -0
  46. data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
  47. data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
  48. data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
  49. data/lib/capybara/rspec/matchers/have_selector.rb +77 -0
  50. data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
  51. data/lib/capybara/rspec/matchers/have_text.rb +33 -0
  52. data/lib/capybara/rspec/matchers/have_title.rb +29 -0
  53. data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
  54. data/lib/capybara/rspec/matchers/match_style.rb +38 -0
  55. data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  56. data/lib/capybara/rspec/matchers.rb +117 -311
  57. data/lib/capybara/selector/builders/css_builder.rb +84 -0
  58. data/lib/capybara/selector/builders/xpath_builder.rb +69 -0
  59. data/lib/capybara/selector/css.rb +17 -15
  60. data/lib/capybara/selector/definition/button.rb +52 -0
  61. data/lib/capybara/selector/definition/checkbox.rb +26 -0
  62. data/lib/capybara/selector/definition/css.rb +10 -0
  63. data/lib/capybara/selector/definition/datalist_input.rb +35 -0
  64. data/lib/capybara/selector/definition/datalist_option.rb +25 -0
  65. data/lib/capybara/selector/definition/element.rb +27 -0
  66. data/lib/capybara/selector/definition/field.rb +40 -0
  67. data/lib/capybara/selector/definition/fieldset.rb +14 -0
  68. data/lib/capybara/selector/definition/file_field.rb +13 -0
  69. data/lib/capybara/selector/definition/fillable_field.rb +33 -0
  70. data/lib/capybara/selector/definition/frame.rb +17 -0
  71. data/lib/capybara/selector/definition/id.rb +6 -0
  72. data/lib/capybara/selector/definition/label.rb +62 -0
  73. data/lib/capybara/selector/definition/link.rb +54 -0
  74. data/lib/capybara/selector/definition/link_or_button.rb +16 -0
  75. data/lib/capybara/selector/definition/option.rb +27 -0
  76. data/lib/capybara/selector/definition/radio_button.rb +27 -0
  77. data/lib/capybara/selector/definition/select.rb +81 -0
  78. data/lib/capybara/selector/definition/table.rb +109 -0
  79. data/lib/capybara/selector/definition/table_row.rb +21 -0
  80. data/lib/capybara/selector/definition/xpath.rb +5 -0
  81. data/lib/capybara/selector/definition.rb +277 -0
  82. data/lib/capybara/selector/filter.rb +1 -0
  83. data/lib/capybara/selector/filter_set.rb +26 -19
  84. data/lib/capybara/selector/filters/base.rb +24 -5
  85. data/lib/capybara/selector/filters/expression_filter.rb +3 -3
  86. data/lib/capybara/selector/filters/locator_filter.rb +29 -0
  87. data/lib/capybara/selector/filters/node_filter.rb +16 -2
  88. data/lib/capybara/selector/regexp_disassembler.rb +214 -0
  89. data/lib/capybara/selector/selector.rb +73 -367
  90. data/lib/capybara/selector/xpath_extensions.rb +17 -0
  91. data/lib/capybara/selector.rb +221 -480
  92. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
  93. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
  94. data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
  95. data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
  96. data/lib/capybara/selenium/driver.rb +203 -86
  97. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +88 -14
  98. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
  99. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +89 -0
  100. data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
  101. data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
  102. data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  103. data/lib/capybara/selenium/extensions/find.rb +110 -0
  104. data/lib/capybara/selenium/extensions/html5_drag.rb +191 -22
  105. data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  106. data/lib/capybara/selenium/extensions/scroll.rb +78 -0
  107. data/lib/capybara/selenium/logger_suppressor.rb +34 -0
  108. data/lib/capybara/selenium/node.rb +298 -93
  109. data/lib/capybara/selenium/nodes/chrome_node.rb +100 -8
  110. data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
  111. data/lib/capybara/selenium/nodes/firefox_node.rb +131 -0
  112. data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
  113. data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
  114. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  115. data/lib/capybara/selenium/patches/atoms.rb +18 -0
  116. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  117. data/lib/capybara/selenium/patches/logs.rb +45 -0
  118. data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -3
  119. data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
  120. data/lib/capybara/server/animation_disabler.rb +4 -3
  121. data/lib/capybara/server/checker.rb +6 -2
  122. data/lib/capybara/server/middleware.rb +23 -13
  123. data/lib/capybara/server.rb +30 -7
  124. data/lib/capybara/session/config.rb +14 -10
  125. data/lib/capybara/session/matchers.rb +11 -7
  126. data/lib/capybara/session.rb +152 -111
  127. data/lib/capybara/spec/public/offset.js +6 -0
  128. data/lib/capybara/spec/public/test.js +101 -10
  129. data/lib/capybara/spec/session/all_spec.rb +96 -6
  130. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  131. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +29 -0
  132. data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
  133. data/lib/capybara/spec/session/assert_selector_spec.rb +0 -10
  134. data/lib/capybara/spec/session/assert_style_spec.rb +4 -4
  135. data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
  136. data/lib/capybara/spec/session/attach_file_spec.rb +63 -36
  137. data/lib/capybara/spec/session/check_spec.rb +10 -4
  138. data/lib/capybara/spec/session/choose_spec.rb +8 -2
  139. data/lib/capybara/spec/session/click_button_spec.rb +117 -61
  140. data/lib/capybara/spec/session/click_link_or_button_spec.rb +16 -0
  141. data/lib/capybara/spec/session/click_link_spec.rb +17 -6
  142. data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
  143. data/lib/capybara/spec/session/evaluate_script_spec.rb +13 -0
  144. data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
  145. data/lib/capybara/spec/session/fill_in_spec.rb +47 -6
  146. data/lib/capybara/spec/session/find_field_spec.rb +1 -1
  147. data/lib/capybara/spec/session/find_spec.rb +74 -4
  148. data/lib/capybara/spec/session/first_spec.rb +1 -1
  149. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +13 -1
  150. data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
  151. data/lib/capybara/spec/session/has_all_selectors_spec.rb +1 -1
  152. data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
  153. data/lib/capybara/spec/session/has_any_selectors_spec.rb +25 -0
  154. data/lib/capybara/spec/session/has_button_spec.rb +16 -0
  155. data/lib/capybara/spec/session/has_css_spec.rb +122 -12
  156. data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
  157. data/lib/capybara/spec/session/has_field_spec.rb +55 -0
  158. data/lib/capybara/spec/session/has_select_spec.rb +34 -6
  159. data/lib/capybara/spec/session/has_selector_spec.rb +11 -4
  160. data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
  161. data/lib/capybara/spec/session/has_table_spec.rb +166 -0
  162. data/lib/capybara/spec/session/has_text_spec.rb +48 -1
  163. data/lib/capybara/spec/session/has_xpath_spec.rb +17 -0
  164. data/lib/capybara/spec/session/html_spec.rb +7 -0
  165. data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
  166. data/lib/capybara/spec/session/node_spec.rb +643 -18
  167. data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
  168. data/lib/capybara/spec/session/refresh_spec.rb +4 -0
  169. data/lib/capybara/spec/session/reset_session_spec.rb +23 -8
  170. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  171. data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
  172. data/lib/capybara/spec/session/scroll_spec.rb +117 -0
  173. data/lib/capybara/spec/session/select_spec.rb +10 -10
  174. data/lib/capybara/spec/session/selectors_spec.rb +36 -5
  175. data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
  176. data/lib/capybara/spec/session/unselect_spec.rb +1 -1
  177. data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
  178. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +4 -0
  179. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +4 -0
  180. data/lib/capybara/spec/session/window/window_spec.rb +59 -58
  181. data/lib/capybara/spec/session/window/windows_spec.rb +4 -0
  182. data/lib/capybara/spec/session/within_spec.rb +23 -0
  183. data/lib/capybara/spec/spec_helper.rb +16 -6
  184. data/lib/capybara/spec/test_app.rb +28 -23
  185. data/lib/capybara/spec/views/animated.erb +49 -0
  186. data/lib/capybara/spec/views/form.erb +48 -7
  187. data/lib/capybara/spec/views/frame_child.erb +3 -2
  188. data/lib/capybara/spec/views/frame_one.erb +1 -0
  189. data/lib/capybara/spec/views/obscured.erb +47 -0
  190. data/lib/capybara/spec/views/offset.erb +32 -0
  191. data/lib/capybara/spec/views/react.erb +45 -0
  192. data/lib/capybara/spec/views/scroll.erb +20 -0
  193. data/lib/capybara/spec/views/spatial.erb +31 -0
  194. data/lib/capybara/spec/views/tables.erb +67 -0
  195. data/lib/capybara/spec/views/with_animation.erb +29 -1
  196. data/lib/capybara/spec/views/with_dragula.erb +24 -0
  197. data/lib/capybara/spec/views/with_hover.erb +1 -0
  198. data/lib/capybara/spec/views/with_hover1.erb +10 -0
  199. data/lib/capybara/spec/views/with_html.erb +32 -6
  200. data/lib/capybara/spec/views/with_js.erb +3 -1
  201. data/lib/capybara/spec/views/with_jstree.erb +26 -0
  202. data/lib/capybara/spec/views/with_scope_other.erb +6 -0
  203. data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
  204. data/lib/capybara/version.rb +1 -1
  205. data/lib/capybara/window.rb +11 -11
  206. data/lib/capybara.rb +118 -111
  207. data/spec/basic_node_spec.rb +14 -3
  208. data/spec/capybara_spec.rb +29 -29
  209. data/spec/css_builder_spec.rb +101 -0
  210. data/spec/dsl_spec.rb +46 -21
  211. data/spec/filter_set_spec.rb +5 -5
  212. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  213. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  214. data/spec/minitest_spec.rb +18 -4
  215. data/spec/minitest_spec_spec.rb +59 -44
  216. data/spec/rack_test_spec.rb +117 -89
  217. data/spec/regexp_dissassembler_spec.rb +250 -0
  218. data/spec/result_spec.rb +51 -49
  219. data/spec/rspec/features_spec.rb +3 -0
  220. data/spec/rspec/shared_spec_matchers.rb +112 -97
  221. data/spec/rspec_spec.rb +35 -17
  222. data/spec/sauce_spec_chrome.rb +43 -0
  223. data/spec/selector_spec.rb +244 -28
  224. data/spec/selenium_spec_chrome.rb +125 -54
  225. data/spec/selenium_spec_chrome_remote.rb +26 -12
  226. data/spec/selenium_spec_edge.rb +23 -8
  227. data/spec/selenium_spec_firefox.rb +208 -0
  228. data/spec/selenium_spec_firefox_remote.rb +15 -18
  229. data/spec/selenium_spec_ie.rb +82 -13
  230. data/spec/selenium_spec_safari.rb +148 -0
  231. data/spec/server_spec.rb +118 -77
  232. data/spec/session_spec.rb +19 -3
  233. data/spec/shared_selenium_node.rb +83 -0
  234. data/spec/shared_selenium_session.rb +110 -65
  235. data/spec/spec_helper.rb +57 -9
  236. data/spec/xpath_builder_spec.rb +93 -0
  237. metadata +257 -17
  238. data/lib/capybara/rspec/compound.rb +0 -94
  239. data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -49
  240. data/lib/capybara/selenium/nodes/marionette_node.rb +0 -121
  241. data/lib/capybara/spec/session/has_style_spec.rb +0 -25
  242. data/spec/selenium_spec_marionette.rb +0 -172
data/README.md CHANGED
@@ -3,12 +3,11 @@
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)
7
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)
8
9
 
9
- **Note** You are viewing the README for the development version of Capybara. If you are using the current release version
10
- you can find the README at https://github.com/teamcapybara/capybara/blob/3.8_stable/README.md
11
-
10
+ **Note** You are viewing the README for the 3.33.x release of Capybara.
12
11
 
13
12
  Capybara helps you test web applications by simulating how a real user would
14
13
  interact with your app. It is agnostic about the driver running your tests and
@@ -37,8 +36,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
37
36
  - [Selecting the Driver](#selecting-the-driver)
38
37
  - [RackTest](#racktest)
39
38
  - [Selenium](#selenium)
40
- - [Capybara-webkit](#capybara-webkit)
41
- - [Poltergeist](#poltergeist)
39
+ - [Apparition](#apparition)
42
40
  - [The DSL](#the-dsl)
43
41
  - [Navigating](#navigating)
44
42
  - [Clicking links and buttons](#clicking-links-and-buttons)
@@ -58,11 +56,13 @@ GitHub): http://groups.google.com/group/ruby-capybara
58
56
  - [Using the DSL elsewhere](#using-the-dsl-elsewhere)
59
57
  - [Calling remote servers](#calling-remote-servers)
60
58
  - [Using sessions](#using-sessions)
59
+ - [Named sessions](#named-sessions)
60
+ - [Using sessions manually](#using-sessions-manually)
61
61
  - [XPath, CSS and selectors](#xpath-css-and-selectors)
62
62
  - [Beware the XPath // trap](#beware-the-xpath--trap)
63
63
  - [Configuring and adding drivers](#configuring-and-adding-drivers)
64
64
  - [Gotchas:](#gotchas)
65
- - ["Threadsafe" mode](#threadsafe)
65
+ - ["Threadsafe" mode](#threadsafe-mode)
66
66
  - [Development](#development)
67
67
 
68
68
  ## <a name="key-benefits"></a>Key benefits
@@ -76,7 +76,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
76
76
 
77
77
  ## <a name="setup"></a>Setup
78
78
 
79
- Capybara requires Ruby 2.3.0 or later. To install, add this line to your
79
+ Capybara requires Ruby 2.5.0 or later. To install, add this line to your
80
80
  `Gemfile` and run `bundle install`:
81
81
 
82
82
  ```ruby
@@ -140,7 +140,7 @@ There are also explicit tags for each registered driver set up for you (`@seleni
140
140
 
141
141
  ## <a name="using-capybara-with-rspec"></a>Using Capybara with RSpec
142
142
 
143
- Load RSpec 3.x support by adding the following line (typically to your
143
+ Load RSpec 3.5+ support by adding the following line (typically to your
144
144
  `spec_helper.rb` file):
145
145
 
146
146
  ```ruby
@@ -149,7 +149,7 @@ require 'capybara/rspec'
149
149
 
150
150
  If you are using Rails, put your Capybara specs in `spec/features` or `spec/system` (only works
151
151
  if [you have it configured in
152
- RSpec](https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#file-type-inference-disabled))
152
+ RSpec](https://relishapp.com/rspec/rspec-rails/v/4-0/docs/directory-structure))
153
153
  and if you have your Capybara specs in a different directory, then tag the
154
154
  example groups with `type: :feature` or `type: :system` depending on which type of test you're writing.
155
155
 
@@ -183,7 +183,7 @@ to one specific driver. For example:
183
183
  ```ruby
184
184
  describe 'some stuff which requires js', js: true do
185
185
  it 'will use the default js driver'
186
- it 'will switch to one specific driver', driver: :webkit
186
+ it 'will switch to one specific driver', driver: :apparition
187
187
  end
188
188
  ```
189
189
 
@@ -219,7 +219,7 @@ feature "Signing in" do
219
219
  end
220
220
  ```
221
221
 
222
- `feature` is in fact just an alias for `describe ..., type:> :feature`,
222
+ `feature` is in fact just an alias for `describe ..., type: :feature`,
223
223
  `background` is an alias for `before`, `scenario` for `it`, and
224
224
  `given`/`given!` aliases for `let`/`let!`, respectively.
225
225
 
@@ -260,7 +260,7 @@ end
260
260
 
261
261
  ## <a name="using-capybara-with-minitest"></a>Using Capybara with Minitest
262
262
 
263
- * If you are using Rails, add the following code in your `test_helper.rb`
263
+ * If you are using Rails, but not using Rails system tests, add the following code in your `test_helper.rb`
264
264
  file to make Capybara available in all test cases deriving from
265
265
  `ActionDispatch::IntegrationTest`:
266
266
 
@@ -275,8 +275,7 @@ end
275
275
  include Capybara::Minitest::Assertions
276
276
 
277
277
  # Reset sessions and driver between tests
278
- # Use super wherever this method is redefined in your individual test classes
279
- def teardown
278
+ teardown do
280
279
  Capybara.reset_sessions!
281
280
  Capybara.use_default_driver
282
281
  end
@@ -341,9 +340,9 @@ For example if you'd prefer to run everything in Selenium, you could do:
341
340
  Capybara.default_driver = :selenium # :selenium_chrome and :selenium_chrome_headless are also registered
342
341
  ```
343
342
 
344
- However, if you are using RSpec or Cucumber, you may instead want to consider
345
- leaving the faster `:rack_test` as the __default_driver__, and marking only those
346
- tests that require a JavaScript-capable driver using `js: true` or
343
+ However, if you are using RSpec or Cucumber (and your app runs correctly without JS),
344
+ you may instead want to consider leaving the faster `:rack_test` as the __default_driver__, and
345
+ marking only those tests that require a JavaScript-capable driver using `js: true` or
347
346
  `@javascript`, respectively. By default, JavaScript tests are run using the
348
347
  `:selenium` driver. You can change this by setting
349
348
  `Capybara.javascript_driver`.
@@ -352,7 +351,7 @@ You can also change the driver temporarily (typically in the Before/setup and
352
351
  After/teardown blocks):
353
352
 
354
353
  ```ruby
355
- Capybara.current_driver = :webkit # temporarily select different driver
354
+ Capybara.current_driver = :apparition # temporarily select different driver
356
355
  # tests here
357
356
  Capybara.use_default_driver # switch back to default driver
358
357
  ```
@@ -392,9 +391,10 @@ Capybara supports [Selenium 3.5+
392
391
  In order to use Selenium, you'll need to install the `selenium-webdriver` gem,
393
392
  and add it to your Gemfile if you're using bundler.
394
393
 
395
- Capybara pre-registers a number of named drives that use Selenium - they are:
394
+ Capybara pre-registers a number of named drivers that use Selenium - they are:
396
395
 
397
396
  * :selenium => Selenium driving Firefox
397
+ * :selenium_headless => Selenium driving Firefox in a headless configuration
398
398
  * :selenium_chrome => Selenium driving Chrome
399
399
  * :selenium_chrome_headless => Selenium driving Chrome in a headless configuration
400
400
 
@@ -405,37 +405,16 @@ to the browsers. See the section on adding and configuring drivers.
405
405
 
406
406
  **Note**: drivers which run the server in a different thread may not share the
407
407
  same transaction as your tests, causing data not to be shared between your test
408
- and test server, see "Transactions and database setup" below.
409
-
410
- ### <a name="capybara-webkit"></a>Capybara-webkit
411
-
412
- Note: `capybara-webkit` depends on QtWebkit which went EOL quite some time ago. There has been an attempt to revive the project but `capybara-webkit` is not yet (AFAIK) compatible with the revived version of QtWebKit (could be a good OSS project for someone) and as such is still limited to an old version of QtWebKit. This means its support for modern JS and CSS is severely limited. Y
413
-
414
- The [capybara-webkit driver](https://github.com/thoughtbot/capybara-webkit) is for true headless
415
- testing. It uses QtWebKit to start a rendering engine process. It can execute JavaScript as well.
416
- It is significantly faster than drivers like Selenium since it does not load an entire browser.
417
-
418
- You can install it with:
419
-
420
- ```bash
421
- gem install capybara-webkit
422
- ```
423
-
424
- And you can use it by:
408
+ and test server, see [Transactions and database setup](#transactions-and-database-setup) below.
425
409
 
426
- ```ruby
427
- Capybara.javascript_driver = :webkit
428
- ```
429
-
430
- ### <a name="poltergeist"></a>Poltergeist
410
+ ### <a name="apparition"></a>Apparition
431
411
 
432
- Note: `poltergeist` depends on PhantomJS for which active development ended quite some time ago (2.1.1). As such it is roughly equivalent to a 6-7 year old version of Safari, meaning lack of support for modern JS And CSS. If any effort to update PhantomJS succeeds in the future this situation could change.
433
-
434
- [Poltergeist](https://github.com/teampoltergeist/poltergeist) is another
435
- headless driver which integrates Capybara with
436
- [PhantomJS](http://phantomjs.org/). It is truly headless, so doesn't
437
- require Xvfb to run on your CI server. It will also detect and report
438
- any Javascript errors that happen within the page.
412
+ The [apparition driver](https://github.com/twalpole/apparition) is a new driver that allows you to run tests using Chrome in a headless
413
+ or headed configuration. It attempts to provide backwards compatibility with the [Poltergeist driver API](https://github.com/teampoltergeist/poltergeist)
414
+ and [capybara-webkit API](https://github.com/thoughtbot/capybara-webkit) while allowing for the use of modern JS/CSS. It
415
+ uses CDP to communicate with Chrome, thereby obviating the need for chromedriver. This driver is being developed by the
416
+ current developer of Capybara and will attempt to keep up to date with new Capybara releases. It will probably be moved into the
417
+ teamcapybara repo once it reaches v1.0.
439
418
 
440
419
  ## <a name="the-dsl"></a>The DSL
441
420
 
@@ -630,13 +609,23 @@ In drivers which support it, you can easily execute JavaScript:
630
609
  page.execute_script("$('body').empty()")
631
610
  ```
632
611
 
633
- For simple expressions, you can return the result of the script. Note
634
- that this may break with more complicated expressions:
612
+ For simple expressions, you can return the result of the script.
635
613
 
636
614
  ```ruby
637
615
  result = page.evaluate_script('4 + 4');
638
616
  ```
639
617
 
618
+ For more complicated scripts you'll need to write them as one expression.
619
+
620
+ ```ruby
621
+ result = page.evaluate_script(<<~JS, 3, element)
622
+ (function(n, el){
623
+ var val = parseInt(el.value, 10);
624
+ return n+val;
625
+ })(arguments[0], arguments[1])
626
+ JS
627
+ ```
628
+
640
629
  ### <a name="modals"></a>Modals
641
630
 
642
631
  In drivers which support it, you can accept, dismiss and respond to alerts, confirms and prompts.
@@ -945,12 +934,17 @@ Capybara.default_selector = :xpath
945
934
  find('.//ul/li').text
946
935
  ```
947
936
 
948
- Capybara allows you to add custom selectors, which can be very useful if you
949
- find yourself using the same kinds of selectors very often:
937
+ Capybara provides a number of other built-in selector types. The full list, along
938
+ with applicable filters, can be seen at [built-in selectors](https://www.rubydoc.info/github/teamcapybara/capybara/Capybara/Selector)
939
+
940
+ Capybara also allows you to add custom selectors, which can be very useful if you
941
+ find yourself using the same kinds of selectors very often. The examples below are very
942
+ simple, and there are many available features not demonstrated. For more in-depth examples
943
+ please see Capybaras built-in selector definitions.
950
944
 
951
945
  ```ruby
952
- Capybara.add_selector(:id) do
953
- xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
946
+ Capybara.add_selector(:my_attribute) do
947
+ xpath { |id| XPath.descendant[XPath.attr(:my_attribute) == id.to_s] }
954
948
  end
955
949
 
956
950
  Capybara.add_selector(:row) do
@@ -967,9 +961,9 @@ an XPath expression generated through the XPath gem. You can now use these
967
961
  selectors like this:
968
962
 
969
963
  ```ruby
970
- find(:id, 'post_123')
971
- find(:row, 3)
972
- find(:flash_type, :notice)
964
+ find(:my_attribute, 'post_123') # find element with matching attribute
965
+ find(:row, 3) # find 3rd row in table body
966
+ find(:flash_type, :notice) # find element with id of 'flash' and class of 'notice'
973
967
  ```
974
968
 
975
969
  ## <a name="beware-the-xpath--trap"></a>Beware the XPath // trap
@@ -1061,6 +1055,13 @@ additional info about how the underlying driver can be configured.
1061
1055
  are testing for specific server errors and using multiple sessions make sure to test for the
1062
1056
  errors using the initial session (usually :default)
1063
1057
 
1058
+ * If WebMock is enabled, you may encounter a "Too many open files"
1059
+ error. A simple `page.find` call may cause thousands of HTTP requests
1060
+ until the timeout occurs. By default, WebMock will cause each of these
1061
+ requests to spawn a new connection. To work around this problem, you
1062
+ may need to [enable WebMock's `net_http_connect_on_start: true`
1063
+ parameter](https://github.com/bblimke/webmock/blob/master/README.md#connecting-on-nethttpstart).
1064
+
1064
1065
  ## <a name="threadsafe"></a>"Threadsafe" mode
1065
1066
 
1066
1067
  In normal mode most of Capybara's configuration options are global settings which can cause issues
@@ -7,12 +7,13 @@ module Capybara
7
7
  class Config
8
8
  extend Forwardable
9
9
 
10
- OPTIONS = %i[app reuse_server threadsafe default_wait_time server default_driver javascript_driver].freeze
10
+ OPTIONS = %i[app reuse_server threadsafe server default_driver javascript_driver allow_gumbo].freeze
11
11
 
12
12
  attr_accessor :app
13
13
  attr_reader :reuse_server, :threadsafe
14
14
  attr_reader :session_options
15
15
  attr_writer :default_driver, :javascript_driver
16
+ attr_accessor :allow_gumbo
16
17
 
17
18
  SessionConfig::OPTIONS.each do |method|
18
19
  def_delegators :session_options, method, "#{method}="
@@ -26,7 +27,10 @@ module Capybara
26
27
  attr_writer :reuse_server
27
28
 
28
29
  def threadsafe=(bool)
29
- raise 'Threadsafe setting cannot be changed once a session is created' if (bool != threadsafe) && Session.instance_created?
30
+ if (bool != threadsafe) && Session.instance_created?
31
+ raise 'Threadsafe setting cannot be changed once a session is created'
32
+ end
33
+
30
34
  @threadsafe = bool
31
35
  end
32
36
 
@@ -57,7 +61,7 @@ module Capybara
57
61
  @server = if name.respond_to? :call
58
62
  name
59
63
  elsif options
60
- proc { |app, port, host| Capybara.servers[name.to_sym].call(app, port, host, options) }
64
+ proc { |app, port, host| Capybara.servers[name.to_sym].call(app, port, host, **options) }
61
65
  else
62
66
  Capybara.servers[name.to_sym]
63
67
  end
@@ -81,7 +85,9 @@ module Capybara
81
85
 
82
86
  def deprecate(method, alternate_method, once = false)
83
87
  @deprecation_notified ||= {}
84
- warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once && @deprecation_notified[method]
88
+ unless once && @deprecation_notified[method]
89
+ warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead"
90
+ end
85
91
  @deprecation_notified[method] = true
86
92
  end
87
93
  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
@@ -15,11 +15,11 @@ class Capybara::Driver::Base
15
15
  raise NotImplementedError
16
16
  end
17
17
 
18
- def find_xpath(query)
18
+ def find_xpath(query, **options)
19
19
  raise NotImplementedError
20
20
  end
21
21
 
22
- def find_css(query)
22
+ def find_css(query, **options)
23
23
  raise NotImplementedError
24
24
  end
25
25
 
@@ -3,11 +3,12 @@
3
3
  module Capybara
4
4
  module Driver
5
5
  class Node
6
- attr_reader :driver, :native
6
+ attr_reader :driver, :native, :initial_cache
7
7
 
8
- def initialize(driver, native)
8
+ def initialize(driver, native, initial_cache = {})
9
9
  @driver = driver
10
10
  @native = native
11
+ @initial_cache = initial_cache
11
12
  end
12
13
 
13
14
  def all_text
@@ -30,8 +31,8 @@ module Capybara
30
31
  raise NotImplementedError
31
32
  end
32
33
 
33
- # @param value String or Array. Array is only allowed if node has 'multiple' attribute
34
- # @param options [Hash{}] Driver specific options for how to set a value on a node
34
+ # @param value [String, Array] Array is only allowed if node has 'multiple' attribute
35
+ # @param options [Hash] Driver specific options for how to set a value on a node
35
36
  def set(value, **options)
36
37
  raise NotImplementedError
37
38
  end
@@ -64,7 +65,19 @@ module Capybara
64
65
  raise NotImplementedError
65
66
  end
66
67
 
67
- def drag_to(element)
68
+ def drag_to(element, **options)
69
+ raise NotImplementedError
70
+ end
71
+
72
+ def drop(*args)
73
+ raise NotImplementedError
74
+ end
75
+
76
+ def scroll_by(x, y)
77
+ raise NotImplementedError
78
+ end
79
+
80
+ def scroll_to(element, alignment, position = nil)
68
81
  raise NotImplementedError
69
82
  end
70
83
 
@@ -76,6 +89,10 @@ module Capybara
76
89
  raise NotImplementedError
77
90
  end
78
91
 
92
+ def obscured?
93
+ raise NotImplementedError
94
+ end
95
+
79
96
  def checked?
80
97
  raise NotImplementedError
81
98
  end
@@ -96,6 +113,10 @@ module Capybara
96
113
  !!self[:multiple]
97
114
  end
98
115
 
116
+ def rect
117
+ raise NotSupportedByDriverError, 'Capybara::Driver::Node#rect'
118
+ end
119
+
99
120
  def path
100
121
  raise NotSupportedByDriverError, 'Capybara::Driver::Node#path'
101
122
  end
data/lib/capybara/dsl.rb CHANGED
@@ -18,8 +18,8 @@ module Capybara
18
18
  #
19
19
  # Shortcut to working in a different session.
20
20
  #
21
- def using_session(name, &block)
22
- Capybara.using_session(name, &block)
21
+ def using_session(name_or_session, &block)
22
+ Capybara.using_session(name_or_session, &block)
23
23
  end
24
24
 
25
25
  # Shortcut to using a different wait time.
@@ -47,8 +47,16 @@ module Capybara
47
47
  end
48
48
 
49
49
  Session::DSL_METHODS.each do |method|
50
- define_method method do |*args, &block|
51
- page.send method, *args, &block
50
+ if RUBY_VERSION >= '2.7'
51
+ class_eval <<~METHOD, __FILE__, __LINE__ + 1
52
+ def #{method}(...)
53
+ page.method("#{method}").call(...)
54
+ end
55
+ METHOD
56
+ else
57
+ define_method method do |*args, &block|
58
+ page.send method, *args, &block
59
+ end
52
60
  end
53
61
  end
54
62
  end
@@ -41,7 +41,7 @@ module Capybara
41
41
  ##
42
42
  #
43
43
  # Injects a `<base>` tag into the given HTML code, pointing to
44
- # `Capybara.asset_host`.
44
+ # {Capybara.configure asset_host}.
45
45
  #
46
46
  # @param [String] html HTML code to inject into
47
47
  # @param [URL] host (Capybara.asset_host) The host from which assets should be loaded
@@ -49,8 +49,9 @@ module Capybara
49
49
  #
50
50
  def inject_asset_host(html, host: Capybara.asset_host)
51
51
  if host && Nokogiri::HTML(html).css('base').empty?
52
- match = html.match(/<head[^<]*?>/)
53
- return html.clone.insert match.end(0), "<base href='#{host}' />" if match
52
+ html.match(/<head[^<]*?>/) do |m|
53
+ return html.clone.insert m.end(0), "<base href='#{host}' />"
54
+ end
54
55
  end
55
56
  html
56
57
  end
@@ -86,7 +87,10 @@ module Capybara
86
87
  end
87
88
 
88
89
  def expired?
89
- raise Capybara::FrozenInTime, 'Time appears to be frozen. Capybara does not work with libraries which freeze time, consider using time travelling instead' if stalled?
90
+ if stalled?
91
+ raise Capybara::FrozenInTime, 'Time appears to be frozen. Capybara does not work with libraries which freeze time, consider using time travelling instead'
92
+ end
93
+
90
94
  current - @start >= @expire_in
91
95
  end
92
96