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
@@ -89,29 +89,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
89
89
 
90
90
  context 'on a page or node' do
91
91
  before do
92
- visit('/with_html')
92
+ session.visit('/with_html')
93
93
  end
94
94
 
95
95
  context 'with should' do
96
96
  it 'passes if has_css? returns true' do
97
- expect(page).to have_css('h1')
97
+ expect(session).to have_css('h1')
98
98
  end
99
99
 
100
100
  it 'fails if has_css? returns false' do
101
101
  expect do
102
- expect(page).to have_css('h1#doesnotexist')
102
+ expect(session).to have_css('h1#doesnotexist')
103
103
  end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
104
104
  end
105
105
  end
106
106
 
107
107
  context 'with should_not' do
108
108
  it 'passes if has_no_css? returns true' do
109
- expect(page).not_to have_css('h1#doesnotexist')
109
+ expect(session).not_to have_css('h1#doesnotexist')
110
110
  end
111
111
 
112
112
  it 'fails if has_no_css? returns false' do
113
113
  expect do
114
- expect(page).not_to have_css('h1')
114
+ expect(session).not_to have_css('h1')
115
115
  end.to raise_error(/expected not to find visible css "h1"/)
116
116
  end
117
117
  end
@@ -158,29 +158,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
158
158
 
159
159
  context 'on a page or node' do
160
160
  before do
161
- visit('/with_html')
161
+ session.visit('/with_html')
162
162
  end
163
163
 
164
164
  context 'with should' do
165
165
  it 'passes if has_xpath? returns true' do
166
- expect(page).to have_xpath('//h1')
166
+ expect(session).to have_xpath('//h1')
167
167
  end
168
168
 
169
169
  it 'fails if has_xpath? returns false' do
170
170
  expect do
171
- expect(page).to have_xpath("//h1[@id='doesnotexist']")
171
+ expect(session).to have_xpath("//h1[@id='doesnotexist']")
172
172
  end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
173
173
  end
174
174
  end
175
175
 
176
176
  context 'with should_not' do
177
177
  it 'passes if has_no_xpath? returns true' do
178
- expect(page).not_to have_xpath('//h1[@id="doesnotexist"]')
178
+ expect(session).not_to have_xpath('//h1[@id="doesnotexist"]')
179
179
  end
180
180
 
181
181
  it 'fails if has_no_xpath? returns false' do
182
182
  expect do
183
- expect(page).not_to have_xpath('//h1')
183
+ expect(session).not_to have_xpath('//h1')
184
184
  end.to raise_error(%r{expected not to find visible xpath "//h1"})
185
185
  end
186
186
  end
@@ -222,35 +222,35 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
222
222
 
223
223
  context 'on a page or node' do
224
224
  before do
225
- visit('/with_html')
225
+ session.visit('/with_html')
226
226
  end
227
227
 
228
228
  context 'with should' do
229
229
  it 'passes if has_selector? returns true' do
230
- expect(page).to have_selector('//h1', text: 'test')
230
+ expect(session).to have_selector('//h1', text: 'test')
231
231
  end
232
232
 
233
233
  it 'fails if has_selector? returns false' do
234
234
  expect do
235
- expect(page).to have_selector("//h1[@id='doesnotexist']")
235
+ expect(session).to have_selector("//h1[@id='doesnotexist']")
236
236
  end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
237
237
  end
238
238
 
239
239
  it 'includes text in error message' do
240
240
  expect do
241
- expect(page).to have_selector('//h1', text: 'wrong text')
241
+ expect(session).to have_selector('//h1', text: 'wrong text')
242
242
  end.to raise_error(%r{expected to find visible xpath "//h1" with text "wrong text" but there were no matches})
243
243
  end
244
244
  end
245
245
 
246
246
  context 'with should_not' do
247
247
  it 'passes if has_no_css? returns true' do
248
- expect(page).not_to have_selector(:css, 'h1#doesnotexist')
248
+ expect(session).not_to have_selector(:css, 'h1#doesnotexist')
249
249
  end
250
250
 
251
251
  it 'fails if has_no_selector? returns false' do
252
252
  expect do
253
- expect(page).not_to have_selector(:css, 'h1', text: 'test')
253
+ expect(session).not_to have_selector(:css, 'h1', text: 'test')
254
254
  end.to raise_error(/expected not to find visible css "h1" with text "test"/)
