capybara 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +52 -15
  3. data/README.md +45 -38
  4. data/lib/capybara/cucumber.rb +1 -0
  5. data/lib/capybara/driver/base.rb +5 -2
  6. data/lib/capybara/driver/node.rb +1 -0
  7. data/lib/capybara/dsl.rb +1 -0
  8. data/lib/capybara/helpers.rb +3 -2
  9. data/lib/capybara/node/actions.rb +6 -0
  10. data/lib/capybara/node/base.rb +1 -0
  11. data/lib/capybara/node/document.rb +1 -0
  12. data/lib/capybara/node/document_matchers.rb +1 -0
  13. data/lib/capybara/node/element.rb +1 -0
  14. data/lib/capybara/node/finders.rb +3 -2
  15. data/lib/capybara/node/matchers.rb +72 -2
  16. data/lib/capybara/node/simple.rb +6 -3
  17. data/lib/capybara/queries/base_query.rb +1 -0
  18. data/lib/capybara/queries/current_path_query.rb +6 -3
  19. data/lib/capybara/queries/match_query.rb +21 -0
  20. data/lib/capybara/queries/selector_query.rb +138 -0
  21. data/lib/capybara/queries/text_query.rb +1 -0
  22. data/lib/capybara/queries/title_query.rb +1 -0
  23. data/lib/capybara/query.rb +3 -131
  24. data/lib/capybara/rack_test/browser.rb +1 -0
  25. data/lib/capybara/rack_test/css_handlers.rb +1 -0
  26. data/lib/capybara/rack_test/driver.rb +6 -4
  27. data/lib/capybara/rack_test/form.rb +1 -0
  28. data/lib/capybara/rack_test/node.rb +1 -0
  29. data/lib/capybara/rails.rb +2 -1
  30. data/lib/capybara/result.rb +1 -0
  31. data/lib/capybara/rspec/features.rb +1 -0
  32. data/lib/capybara/rspec/matchers.rb +54 -3
  33. data/lib/capybara/rspec.rb +1 -0
  34. data/lib/capybara/selector/filter.rb +48 -0
  35. data/lib/capybara/selector.rb +175 -75
  36. data/lib/capybara/selenium/driver.rb +24 -7
  37. data/lib/capybara/selenium/node.rb +1 -0
  38. data/lib/capybara/server.rb +38 -6
  39. data/lib/capybara/session/matchers.rb +2 -1
  40. data/lib/capybara/session.rb +30 -14
  41. data/lib/capybara/spec/public/test.js +6 -0
  42. data/lib/capybara/spec/session/accept_alert_spec.rb +2 -1
  43. data/lib/capybara/spec/session/accept_confirm_spec.rb +2 -1
  44. data/lib/capybara/spec/session/accept_prompt_spec.rb +2 -1
  45. data/lib/capybara/spec/session/all_spec.rb +1 -0
  46. data/lib/capybara/spec/session/assert_current_path.rb +1 -0
  47. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  48. data/lib/capybara/spec/session/assert_text.rb +1 -0
  49. data/lib/capybara/spec/session/assert_title.rb +1 -0
  50. data/lib/capybara/spec/session/attach_file_spec.rb +1 -0
  51. data/lib/capybara/spec/session/body_spec.rb +1 -0
  52. data/lib/capybara/spec/session/check_spec.rb +1 -0
  53. data/lib/capybara/spec/session/choose_spec.rb +1 -0
  54. data/lib/capybara/spec/session/click_button_spec.rb +1 -0
  55. data/lib/capybara/spec/session/click_link_or_button_spec.rb +1 -0
  56. data/lib/capybara/spec/session/click_link_spec.rb +1 -0
  57. data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
  58. data/lib/capybara/spec/session/current_url_spec.rb +1 -0
  59. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +2 -1
  60. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -1
  61. data/lib/capybara/spec/session/element/assert_match_selector.rb +31 -0
  62. data/lib/capybara/spec/session/element/match_css_spec.rb +17 -0
  63. data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
  64. data/lib/capybara/spec/session/element/matches_selector_spec.rb +63 -0
  65. data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -0
  66. data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
  67. data/lib/capybara/spec/session/fill_in_spec.rb +1 -0
  68. data/lib/capybara/spec/session/find_button_spec.rb +1 -0
  69. data/lib/capybara/spec/session/find_by_id_spec.rb +1 -0
  70. data/lib/capybara/spec/session/find_field_spec.rb +1 -0
  71. data/lib/capybara/spec/session/find_link_spec.rb +1 -0
  72. data/lib/capybara/spec/session/find_spec.rb +1 -0
  73. data/lib/capybara/spec/session/first_spec.rb +1 -0
  74. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  75. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  76. data/lib/capybara/spec/session/has_button_spec.rb +1 -0
  77. data/lib/capybara/spec/session/has_css_spec.rb +1 -0
  78. data/lib/capybara/spec/session/has_current_path_spec.rb +1 -0
  79. data/lib/capybara/spec/session/has_field_spec.rb +13 -0
  80. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  81. data/lib/capybara/spec/session/has_select_spec.rb +19 -0
  82. data/lib/capybara/spec/session/has_selector_spec.rb +6 -0
  83. data/lib/capybara/spec/session/has_table_spec.rb +1 -0
  84. data/lib/capybara/spec/session/has_text_spec.rb +1 -0
  85. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  86. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  87. data/lib/capybara/spec/session/headers.rb +1 -0
  88. data/lib/capybara/spec/session/html_spec.rb +1 -0
  89. data/lib/capybara/spec/session/node_spec.rb +29 -0
  90. data/lib/capybara/spec/session/reset_session_spec.rb +35 -1
  91. data/lib/capybara/spec/session/response_code.rb +1 -0
  92. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  93. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -2
  94. data/lib/capybara/spec/session/save_page_spec.rb +34 -2
  95. data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
  96. data/lib/capybara/spec/session/screenshot_spec.rb +3 -1
  97. data/lib/capybara/spec/session/select_spec.rb +1 -0
  98. data/lib/capybara/spec/session/selectors_spec.rb +35 -0
  99. data/lib/capybara/spec/session/text_spec.rb +1 -0
  100. data/lib/capybara/spec/session/title_spec.rb +2 -1
  101. data/lib/capybara/spec/session/uncheck_spec.rb +1 -0
  102. data/lib/capybara/spec/session/unselect_spec.rb +1 -0
  103. data/lib/capybara/spec/session/visit_spec.rb +1 -0
  104. data/lib/capybara/spec/session/window/become_closed_spec.rb +1 -0
  105. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  106. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  107. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -0
  108. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -0
  109. data/lib/capybara/spec/session/window/window_spec.rb +1 -8
  110. data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
  111. data/lib/capybara/spec/session/window/within_window_spec.rb +2 -3
  112. data/lib/capybara/spec/session/within_frame_spec.rb +1 -0
  113. data/lib/capybara/spec/session/within_spec.rb +1 -0
  114. data/lib/capybara/spec/spec_helper.rb +2 -0
  115. data/lib/capybara/spec/test_app.rb +1 -0
  116. data/lib/capybara/spec/views/buttons.erb +1 -0
  117. data/lib/capybara/spec/views/fieldsets.erb +2 -1
  118. data/lib/capybara/spec/views/form.erb +24 -0
  119. data/lib/capybara/spec/views/frame_child.erb +2 -1
  120. data/lib/capybara/spec/views/frame_one.erb +2 -1
  121. data/lib/capybara/spec/views/frame_parent.erb +2 -1
  122. data/lib/capybara/spec/views/frame_two.erb +2 -1
  123. data/lib/capybara/spec/views/header_links.erb +1 -0
  124. data/lib/capybara/spec/views/host_links.erb +1 -0
  125. data/lib/capybara/spec/views/path.erb +1 -0
  126. data/lib/capybara/spec/views/popup_one.erb +1 -0
  127. data/lib/capybara/spec/views/popup_two.erb +1 -0
  128. data/lib/capybara/spec/views/postback.erb +2 -1
  129. data/lib/capybara/spec/views/tables.erb +1 -0
  130. data/lib/capybara/spec/views/with_base_tag.erb +1 -0
  131. data/lib/capybara/spec/views/with_count.erb +2 -1
  132. data/lib/capybara/spec/views/with_hover.erb +2 -1
  133. data/lib/capybara/spec/views/with_html.erb +3 -0
  134. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  135. data/lib/capybara/spec/views/with_js.erb +5 -0
  136. data/lib/capybara/spec/views/with_scope.erb +1 -0
  137. data/lib/capybara/spec/views/with_simple_html.erb +2 -1
  138. data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
  139. data/lib/capybara/spec/views/with_title.erb +2 -1
  140. data/lib/capybara/spec/views/with_unload_alert.erb +12 -0
  141. data/lib/capybara/spec/views/with_windows.erb +1 -0
  142. data/lib/capybara/spec/views/within_frames.erb +2 -1
  143. data/lib/capybara/version.rb +2 -1
  144. data/lib/capybara/window.rb +1 -0
  145. data/lib/capybara.rb +86 -10
  146. data/spec/basic_node_spec.rb +1 -0
  147. data/spec/capybara_spec.rb +28 -1
  148. data/spec/dsl_spec.rb +1 -0
  149. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -0
  150. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -0
  151. data/spec/rack_test_spec.rb +1 -0
  152. data/spec/result_spec.rb +1 -0
  153. data/spec/rspec/features_spec.rb +1 -0
  154. data/spec/rspec/matchers_spec.rb +1 -0
  155. data/spec/rspec/scenarios_spec.rb +1 -0
  156. data/spec/rspec/views_spec.rb +1 -0
  157. data/spec/rspec_spec.rb +1 -0
  158. data/spec/selector_spec.rb +55 -1
  159. data/spec/selenium_spec.rb +6 -2
  160. data/spec/selenium_spec_chrome.rb +1 -0
  161. data/spec/server_spec.rb +101 -13
  162. data/spec/spec_helper.rb +1 -0
  163. metadata +16 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7503b0ca48f7ee15c40c1baacb2e4147aeda674