255
255
  end
256
256
  end
@@ -265,7 +265,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
265
265
 
266
266
  describe 'have_content matcher' do
267
267
  it 'gives proper description' do
268
- expect(have_content('Text').description).to eq('text "Text"')
268
+ expect(have_content('Text').description).to eq('have text "Text"')
269
269
  end
270
270
 
271
271
  context 'on a string' do
@@ -304,21 +304,21 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
304
304
 
305
305
  context 'on a page or node' do
306
306
  before do
307
- visit('/with_html')
307
+ session.visit('/with_html')
308
308
  end
309
309
 
310
310
  context 'with should' do
311
311
  it 'passes if has_content? returns true' do
312
- expect(page).to have_content('This is a test')
312
+ expect(session).to have_content('This is a test')
313
313
  end
314
314
 
315
315
  it 'passes if has_content? returns true using regexp' do
316
- expect(page).to have_content(/test/)
316
+ expect(session).to have_content(/test/)
317
317
  end
318
318
 
319
319
  it 'fails if has_content? returns false' do
320
320
  expect do
321
- expect(page).to have_content('No such Text')
321
+ expect(session).to have_content('No such Text')
322
322
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
323
323
  end
324
324
 
@@ -329,7 +329,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
329
329
 
330
330
  it 'fails if has_content? returns false' do
331
331
  expect do
332
- expect(page).to have_content('No such Text')
332
+ expect(session).to have_content('No such Text')
333
333
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
334
334
  end
335
335
  end
@@ -337,14 +337,26 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
337
337
 
338
338
  context 'with should_not' do
339
339
  it 'passes if has_no_content? returns true' do
340
- expect(page).not_to have_content('No such Text')
340
+ expect(session).not_to have_content('No such Text')
341
341
  end
342
342
 
343
343
  it 'fails if has_no_content? returns false' do
344
344
  expect do
345
- expect(page).not_to have_content('This is a test')
345
+ expect(session).not_to have_content('This is a test')
346
346
  end.to raise_error(/expected not to find text "This is a test"/)
347
347
  end
348
+
349
+ it 'not_to have_content behaves the same as to have_no_content' do
350
+ Capybara.using_wait_time(5) do
351
+ expect(session).to have_content('This is a test')
352
+ start = Time.now
353
+ expect(session).to have_no_content('No such Text')
354
+ to_time = Time.now
355
+ expect(session).not_to have_content('No such Text')
356
+ not_to_time = Time.now
357
+ expect(not_to_time - to_time).to be_within(0.5).of(to_time - start)
358
+ end
359
+ end
348
360
  end
349
361
  end
350
362
 
@@ -357,7 +369,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
357
369
 
358
370
  describe 'have_text matcher' do
359
371
  it 'gives proper description' do
360
- expect(have_text('Text').description).to eq('text "Text"')
372
+ expect(have_text('Text').description).to eq('have text "Text"')
361
373
  end
362
374
 
363
375
  context 'on a string' do
@@ -432,30 +444,30 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
432
444
 
433
445
  context 'on a page or node' do
434
446
  before do
435
- visit('/with_html')
447
+ session.visit('/with_html')
436
448
  end
437
449
 
438
450
  context 'with should' do
439
451
  it 'passes if has_text? returns true' do
440
- expect(page).to have_text('This is a test')
452
+ expect(session).to have_text('This is a test')
441
453
  end
442
454
 
443
455
  it 'passes if has_text? returns true using regexp' do
444
- expect(page).to have_text(/test/)
456
+ expect(session).to have_text(/test/)
445
457
  end
446
458
 
447
459
  it 'can check for all text' do
448
- expect(page).to have_text(:all, 'Some of this text is hidden!')
460
+ expect(session).to have_text(:all, 'Some of this text is hidden!')
449
461
  end
450
462
 
451
463
  it 'can check for visible text' do
452
- expect(page).to have_text(:visible, 'Some of this text is')
453
- expect(page).not_to have_text(:visible, 'Some of this text is hidden!')
464
+ expect(session).to have_text(:visible, 'Some of this text is')
465
+ expect(session).not_to have_text(:visible, 'Some of this text is hidden!')
454
466
  end
455
467
 
456
468
  it 'fails if has_text? returns false' do
457
469
  expect do
458
- expect(page).to have_text('No such Text')
470
+ expect(session).to have_text('No such Text')
459
471
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
460
472
  end
461
473
 
@@ -466,7 +478,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
466
478
 
467
479
  it 'fails if has_text? returns false' do
468
480
  expect do
469
- expect(page).to have_text('No such Text')
481
+ expect(session).to have_text('No such Text')
470
482
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
471
483
  end
472
484
  end
@@ -474,12 +486,12 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
474
486
 
475
487
  context 'with should_not' do
476
488
  it 'passes if has_no_text? returns true' do
477
- expect(page).not_to have_text('No such Text')
489
+ expect(session).not_to have_text('No such Text')
478
490
  end
479
491
 
480
492
  it 'fails if has_no_text? returns false' do
481
493
  expect do
482
- expect(page).not_to have_text('This is a test')
494
+ expect(session).not_to have_text('This is a test')
483
495
  end.to raise_error(/expected not to find text "This is a test"/)
484
496
  end
485
497
  end
@@ -542,34 +554,33 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
542
554
 
543
555
  context 'on a page or node' do
544
556
  it 'passes if there is such a title' do
545
- visit('/with_js')
546
- expect(page).to have_title('with_js')
557
+ session.visit('/with_js')
558
+ expect(session).to have_title('with_js')
547
559
  end
548
560
 
549
561
  it 'fails if there is no such title' do
550
- visit('/with_js')
562
+ session.visit('/with_js')
551
563
  expect do
552
- expect(page).to have_title('No such title')
553
- end.to raise_error('expected "with_js" to include "No such title"')
564
+ expect(session).to have_title('No such title')
565
+ end.to raise_error(/ to include "No such title"/)
554
566
  end
555
567
 
556
568
  context 'with wait' do
557
569
  before do
558
- @session = session
559
- @session.visit('/with_js')
570
+ session.visit('/with_js')
560
571
  end
561
572
 
562
573
  it 'waits if wait time is more than timeout' do
563
- @session.click_link('Change title')
564
- using_wait_time 0 do
565
- expect(@session).to have_title('changed title', wait: 2)
574
+ session.click_link('Change title')
575
+ session.using_wait_time 0 do
576
+ expect(session).to have_title('changed title', wait: 2)
566
577
  end
567
578
  end
568
579
 
569
580
  it "doesn't wait if wait time is less than timeout" do
570
- @session.click_link('Change title')
571
- using_wait_time 3 do
572
- expect(@session).not_to have_title('changed title', wait: 0)
581
+ session.click_link('Change title')
582
+ session.using_wait_time 3 do
583
+ expect(session).not_to have_title('changed title', wait: 0)
573
584
  end
574
585
  end
575
586
  end
@@ -587,50 +598,53 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
587
598
 
588
599
  context 'on a page or node' do
589
600
  it 'passes if there is such a current path' do
590
- visit('/with_js')
591
- expect(page).to have_current_path('/with_js')
601
+ session.visit('/with_js')
602
+ expect(session).to have_current_path('/with_js')
592
603
  end
593
604
 
594
605
  it 'fails if there is no such current_path' do
595
606
  visit('/with_js')
596
607
  expect do
597
- expect(page).to have_current_path('/not_with_js')
598
- end.to raise_error('expected "/with_js" to equal "/not_with_js"')
608
+ expect(session).to have_current_path('/not_with_js')
609
+ end.to raise_error(%r{to equal "/not_with_js"})
599
610
  end
600
611
 
601
612
  context 'with wait' do
602
613
  before do
603
- @session = session
604
- @session.visit('/with_js')
614
+ session.visit('/with_js')
605
615
  end
606
616
 
607
617
  it 'waits if wait time is more than timeout' do
608
- @session.click_link('Change page')
609
- using_wait_time 0 do
610
- expect(@session).to have_current_path('/with_html', wait: 2)
618
+ session.click_link('Change page')
619
+ session.using_wait_time 0 do
620
+ expect(session).to have_current_path('/with_html', wait: 2)
611
621
  end
612
622
  end
613
623
 
614
624
  it "doesn't wait if wait time is less than timeout" do