4
- data.tar.gz: 0da9283932e38baf19334f06cb94cd3eeaf5acdf
3
+ metadata.gz: 13e267dd4eab833671b7653e9cec855306653102
4
+ data.tar.gz: 80707daeb161eac1ac1cabff4edef7c06823b707
5
5
  SHA512:
6
- metadata.gz: 388e135a8d62498ae35e0f0ae289a0f78cef7ebd2f522197926a3c0a4fa68e67f548aba020ff513dde67dba3ef899685ce7cac49246a647be432f43cdd6bf697
7
- data.tar.gz: b31b4c8ee11655e952d746ccd44ac228b8d0f739bb684c2e5bbbc80c961219bbbb380570e1adc0e4dc272d7c6081df5f74ab03f5bdf5ca7df8b3b14df7f63d60
6
+ metadata.gz: 03a372cfdbdd251f39577df0b83bd8286af62cc4d02bdedd49d91594fb3c2de88babacf628366f49c3a8d10470203bccfe371e461f3789f8c7dae0be94d6eda2
7
+ data.tar.gz: 77db21ebef969917a1a8836d5d95e6a725f1fe6dc235fe0e795eeca25fd46b209f77487ddb5e38a523c80f7772ea6d17627ddabda78081e335e002847f8da53e
data/History.md CHANGED
@@ -1,45 +1,82 @@
1
+ # Version 2.7.0
2
+ Release date: unreleased
3
+
4
+ ### Fixed
5
+ * Element#visible?/checked?/disabled?/selected? Now return boolean
6
+ as expected when using the rack_test driver [Thomas Walpole]
7
+ * The rack_test driver now considers \<input type="hidden"> elements as non-visible [Thomas Walpole]
8
+ * A nil locator passed to the built-in html type selectors now behaves consistently, and finds elements of the expected types [Thomas Walpole]
9
+ * Capybara::Server now searches for available ports on the same interface it binds to [Aaron Stone]
10
+ * Selenium Driver handles system modals that appear when page is unloading [Thomas Walpole]
11
+ * Warning output if unused parameters are passed to a selector query [Thomas Walpole]
12
+
13
+ ### Added
14
+ * Capybara now waits for requests to Capybaras server to complete while restting the session [John Hawthorn, Thomas Walpole]
15
+ * Capybara.reuse_server option to allow disabling of sharing server instance between sessions [Thomas Walpole]
16
+ * :multiple filter added to relevant selectors [Thomas Walpole]
17
+ * Provided server registrations for :webrick and :puma. Capybara.server = :puma for testing with Rails 5 [Thomas Walpole]
18
+ * Deprecate passing a block to Capybara::server user Capybara::register_server instead [Thomas Walpole]
19
+ * :option selector supports :selected and :disabled filters [Thomas Walpole]
20
+ * Element#matches_selector? and associated matchers (match_selector, match_css, etc) for comparing an element to a selector [Thomas Walpole]
21
+ * Deprecated Driver#browser_initialized? - Driver#reset! is required to be synchronous [Jonas Nicklas, Thomas Walpole]
22
+ * Deprecated Capybara.save_and_open_page_path in favor of Capybara.save_path with slightly different behavior when using relative paths with
23
+ save_page/save_screenshot [Thomas Walpole]
24
+ * :label selector [Thomas Walpole]
25
+
26
+ #Version 2.6.2
27
+ Relase date: 2016-01-27
28
+
29
+ ### Fixed
30
+ * support for more than just addressable 2.4.0 [Thomas Walpole]
31
+
32
+ # Version 2.6.1
33
+ Release date: 2016-01-27
34
+
35
+ ### Fixed
36
+ * Add missing require for addressable [Jorge Bejar]
37
+
1
38
  # Version 2.6.0