615
- @session.click_link('Change page')
616
- using_wait_time 0 do
617
- expect(@session).not_to have_current_path('/with_html')
625
+ session.click_link('Change page')
626
+ session.using_wait_time 0 do
627
+ expect(session).not_to have_current_path('/with_html')
618
628
  end
619
629
  end
620
630
  end
621
631
  end
622
632
 
623
633
  it 'supports compounding' do
624
- visit('/with_html')
625
- expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html')
634
+ session.visit('/with_html')
635
+ expect(session).to have_current_path('/not_with_html').or have_current_path('/with_html')
626
636
  end
627
637
  end
628
638
 
629
639
  describe 'have_button matcher' do
630
640
  let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
631
641
 
632
- it 'gives proper description' do
633
- expect(have_button('A button').description).to eq('have visible button "A button"')
642
+ it 'gives proper description with no options' do
643
+ expect(have_button('A button').description).to eq('have visible button "A button" that is not disabled')
644
+ end
645
+
646
+ it 'gives proper description with disabled :any option' do
647
+ expect(have_button('A button', disabled: :all).description).to eq('have visible button "A button"')
634
648
  end
635
649
 
636
650
  it 'passes if there is such a button' do
@@ -680,12 +694,12 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
680
694
  end
681
695
 
682
696
  it 'treats a given value as a string' do
683
- class Foo
697
+ foo = Class.new do
684
698
  def to_s
685
699
  'some value'
686
700
  end
687
701
  end
688
- expect(html).to have_field('Text field', with: Foo.new)
702
+ expect(html).to have_field('Text field', with: foo.new)
689
703
  end
690
704
 
691
705
  it 'supports compounding' do
@@ -700,7 +714,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
700
714
  end
701
715
 
702
716
  it 'gives proper description' do
703
- expect(have_checked_field('it is checked').description).to eq('have visible field "it is checked" that is checked and not disabled')
717
+ expect(have_checked_field('it is checked').description).to eq('have visible field "it is checked" that is not disabled that is checked')
704
718
  end
705
719
 
706
720
  context 'with should' do
@@ -749,7 +763,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
749
763
  end
750
764
 
751
765
  it 'gives proper description' do
752
- expect(have_unchecked_field('unchecked field').description).to eq('have visible field "unchecked field" that is not checked and not disabled')
766
+ expect(have_unchecked_field('unchecked field').description).to eq('have visible field "unchecked field" that is not disabled that is not checked')
753
767
  end
754
768
 
755
769
  context 'with should' do
@@ -826,10 +840,10 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
826
840
  end
827
841
 
828
842
  it 'gives proper description when :visible option passed' do
829
- expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"')
843
+ expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher
830
844
  expect(have_table('Lovely table', visible: :hidden).description).to eq('have non-visible table "Lovely table"')
831
845
  expect(have_table('Lovely table', visible: :all).description).to eq('have table "Lovely table"')
832
- expect(have_table('Lovely table', visible: false).description).to eq('have table "Lovely table"')
846
+ expect(have_table('Lovely table', visible: false).description).to eq('have table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher
833
847
  end
834
848
 
835
849
  it 'passes if there is such a table' do
@@ -848,94 +862,95 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
848
862
  end
849
863
 
850
864
  context 'compounding timing' do
865
+ let(:session) { session }
866
+ let(:el) { session.find(:css, '#reload-me') }
867
+
851
868
  before do
852
- @session = session
853
- @session.visit('/with_js')
854
- @el = @session.find(:css, '#reload-me')
869
+ session.visit('/with_js')
855
870
  end
856
871
 
857
- context '#and' do
872
+ describe '#and' do
858
873
  it "should run 'concurrently'" do
859
- Capybara.using_wait_time(2) do
874
+ session.using_wait_time(2) do
860
875
  matcher = have_text('this is not there').and have_text('neither is this')
861
876
  expect(Benchmark.realtime do
862
877
  expect do
863
- expect(@el).to matcher
878
+ expect(el).to matcher
864
879
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
865
880
  end).to be_between(2, 3)
866
881
  end
867
882
  end
868
883
 
869
884
  it "should run 'concurrently' and retry" do
870
- @session.click_link('reload-link')
871
- @session.using_wait_time(2) do
885
+ session.click_link('reload-link')
886
+ session.using_wait_time(2) do
872
887
  expect(Benchmark.realtime do
873
888
  expect do
874
- expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
889
+ expect(el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
875
890
  end.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
876
891
  end).to be_between(2, 3)
877
892
  end
878
893
  end
879
894
 
880
895
  it 'should ignore :wait options' do
881
- @session.using_wait_time(2) do
896
+ session.using_wait_time(2) do
882
897
  matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6)
883
898
  expect(Benchmark.realtime do
884
899
  expect do
885
- expect(@el).to matcher
900
+ expect(el).to matcher
886
901
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
887
902
  end).to be_between(2, 3)
888
903
  end
889
904
  end
890
905
 
891
906
  it 'should work on the session' do
892
- @session.using_wait_time(2) do
893
- @session.click_link('reload-link')
894
- expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
907
+ session.using_wait_time(2) do
908
+ session.click_link('reload-link')
909
+ expect(session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
895
910
  end
896
911
  end
897
912
  end
898
913
 
899
- context '#and_then' do
914
+ describe '#and_then' do
900
915
  it 'should run sequentially' do
901
- @session.click_link('reload-link')
902
- expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
916
+ session.click_link('reload-link')
917
+ expect(el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
903
918
  end
904
919
  end
905
920
 
906
- context '#or' do
921
+ describe '#or' do
907
922
  it "should run 'concurrently'" do
908
- @session.using_wait_time(3) do
923
+ session.using_wait_time(3) do
909
924
  expect(Benchmark.realtime do
910
- expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
925
+ expect(el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
911
926
  end).to be < 1
912
927
  end
913
928
  end
914
929
 
915
930
  it 'should retry' do
916
- @session.using_wait_time(3) do
931
+ session.using_wait_time(3) do
917
932
  expect(Benchmark.realtime do
918
933
  expect do
919
- expect(@el).to have_text('has been reloaded').or have_text('random stuff')
934
+ expect(el).to have_text('has been reloaded').or have_text('random stuff')
920
935
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
921
936
  end).to be > 3
922
937
  end
923
938
  end
924
939
 
925
940
  it 'should ignore :wait options' do
926
- @session.using_wait_time(2) do
941
+ session.using_wait_time(2) do
927
942
  expect(Benchmark.realtime do
928
943
  expect do
929
- expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
944
+ expect(el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
930
945
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
931
946
  end).to be_between(2, 3)
932
947
  end
933
948
  end
934
949
 
935
950
  it 'should work on the session' do
936
- @session.using_wait_time(2) do
937
- @session.click_link('reload-link')
938
- expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
951
+ session.using_wait_time(2) do
952
+ session.click_link('reload-link')
953
+ expect(session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
939
954
  end
940
955
  end
941
956
  end
data/spec/rspec_spec.rb CHANGED
@@ -43,7 +43,7 @@ RSpec.describe 'capybara/rspec' do
43
43
  expect(Capybara.current_driver).to eq(:culerity)
44
44
  end
45
45
 
46
- context '#all' do
46
+ describe '#all' do
47
47
  it 'allows access to the Capybara finder' do
48
48
  visit('/with_html')
49
49
  found = all(:css, 'h2') { |element| element[:class] == 'head' }
@@ -57,7 +57,7 @@ RSpec.describe 'capybara/rspec' do
57
57
  end
58
58
  end
59
59
 
60
- context '#within' do
60
+ describe '#within' do
61
61
  it 'allows access to the Capybara scoper' do
62
62
  visit('/with_html')
63
63
  expect do
@@ -75,40 +75,58 @@ RSpec.describe 'capybara/rspec' do
75
75
 
76
76
  context 'Type: Other', type: :other do
77
77
  context 'when RSpec::Matchers is included after Capybara::DSL' do
78
- before do
79
- class DSLMatchersTest
78
+ let(:test_class_instance) do
79
+ Class.new do
80
80
  include Capybara::DSL
81
81
  include RSpec::Matchers
82
- end
83
-
84
- @test_class_instance = DSLMatchersTest.new
82
+ end.new
85
83
  end
86
84
 
87
- context '#all' do
85
+ describe '#all' do
88
86
  it 'allows access to the Capybara finder' do
89
- @test_class_instance.visit('/with_html')
90
- expect(@test_class_instance.all(:css, 'h2.head').size).to eq(5)
87
+ test_class_instance.visit('/with_html')
88
+ expect(test_class_instance.all(:css, 'h2.head').size).to eq(5)
91
89
  end
92
90
 
93
91
  it 'allows access to the RSpec matcher' do
94
- @test_class_instance.visit('/with_html')
92
+ test_class_instance.visit('/with_html')
95
93
  strings = %w[test1 test2]
96
- expect(strings).to @test_class_instance.all(be_a(String))
94
+ expect(strings).to test_class_instance.all(be_a(String))
97
95
  end
98
96
  end
99
97
 
100
- context '#within' do
98
+ describe '#within' do
101
99
  it 'allows access to the Capybara scoper' do
102
- @test_class_instance.visit('/with_html')
100
+ test_class_instance.visit('/with_html')
103
101
  expect do
104
- @test_class_instance.within(:css, '#does_not_exist') { @test_class_instance.click_link 'Go to simple' }
102
+ test_class_instance.within(:css, '#does_not_exist') { test_class_instance.click_link 'Go to simple' }
105
103
  end.to raise_error(Capybara::ElementNotFound)
106
104
  end
107
105
 
108
106
  it 'allows access to the RSpec matcher' do
109
- @test_class_instance.visit('/with_html')
107
+ test_class_instance.visit('/with_html')
110
108
  # This reads terribly, but must call #within
111
- expect(@test_class_instance.find(:css, 'span.number').text.to_i).to @test_class_instance.within(1).of(41)
109
+ expect(test_class_instance.find(:css, 'span.number').text.to_i).to test_class_instance.within(1).of(41)
110
+ end
111
+ end
112
+
113
+ context 'when `match_when_negated` is not defined in a matcher' do
114
+ before do
115
+ RSpec::Matchers.define :only_match_matcher do |expected|
116
+ match do |actual|
117
+ !(actual ^ expected)
118
+ end
119
+ end
120
+ end
121
+
122
+ it 'can be called with `not_to`' do
123
+ # This test is for a bug in jruby where `super` isn't defined correctly - https://github.com/jruby/jruby/issues/4678
124
+ # Reported in https://github.com/teamcapybara/capybara/issues/2115
125
+ test_class_instance.instance_eval do
126
+ expect do
127
+ expect(true).not_to only_match_matcher(false) # rubocop:disable RSpec/ExpectActual
128
+ end.not_to raise_error
129
+ end
112
130
  end
113
131
  end
114
132
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'selenium-webdriver'
5
+
6
+ require 'sauce_whisk'
7
+ # require 'shared_selenium_session'
8
+ # require 'shared_selenium_node'
9
+ # require 'rspec/shared_spec_matchers'
10
+
11
+ Capybara.register_driver :sauce_chrome do |app|
12
+ options = {
13
+ selenium_version: '3.141.59',
14
+ platform: 'macOS 10.12',
15
+ browser_name: 'chrome',
16
+ version: '65.0',
17
+ name: 'Capybara test',
18
+ build: ENV['TRAVIS_REPO_SLUG'] || "Ruby-RSpec-Selenium: Local-#{Time.now.to_i}",
19
+ username: ENV['SAUCE_USERNAME'],
20
+ access_key: ENV['SAUCE_ACCESS_KEY']
21
+ }
22
+
23
+ options.delete(:browser_name)
24
+
25
+ capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(options)
26
+ url = 'https://ondemand.saucelabs.com:443/wd/hub'
27
+
28
+ Capybara::Selenium::Driver.new(app,
29
+ browser: :remote, url: url,
30
+ desired_capabilities: capabilities,
31
+ options: Selenium::WebDriver::Chrome::Options.new(args: ['']))
32
+ end
33
+
34
+ CHROME_REMOTE_DRIVER = :sauce_chrome
35
+
36
+ module TestSessions
37
+ Chrome = Capybara::Session.new(CHROME_REMOTE_DRIVER, TestApp)
38
+ end
39
+
40
+ skipped_tests = %i[response_headers status_code trigger download]
41
+
42
+ Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_REMOTE_DRIVER.to_s, capybara_skip: skipped_tests do |example|
43
+ end