2
39
  Relase date: 2016-01-17
3
40
 
4
41
  ### Fixed
5
- * Fixed path escaping issue with current_path matchers [Tom Walpole, Luke Rollans] (Issue #1611)
42
+ * Fixed path escaping issue with current_path matchers [Thomas Walpole, Luke Rollans] (Issue #1611)
6
43
  * Fixed circular require [David Rodríguez]
7
44
  * Capybara::RackTest::Form no longer overrides Object#method [David Rodriguez]
8
45
  * options and with_options filter for :select selector have more intuitive visibility behavior [Nathan]
9
- * Test for nested modal API method support [Tom Walpole]
46
+ * Test for nested modal API method support [Thomas Walpole]
10
47
 
11
48
 
12
49
  ### Added
13
- * Capybara.modify_selector [Tom Walpole]
50
+ * Capybara.modify_selector [Thomas Walpole]
14
51
  * xfeature and ffeature aliases added when using RSpec [Filip Bartuzi]
15
- * Selenium driver supports a :clear option to #set to handle different strategies for clearing a field [Tom Walpole]
16
- * Support the use of rack 2.0 with the rack_test driver [Travis Grathwell, Tom Walpole]
17
- * Disabled option for default selectors now supports true, false, or :all [Jillian Rosile, Tom Walpole]
18
- * Modal API methods now default wait time to Capybara.max_default_wait_time [Tom Walpole]
52
+ * Selenium driver supports a :clear option to #set to handle different strategies for clearing a field [Thomas Walpole]
53
+ * Support the use of rack 2.0 with the rack_test driver [Travis Grathwell, Thomas Walpole]
54
+ * Disabled option for default selectors now supports true, false, or :all [Jillian Rosile, Thomas Walpole]
55
+ * Modal API methods now default wait time to Capybara.default_max_wait_time [Thomas Walpole]
19
56
 
20
57
  # Version 2.5.0
21
58
  Release date: 2015-08-25
22
59
 
23
60
  ### Fixed
24
- * Error message now raised correctly when invalid options passed to 'have_text'/'have_content' [Tom Walpole]
25
- * Rack-test driver correctly gets document title when elements on the page have nested title elements (SVG) [Tom Walpole]
61
+ * Error message now raised correctly when invalid options passed to 'have_text'/'have_content' [Thomas Walpole]
62
+ * Rack-test driver correctly gets document title when elements on the page have nested title elements (SVG) [Thomas Walpole]
26
63
  * 'save_page' no longer errors when using Capybara.asset_host if the page has no \<head> element [Travis Grathwell]
27
64
  * rack-test driver will ignore clicks on links with href starting with '#' or 'javascript:'
28
65
 
29
66
  ### Added
30
- * has_current_path? and associated asserts/matchers added [Tom Walpole]
67
+ * has_current_path? and associated asserts/matchers added [Thomas Walpole]
31
68
  * Implement Node#path in selenium driver [Soutaro Matsumoto]
32
- * 'using_session' is now nestable [Tom Walpole]
33
- * 'switch_to_window' will now use waiting behavior for a matching window to appear [Tom Walpole]
69
+ * 'using_session' is now nestable [Thomas Walpole]
70
+ * 'switch_to_window' will now use waiting behavior for a matching window to appear [Thomas Walpole]
34
71
  * Warning when attempting to select a disabled option
35
72
  * Capybara matchers are now available in RSpec view specs by default [Joshua Clayton]
36
73
  * 'have_link' and 'click_link' now accept Regexp for href matching [Yaniv Savir]
37
74
  * 'find_all' as an alias of 'all' due to collision with RSpec
38
75
  * Capybara.wait_on_first_by_default setting (default is false)
39
76
  If set to true 'first' will use Capybaras waiting behavior to wait for at least one element to appear by default
40
- * Capybara waiting behavior uses the monotonic clock if supported to ease restrictions on freezing time in tests [Dmitry Maksyoma, Tom Walpole]
41
- * Capybara.server_errors setting that allows to configure what type of errors will be raised from the server thread [Tom Walpole]
42
- * Node#send_keys to allow for sending keypresses directly to elements [Tom Walpole]
77
+ * Capybara waiting behavior uses the monotonic clock if supported to ease restrictions on freezing time in tests [Dmitry Maksyoma, Thomas Walpole]
78
+ * Capybara.server_errors setting that allows to configure what type of errors will be raised from the server thread [Thomas Walpole]
79
+ * Node#send_keys to allow for sending keypresses directly to elements [Thomas Walpole]
43
80
  * 'formmethod' attribute support in RackTest driver [Emilia Andrzejewska]
44
81
  * Clear field using backspaces in Selenium driver by using `:fill_options => { :clear => :backspace }` [Joe Lencioni]
45
82
 
data/README.md CHANGED
@@ -51,7 +51,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
51
51
  - [Gotchas:](#gotchas)
52
52
  - [Development](#development)
53
53
 
54
- ## Key benefits
54
+ ## <a name="key-benefits"></a>Key benefits
55
55
 
56
56
  - **No setup** necessary for Rails and Rack application. Works out of the box.
57
57
  - **Intuitive API** which mimics the language an actual user would use.
@@ -60,7 +60,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
60
60
  - **Powerful synchronization** features mean you never have to manually wait
61
61
  for asynchronous processes to complete.
62
62
 
63
- ## Setup
63
+ ## <a name="setup"></a>Setup
64
64
 
65
65
  Capybara requires Ruby 1.9.3 or later. To install, add this line to your
66
66
  `Gemfile` and run `bundle install`:
@@ -89,7 +89,7 @@ Capybara.app = MyRackApp
89
89
  If you need to test JavaScript, or if your app interacts with (or is located at)
90
90
  a remote URL, you'll need to [use a different driver](#drivers).
91
91
 
92
- ## Using Capybara with Cucumber
92
+ ## <a name="using-capybara-with-cucumber"></a>Using Capybara with Cucumber
93
93
 
94
94
  The `cucumber-rails` gem comes with Capybara support built-in. If you
95
95
  are not using Rails, manually load the `capybara/cucumber` module:
@@ -124,7 +124,7 @@ Scenario: do something Ajaxy
124
124
  There are also explicit `@selenium` and `@rack_test`
125
125
  tags set up for you.
126
126
 
127
- ## Using Capybara with RSpec
127
+ ## <a name="using-capybara-with-rspec"></a>Using Capybara with RSpec
128
128
 
129
129
  Load RSpec 2.x support by adding the following line (typically to your
130
130
  `spec_helper.rb` file):
@@ -135,7 +135,7 @@ require 'capybara/rspec'
135
135
 
136
136
  If you are using Rails, put your Capybara specs in `spec/features` (only works
137
137
  if [you have it configured in
138
- rpsec](https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#file-type-inference-disabled))
138
+ RSpec](https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#file-type-inference-disabled))
139
139
  and if you have your Capybara specs in a different directory, then tag the
140
140
  example groups with `:type => :feature`.
141
141
 
@@ -223,7 +223,7 @@ RSpec.describe "todos/show.html.erb", type: :view do
223
223
  end
224
224
  ```
225
225
 
226
- ## Using Capybara with Test::Unit
226
+ ## <a name="using-capybara-with-testunit"></a>Using Capybara with Test::Unit
227
227
 
228
228
  * If you are using Rails, add the following code in your `test_helper.rb`
229
229
  file to make Capybara available in all test cases deriving from
@@ -233,6 +233,13 @@ end
233
233
  class ActionDispatch::IntegrationTest
234
234
  # Make the Capybara DSL available in all integration tests
235
235
  include Capybara::DSL
236
+
237
+ # Reset sessions and driver between tests
238
+ # Use super wherever this method is redefined in your individual test classes
239
+ def teardown
240
+ Capybara.reset_sessions!
241
+ Capybara.use_default_driver
242
+ end
236
243
  end
237
244
  ```
238
245
 
@@ -267,7 +274,7 @@ class BlogTest < ActionDispatch::IntegrationTest
267
274
  end
268
275
  ```
269
276
 
270
- ## Using Capybara with MiniTest::Spec
277
+ ## <a name="using-capybara-with-minitestspec"></a>Using Capybara with MiniTest::Spec
271
278
 
272
279
  Set up your base class as with Test::Unit. (On Rails, the right base class
273
280
  could be something other than ActionDispatch::IntegrationTest.)
@@ -280,11 +287,11 @@ expectations for Capybara. For example:
280
287
  page.must_have_content('Important!')
281
288
  ```
282
289
 
283
- ## Drivers
290
+ ## <a name="drivers"></a>Drivers
284
291
 
285
292
  Capybara uses the same DSL to drive a variety of browser and headless drivers.
286
293
 
287
- ### Selecting the Driver
294
+ ### <a name="selecting-the-driver"></a>Selecting the Driver
288
295
 
289
296
  By default, Capybara uses the `:rack_test` driver, which is fast but limited: it
290
297
  does not support JavaScript, nor is it able to access HTTP resources outside of
@@ -315,7 +322,7 @@ Capybara.use_default_driver # switch back to default driver
315
322
  **Note**: switching the driver creates a new session, so you may not be able to
316
323
  switch in the middle of a test.
317
324
 
318
- ### RackTest
325
+ ### <a name="racktest"></a>RackTest
319
326
 
320
327
  RackTest is Capybara's default driver. It is written in pure Ruby and does not
321
328
  have any support for executing JavaScript. Since the RackTest driver interacts
@@ -340,7 +347,7 @@ end
340
347
 
341
348
  See the section on adding and configuring drivers.
342
349
 
343
- ### Selenium
350
+ ### <a name="selenium"></a>Selenium
344
351
 
345
352
  At the moment, Capybara supports [Selenium 2.0
346
353
  (Webdriver)](http://seleniumhq.org/docs/01_introducing_selenium.html#selenium-2-aka-selenium-webdriver),
@@ -353,7 +360,7 @@ able to start using Selenium right away.
353
360
  same transaction as your tests, causing data not to be shared between your test
354
361
  and test server, see "Transactions and database setup" below.
355
362
 
356
- ### Capybara-webkit
363
+ ### <a name="capybara-webkit"></a>Capybara-webkit
357
364
 
358
365
  The [capybara-webkit driver](https://github.com/thoughtbot/capybara-webkit) is for true headless
359
366
  testing. It uses QtWebKit to start a rendering engine process. It can execute JavaScript as well.
@@ -371,7 +378,7 @@ And you can use it by:
371
378
  Capybara.javascript_driver = :webkit
372
379
  ```
373
380
 
374
- ### Poltergeist
381
+ ### <a name="poltergeist"></a>Poltergeist
375
382
 
376
383
  [Poltergeist](https://github.com/teampoltergeist/poltergeist) is another
377
384
  headless driver which integrates Capybara with
@@ -379,7 +386,7 @@ headless driver which integrates Capybara with
379
386
  require Xvfb to run on your CI server. It will also detect and report
380
387
  any Javascript errors that happen within the page.
381
388
 
382
- ## The DSL
389
+ ## <a name="the-dsl"></a>The DSL
383
390
 
384
391
  *A complete reference is available at
385
392
  [rubydoc.info](http://rubydoc.info/github/jnicklas/capybara/master)*.
@@ -390,7 +397,7 @@ any Javascript errors that happen within the page.
390
397
  **Note**: All searches in Capybara are *case sensitive*. This is because
391
398
  Capybara heavily uses XPath, which doesn't support case insensitivity.
392
399
 
393
- ### Navigating
400
+ ### <a name="navigating"></a>Navigating
394
401
 
395
402
  You can use the
396
403
  <tt>[visit](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#visit-instance_method)</tt>
@@ -416,7 +423,7 @@ expect(page).to have_current_path(post_comments_path(post))
416
423
  safer since it uses Capybara's [waiting behaviour](#asynchronous-javascript-ajax-and-friends)
417
424
  to ensure that preceding actions (such as a `click_link`) have completed.
418
425
 
419
- ### Clicking links and buttons
426
+ ### <a name="clicking-links-and-buttons"></a>Clicking links and buttons
420
427
 
421
428
  *Full reference: [Capybara::Node::Actions](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions)*
422
429
 
@@ -431,7 +438,7 @@ click_on('Link Text') # clicks on either links or buttons
431
438
  click_on('Button Value')
432
439
  ```
433
440
 
434
- ### Interacting with forms
441
+ ### <a name="interacting-with-forms"></a>Interacting with forms
435
442
 
436
443
  *Full reference: [Capybara::Node::Actions](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions)*
437
444
 
@@ -448,7 +455,7 @@ attach_file('Image', '/path/to/image.jpg')
448
455
  select('Option', :from => 'Select Box')
449
456
  ```
450
457
 
451
- ### Querying
458
+ ### <a name="querying"></a>Querying
452
459
 
453
460
  *Full reference: [Capybara::Node::Matchers](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers)*
454
461
 
@@ -478,7 +485,7 @@ expect(page).to have_css('table tr.foo')
478
485
  expect(page).to have_content('foo')
479
486
  ```
480
487
 
481
- ### Finding
488
+ ### <a name="finding"></a>Finding
482
489
 
483
490
  _Full reference: [Capybara::Node::Finders](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders)_
484
491
 
@@ -505,7 +512,7 @@ find('#navigation').click_link('Home')
505
512
  expect(find('#navigation')).to have_button('Sign out')
506
513
  ```
507
514
 
508
- ### Scoping
515
+ ### <a name="scoping"></a>Scoping
509
516
 
510
517
  Capybara makes it possible to restrict certain actions, such as interacting with
511
518
  forms or clicking links and buttons, to within a specific area of the page. For
@@ -537,7 +544,7 @@ within_table('Employee') do
537
544
  end
538
545
  ```
539
546
 
540
- ### Working with windows
547
+ ### <a name="working-with-windows"></a>Working with windows
541
548
 
542
549
  Capybara provides some methods to ease finding and switching windows:
543
550
 
@@ -552,7 +559,7 @@ within_window facebook_window do
552
559
  end
553
560
  ```
554
561
 
555
- ### Scripting
562
+ ### <a name="scripting"></a>Scripting
556
563
 
557
564
  In drivers which support it, you can easily execute JavaScript:
558
565
 
@@ -567,7 +574,7 @@ that this may break with more complicated expressions:
567
574
  result = page.evaluate_script('4 + 4');
568
575
  ```
569
576
 
570
- ### Modals
577
+ ### <a name="modals"></a>Modals
571
578
 
572
579
  In drivers which support it, you can accept, dismiss and respond to alerts, confirms and prompts.
573
580
 
@@ -605,7 +612,7 @@ end
605
612
  expect(message).to eq('Who is the chief architect of Linux?')
606
613
  ```
607
614
 
608
- ### Debugging
615
+ ### <a name="debugging"></a>Debugging
609
616
 
610
617
  It can be useful to take a snapshot of the page as it currently is and take a
611
618
  look at it:
@@ -636,12 +643,12 @@ Or have it save and automatically open:
636
643
  save_and_open_screenshot
637
644
  ```
638
645
 
639
- ## Matching
646
+ ## <a name="matching"></a>Matching
640
647
 
641
648
  It is possible to customize how Capybara finds elements. At your disposal
642
649
  are two options, `Capybara.exact` and `Capybara.match`.
643
650
 
644
- ### Exactness
651
+ ### <a name="exactness"></a>Exactness
645
652
 
646
653
  `Capybara.exact` and the `exact` option work together with the `is` expression
647
654
  inside the XPath gem. When `exact` is true, all `is` expressions match exactly,
@@ -658,7 +665,7 @@ click_link("Password") # does not match "Password confirmation"
658
665
  click_link("Password", exact: false) # can be overridden
659
666
  ```
660
667
 
661
- ### Strategy
668
+ ### <a name="strategy"></a>Strategy
662
669
 
663
670
  Using `Capybara.match` and the equivalent `match` option, you can control how
664
671
  Capybara behaves when multiple elements all match a query. There are currently
@@ -679,7 +686,7 @@ The default for `Capybara.match` is `:smart`. To emulate the behaviour in
679
686
  Capybara 2.0.x, set `Capybara.match` to `:one`. To emulate the behaviour in
680
687
  Capybara 1.x, set `Capybara.match` to `:prefer_exact`.
681
688
 
682
- ## Transactions and database setup
689
+ ## <a name="transactions-and-database-setup"></a>Transactions and database setup
683
690
 
684
691
  Some Capybara drivers need to run against an actual HTTP server. Capybara takes
685
692
  care of this and starts one for you in the same process as your test, but on
@@ -695,7 +702,7 @@ Cucumber handles this by using truncation instead of transactions, i.e. they
695
702
  empty out the entire database after each test. You can get the same behaviour
696
703
  by using a gem such as [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner).
697
704
 
698
- ## Asynchronous JavaScript (Ajax and friends)
705
+ ## <a name="asynchronous-javascript-ajax-and-friends"></a>Asynchronous JavaScript (Ajax and friends)
699
706
 
700
707
  When working with asynchronous JavaScript, you might come across situations
701
708
  where you are attempting to interact with an element which is not yet present
@@ -735,7 +742,7 @@ The former would immediately fail because the content has not yet been removed.
735
742
  Only the latter would wait for the asynchronous process to remove the content
736
743
  from the page.
737
744
 
738
- Capybara's Rspec matchers, however, are smart enough to handle either form.
745
+ Capybara's RSpec matchers, however, are smart enough to handle either form.
739
746
  The two following statements are functionally equivalent:
740
747
 
741
748
  ```ruby
@@ -757,7 +764,7 @@ the text of the `h1` to "Something", and this happened, this test would
757
764
  pass. If you do not want this behaviour, you can set
758
765
  `Capybara.automatic_reload` to `false`.
759
766
 
760
- ## Using the DSL elsewhere
767
+ ## <a name="using-the-dsl-elsewhere"></a>Using the DSL elsewhere
761
768
 
762
769
  You can mix the DSL into any context by including <tt>Capybara::DSL</tt>:
763
770
 
@@ -782,7 +789,7 @@ end
782
789
 
783
790
  This enables its use in unsupported testing frameworks, and for general-purpose scripting.
784
791
 
785
- ## Calling remote servers
792
+ ## <a name="calling-remote-servers"></a>Calling remote servers
786
793
 
787
794
  Normally Capybara expects to be testing an in-process Rack application, but you
788
795
  can also use it to talk to a web server running anywhere on the internet, by
@@ -811,7 +818,7 @@ remote application:
811
818
  Capybara.run_server = false
812
819
  ```
813
820
 
814
- ## Using the sessions manually
821
+ ## <a name="using-the-sessions-manually"></a>Using the sessions manually
815
822
 
816
823
  For ultimate control, you can instantiate and use a
817
824
  [Session](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session)
@@ -828,7 +835,7 @@ end
828
835
  session.click_button 'Sign in'
829
836
  ```
830
837
 
831
- ## XPath, CSS and selectors
838
+ ## <a name="xpath-css-and-selectors"></a>XPath, CSS and selectors
832
839
 
833
840
  Capybara does not try to guess what kind of selector you are going to give it,
834
841
  and will always use CSS by default. If you want to use XPath, you'll need to
@@ -874,7 +881,7 @@ find(:row, 3)
874
881
  find(:flash_type, :notice)
875
882
  ```
876
883
 
877
- ## Beware the XPath // trap
884
+ ## <a name="beware-the-xpath--trap"></a>Beware the XPath // trap
878
885
 
879
886
  In XPath the expression // means something very specific, and it might not be what
880
887
  you think. Contrary to common belief, // means "anywhere in the document" not "anywhere
@@ -902,7 +909,7 @@ within(:xpath, '//body') do
902
909
  end
903
910
  ```
904
911
 
905
- ## Configuring and adding drivers
912
+ ## <a name="configuring-and-adding-drivers"></a>Configuring and adding drivers
906
913
 
907
914
  Capybara makes it convenient to switch between different drivers. It also exposes
908
915
  an API to tweak those drivers with whatever settings you want, or to add your own
@@ -934,7 +941,7 @@ Gems can use this API to add their own drivers to Capybara.
934
941
  The [Selenium wiki](https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings) has
935
942
  additional info about how the underlying driver can be configured.
936
943
 
937
- ## Gotchas:
944
+ ## <a name="gotchas"></a>Gotchas:
938
945
 
939
946
  * Access to session and request is not possible from the test, Access to
940
947
  response is limited. Some drivers allow access to response headers and HTTP
@@ -962,7 +969,7 @@ additional info about how the underlying driver can be configured.
962
969
  are testing for specific server errors and using multiple sessions make sure to test for the
963
970
  errors using the initial session (usually :default)
964
971
 
965
- ## Development
972
+ ## <a name="development"></a>Development
966
973
 
967
974
  To set up a development environment, simply do:
968
975
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'capybara/dsl'
2
3
  require 'capybara/rspec/matchers'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Capybara::Driver::Base
2
3
  def current_url
3
4
  raise NotImplementedError
@@ -90,8 +91,8 @@ class Capybara::Driver::Base
90
91
  def no_such_window_error
91
92
  raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#no_such_window_error'
92
93
  end
93
-
94
-
94
+
95
+
95
96
  ##
96
97
  #
97
98
  # Execute the block, and then accept the modal opened.
@@ -134,7 +135,9 @@ class Capybara::Driver::Base
134
135
  false
135
136
  end
136
137
 
138
+ # @deprecated This method is being removed
137
139
  def browser_initialized?
140
+ warn "DEPRECATED: #browser_initialized? is deprecated and will be removed in the next version of Capybara"
138
141
  true
139
142
  end
140
143
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  module Driver
3
4
  class Node
data/lib/capybara/dsl.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'capybara'
2
3
 
3
4
  module Capybara
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Capybara
4
5
 
@@ -96,7 +97,7 @@ module Capybara
96
97
  # @option [Integer] minimum Count should have been larger than or equal to this value
97
98
  #
98
99
  def failure_message(description, options={})
99
- message = "expected to find #{description}"
100
+ message = String.new("expected to find #{description}")
100
101
  if options[:count]
101
102
  message << " #{options[:count]} #{declension('time', 'times', options[:count])}"
102
103
  elsif options[:between]
@@ -129,7 +130,7 @@ module Capybara
129
130
 
130
131
  if defined?(Process::CLOCK_MONOTONIC)
131
132
  def monotonic_time
132
- Process.clock_gettime Process::CLOCK_MONOTONIC
133
+ Process.clock_gettime Process::CLOCK_MONOTONIC
133
134
  end
134
135
  else
135
136
  def monotonic_time
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  module Node
3
4
  module Actions
@@ -150,6 +151,11 @@ module Capybara
150
151
  # @param [String] locator Which field to attach the file to
151
152
  # @param [String] path The path of the file that will be attached, or an array of paths
152
153
  #
154
+ # @option options [Symbol] match (Capybara.match) The matching strategy to use (:one, :first, :prefer_exact, :smart).
155
+ # @option options [Boolean] exact (Capybara.exact) Match the exact label name/contents or accept a partial match.
156
+ # @option options [Fixnum] wait (Capybara.default_max_wait_time) If using a Javascript driver, maximum number of seconds during which the element will be searched for.
157
+ # @option options [Boolean] multiple Match field which allows multiple file selection
158
+ #
153
159
  def attach_file(locator, path, options={})
154
160
  Array(path).each do |p|
155
161
  raise Capybara::FileNotFound, "cannot attach file, #{p} does not exist" unless File.exist?(p.to_s)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  module Node
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  module Node
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  module Node
3
4
  module DocumentMatchers
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  module Node
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  module Node
3
4
  module Finders
@@ -28,7 +29,7 @@ module Capybara
28
29
  # @raise [Capybara::ElementNotFound] If the element can't be found before time expires
29
30
  #
30
31
  def find(*args)
31
- query = Capybara::Query.new(*args)
32
+ query = Capybara::Queries::SelectorQuery.new(*args)
32
33
  synchronize(query.wait) do
33
34
  if query.match == :smart or query.match == :prefer_exact
34
35
  result = query.resolve_for(self, true)
@@ -177,7 +178,7 @@ module Capybara
177
178
  # @return [Capybara::Result] A collection of found elements
178
179
  #
179
180
  def all(*args)
180
- query = Capybara::Query.new(*args)
181
+ query = Capybara::Queries::SelectorQuery.new(*args)
181
182
  synchronize(query.wait) do
182
183
  result = query.resolve_for(self)
183
184
  raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?