capybara 2.5.0 → 2.18.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 (205) hide show
  1. checksums.yaml +5 -5
  2. data/.yard/templates_custom/default/class/html/selectors.erb +38 -0
  3. data/.yard/templates_custom/default/class/html/setup.rb +17 -0
  4. data/.yard/yard_extensions.rb +78 -0
  5. data/.yardopts +1 -0
  6. data/History.md +413 -10
  7. data/License.txt +1 -1
  8. data/README.md +237 -130
  9. data/lib/capybara/config.rb +132 -0
  10. data/lib/capybara/cucumber.rb +3 -1
  11. data/lib/capybara/driver/base.rb +27 -6
  12. data/lib/capybara/driver/node.rb +14 -5
  13. data/lib/capybara/dsl.rb +2 -3
  14. data/lib/capybara/helpers.rb +13 -65
  15. data/lib/capybara/minitest/spec.rb +177 -0
  16. data/lib/capybara/minitest.rb +278 -0
  17. data/lib/capybara/node/actions.rb +180 -24
  18. data/lib/capybara/node/base.rb +17 -5
  19. data/lib/capybara/node/document.rb +5 -0
  20. data/lib/capybara/node/document_matchers.rb +15 -14
  21. data/lib/capybara/node/element.rb +55 -7
  22. data/lib/capybara/node/finders.rb +179 -67
  23. data/lib/capybara/node/matchers.rb +301 -105
  24. data/lib/capybara/node/simple.rb +15 -4
  25. data/lib/capybara/queries/ancestor_query.rb +25 -0
  26. data/lib/capybara/queries/base_query.rb +69 -3
  27. data/lib/capybara/queries/current_path_query.rb +17 -8
  28. data/lib/capybara/queries/match_query.rb +19 -0
  29. data/lib/capybara/queries/selector_query.rb +251 -0
  30. data/lib/capybara/queries/sibling_query.rb +25 -0
  31. data/lib/capybara/queries/text_query.rb +67 -16
  32. data/lib/capybara/queries/title_query.rb +4 -2
  33. data/lib/capybara/query.rb +3 -131
  34. data/lib/capybara/rack_test/browser.rb +14 -5
  35. data/lib/capybara/rack_test/css_handlers.rb +1 -0
  36. data/lib/capybara/rack_test/driver.rb +15 -8
  37. data/lib/capybara/rack_test/form.rb +34 -12
  38. data/lib/capybara/rack_test/node.rb +29 -12
  39. data/lib/capybara/rails.rb +3 -3
  40. data/lib/capybara/result.rb +104 -9
  41. data/lib/capybara/rspec/compound.rb +95 -0
  42. data/lib/capybara/rspec/features.rb +17 -6
  43. data/lib/capybara/rspec/matcher_proxies.rb +45 -0
  44. data/lib/capybara/rspec/matchers.rb +199 -80
  45. data/lib/capybara/rspec.rb +4 -2
  46. data/lib/capybara/selector/css.rb +30 -0
  47. data/lib/capybara/selector/filter.rb +20 -0
  48. data/lib/capybara/selector/filter_set.rb +74 -0
  49. data/lib/capybara/selector/filters/base.rb +33 -0
  50. data/lib/capybara/selector/filters/expression_filter.rb +40 -0
  51. data/lib/capybara/selector/filters/node_filter.rb +27 -0
  52. data/lib/capybara/selector/selector.rb +276 -0
  53. data/lib/capybara/selector.rb +452 -157
  54. data/lib/capybara/selenium/driver.rb +282 -81
  55. data/lib/capybara/selenium/node.rb +144 -46
  56. data/lib/capybara/server.rb +59 -16
  57. data/lib/capybara/session/config.rb +114 -0
  58. data/lib/capybara/session/matchers.rb +29 -19
  59. data/lib/capybara/session.rb +378 -143
  60. data/lib/capybara/spec/fixtures/no_extension +1 -0
  61. data/lib/capybara/spec/public/jquery-ui.js +13 -791
  62. data/lib/capybara/spec/public/jquery.js +4 -9045
  63. data/lib/capybara/spec/public/test.js +45 -11
  64. data/lib/capybara/spec/session/accept_alert_spec.rb +30 -7
  65. data/lib/capybara/spec/session/accept_confirm_spec.rb +14 -2
  66. data/lib/capybara/spec/session/accept_prompt_spec.rb +35 -6
  67. data/lib/capybara/spec/session/all_spec.rb +45 -32
  68. data/lib/capybara/spec/session/ancestor_spec.rb +85 -0
  69. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +110 -0
  70. data/lib/capybara/spec/session/assert_current_path.rb +15 -2
  71. data/lib/capybara/spec/session/assert_selector.rb +29 -28
  72. data/lib/capybara/spec/session/assert_text.rb +59 -20
  73. data/lib/capybara/spec/session/assert_title.rb +25 -11
  74. data/lib/capybara/spec/session/attach_file_spec.rb +42 -4
  75. data/lib/capybara/spec/session/body_spec.rb +1 -0
  76. data/lib/capybara/spec/session/check_spec.rb +90 -14
  77. data/lib/capybara/spec/session/choose_spec.rb +31 -5
  78. data/lib/capybara/spec/session/click_button_spec.rb +20 -9
  79. data/lib/capybara/spec/session/click_link_or_button_spec.rb +15 -9
  80. data/lib/capybara/spec/session/click_link_spec.rb +39 -15
  81. data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
  82. data/lib/capybara/spec/session/current_url_spec.rb +12 -3
  83. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +6 -5
  84. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +4 -3
  85. data/lib/capybara/spec/session/element/assert_match_selector.rb +36 -0
  86. data/lib/capybara/spec/session/element/match_css_spec.rb +23 -0
  87. data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
  88. data/lib/capybara/spec/session/element/matches_selector_spec.rb +106 -0
  89. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +22 -0
  90. data/lib/capybara/spec/session/evaluate_script_spec.rb +23 -1
  91. data/lib/capybara/spec/session/execute_script_spec.rb +22 -3
  92. data/lib/capybara/spec/session/fill_in_spec.rb +50 -32
  93. data/lib/capybara/spec/session/find_button_spec.rb +43 -2
  94. data/lib/capybara/spec/session/find_by_id_spec.rb +3 -2
  95. data/lib/capybara/spec/session/find_field_spec.rb +42 -6
  96. data/lib/capybara/spec/session/find_link_spec.rb +22 -3
  97. data/lib/capybara/spec/session/find_spec.rb +103 -57
  98. data/lib/capybara/spec/session/first_spec.rb +34 -18
  99. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +103 -0
  100. data/lib/capybara/spec/session/{within_frame_spec.rb → frame/within_frame_spec.rb} +44 -2
  101. data/lib/capybara/spec/session/go_back_spec.rb +2 -1
  102. data/lib/capybara/spec/session/go_forward_spec.rb +2 -1
  103. data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
  104. data/lib/capybara/spec/session/has_button_spec.rb +17 -8
  105. data/lib/capybara/spec/session/has_css_spec.rb +85 -73
  106. data/lib/capybara/spec/session/has_current_path_spec.rb +91 -7
  107. data/lib/capybara/spec/session/has_field_spec.rb +93 -58
  108. data/lib/capybara/spec/session/has_link_spec.rb +9 -8
  109. data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
  110. data/lib/capybara/spec/session/has_select_spec.rb +159 -59
  111. data/lib/capybara/spec/session/has_selector_spec.rb +64 -28
  112. data/lib/capybara/spec/session/has_table_spec.rb +1 -0
  113. data/lib/capybara/spec/session/has_text_spec.rb +27 -12
  114. data/lib/capybara/spec/session/has_title_spec.rb +22 -4
  115. data/lib/capybara/spec/session/has_xpath_spec.rb +32 -29
  116. data/lib/capybara/spec/session/headers.rb +2 -1
  117. data/lib/capybara/spec/session/html_spec.rb +4 -3
  118. data/lib/capybara/spec/session/node_spec.rb +198 -38
  119. data/lib/capybara/spec/session/refresh_spec.rb +28 -0
  120. data/lib/capybara/spec/session/reset_session_spec.rb +46 -5
  121. data/lib/capybara/spec/session/response_code.rb +2 -1
  122. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  123. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -5
  124. data/lib/capybara/spec/session/save_page_spec.rb +34 -2
  125. data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
  126. data/lib/capybara/spec/session/screenshot_spec.rb +4 -2
  127. data/lib/capybara/spec/session/select_spec.rb +34 -32
  128. data/lib/capybara/spec/session/selectors_spec.rb +65 -0
  129. data/lib/capybara/spec/session/sibling_spec.rb +52 -0
  130. data/lib/capybara/spec/session/text_spec.rb +4 -4
  131. data/lib/capybara/spec/session/title_spec.rb +2 -1
  132. data/lib/capybara/spec/session/uncheck_spec.rb +42 -2
  133. data/lib/capybara/spec/session/unselect_spec.rb +17 -16
  134. data/lib/capybara/spec/session/visit_spec.rb +77 -2
  135. data/lib/capybara/spec/session/window/become_closed_spec.rb +12 -11
  136. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  137. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  138. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -11
  139. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +7 -4
  140. data/lib/capybara/spec/session/window/window_spec.rb +36 -29
  141. data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
  142. data/lib/capybara/spec/session/window/within_window_spec.rb +31 -7
  143. data/lib/capybara/spec/session/within_spec.rb +14 -6
  144. data/lib/capybara/spec/spec_helper.rb +37 -4
  145. data/lib/capybara/spec/test_app.rb +15 -3
  146. data/lib/capybara/spec/views/buttons.erb +1 -0
  147. data/lib/capybara/spec/views/fieldsets.erb +2 -1
  148. data/lib/capybara/spec/views/form.erb +169 -9
  149. data/lib/capybara/spec/views/frame_child.erb +10 -2
  150. data/lib/capybara/spec/views/frame_one.erb +2 -1
  151. data/lib/capybara/spec/views/frame_parent.erb +3 -2
  152. data/lib/capybara/spec/views/frame_two.erb +2 -1
  153. data/lib/capybara/spec/views/header_links.erb +1 -0
  154. data/lib/capybara/spec/views/host_links.erb +1 -0
  155. data/lib/capybara/spec/views/initial_alert.erb +10 -0
  156. data/lib/capybara/spec/views/path.erb +1 -0
  157. data/lib/capybara/spec/views/popup_one.erb +1 -0
  158. data/lib/capybara/spec/views/popup_two.erb +1 -0
  159. data/lib/capybara/spec/views/postback.erb +2 -1
  160. data/lib/capybara/spec/views/tables.erb +1 -0
  161. data/lib/capybara/spec/views/with_base_tag.erb +1 -0
  162. data/lib/capybara/spec/views/with_count.erb +2 -1
  163. data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
  164. data/lib/capybara/spec/views/with_hover.erb +7 -1
  165. data/lib/capybara/spec/views/with_html.erb +40 -2
  166. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  167. data/lib/capybara/spec/views/with_js.erb +32 -1
  168. data/lib/capybara/spec/views/with_scope.erb +1 -0
  169. data/lib/capybara/spec/views/with_simple_html.erb +2 -1
  170. data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
  171. data/lib/capybara/spec/views/with_title.erb +2 -1
  172. data/lib/capybara/spec/views/with_unload_alert.erb +14 -0
  173. data/lib/capybara/spec/views/with_windows.erb +7 -0
  174. data/lib/capybara/spec/views/within_frames.erb +3 -2
  175. data/lib/capybara/version.rb +2 -1
  176. data/lib/capybara/window.rb +20 -3
  177. data/lib/capybara.rb +189 -93
  178. data/spec/basic_node_spec.rb +7 -6
  179. data/spec/capybara_spec.rb +90 -4
  180. data/spec/dsl_spec.rb +3 -1
  181. data/spec/filter_set_spec.rb +28 -0
  182. data/spec/fixtures/capybara.csv +1 -0
  183. data/spec/fixtures/selenium_driver_rspec_failure.rb +5 -1
  184. data/spec/fixtures/selenium_driver_rspec_success.rb +5 -1
  185. data/spec/minitest_spec.rb +130 -0
  186. data/spec/minitest_spec_spec.rb +135 -0
  187. data/spec/per_session_config_spec.rb +67 -0
  188. data/spec/rack_test_spec.rb +50 -7
  189. data/spec/result_spec.rb +76 -0
  190. data/spec/rspec/features_spec.rb +21 -8
  191. data/spec/rspec/scenarios_spec.rb +21 -0
  192. data/spec/rspec/{matchers_spec.rb → shared_spec_matchers.rb} +160 -54
  193. data/spec/rspec/views_spec.rb +5 -0
  194. data/spec/rspec_matchers_spec.rb +46 -0
  195. data/spec/rspec_spec.rb +79 -1
  196. data/spec/selector_spec.rb +199 -0
  197. data/spec/selenium_spec_chrome.rb +54 -9
  198. data/spec/selenium_spec_firefox.rb +68 -0
  199. data/spec/selenium_spec_marionette.rb +127 -0
  200. data/spec/server_spec.rb +102 -14
  201. data/spec/session_spec.rb +54 -0
  202. data/spec/shared_selenium_session.rb +215 -0
  203. data/spec/spec_helper.rb +7 -0
  204. metadata +140 -15
  205. data/spec/selenium_spec.rb +0 -128
@@ -1,8 +1,8 @@
1
1
  var activeRequests = 0;
2
2
  $(function() {
3
3
  $('#change').text('I changed it');
4
- $('#drag').draggable();
5
- $('#drop').droppable({
4
+ $('#drag, #drag_scroll').draggable();
5
+ $('#drop, #drop_scroll').droppable({
6
6
  drop: function(event, ui) {
7
7
  ui.draggable.remove();
8
8
  $(this).html('Dropped!');
@@ -37,6 +37,9 @@ $(function() {
37
37
  $('#with_change_event').change(function() {
38
38
  $('body').append($('<p class="change_event_triggered"></p>').text(this.value));
39
39
  });
40
+ $('#with_change_event').on('input', function() {
41
+ $('body').append($('<p class="input_event_triggered"></p>').text(this.value));
42
+ });
40
43
  $('#checkbox_with_event').click(function() {
41
44
  $('body').append('<p id="checkbox_event_triggered">Checkbox event triggered</p>');
42
45
  });
@@ -58,17 +61,19 @@ $(function() {
58
61
  $('#change-title').click(function() {
59
62
  setTimeout(function() {
60
63
  $('title').text('changed title')
61
- }, 250)
62
- });
63
- $('#click-test').dblclick(function() {
64
- $(this).after('<a id="has-been-double-clicked" href="#">Has been double clicked</a>');
65
- });
66
- $('#click-test').bind('contextmenu', function(e) {
67
- e.preventDefault();
68
- $(this).after('<a id="has-been-right-clicked" href="#">Has been right clicked</a>');
64
+ }, 400)
65
+ });
66
+ $('#click-test').on({
67
+ dblclick: function() {
68
+ $(this).after('<a id="has-been-double-clicked" href="#">Has been double clicked</a>');
69
+ },
70
+ contextmenu: function(e) {
71
+ e.preventDefault();
72
+ $(this).after('<a id="has-been-right-clicked" href="#">Has been right clicked</a>');
73
+ }
69
74
  });
70
75
  $('#open-alert').click(function() {
71
- alert('Alert opened');
76
+ alert('Alert opened [*Yay?*]');
72
77
  $(this).attr('opened', 'true');
73
78
  });
74
79
  $('#open-delayed-alert').click(function() {
@@ -85,6 +90,10 @@ $(function() {
85
90
  $(link).attr('opened', 'true');
86
91
  }, 3000);
87
92
  });
93
+ $('#alert-page-change').click(function() {
94
+ alert('Page is changing');
95
+ return true;
96
+ });
88
97
  $('#open-confirm').click(function() {
89
98
  if(confirm('Confirm opened')) {
90
99
  $(this).attr('confirmed', 'true');
@@ -100,6 +109,21 @@ $(function() {
100
109
  $(this).attr('response', response);
101
110
  }
102
111
  });
112
+ $('#open-prompt-with-default').click(function() {
113
+ var response = prompt('Prompt opened', 'Default value!');
114
+ if(response === null) {
115
+ $(this).attr('response', 'dismissed');
116
+ } else {
117
+ $(this).attr('response', response);
118
+ }
119
+ });
120
+ $('#open-twice').click(function() {
121
+ if (confirm('Are you sure?')) {
122
+ if (!confirm('Are you really sure?')) {
123
+ $(this).attr('confirmed', 'false');
124
+ }
125
+ }
126
+ })
103
127
  $('#delayed-page-change').click(function() {
104
128
  setTimeout(function() {
105
129
  window.location.pathname = '/with_html'
@@ -108,4 +132,14 @@ $(function() {
108
132
  $('#with-key-events').keydown(function(e){
109
133
  $('#key-events-output').append('keydown:'+e.which+' ')
110
134
  });
135
+ $('#disable-on-click').click(function(e){
136
+ var input = this
137
+ setTimeout(function() {
138
+ input.disabled = true;
139
+ }, 500)
140
+ })
141
+ $('#set-storage').click(function(e){
142
+ sessionStorage.setItem('session', 'session_value');
143
+ localStorage.setItem('local', 'local value');
144
+ })
111
145
  });
@@ -1,4 +1,5 @@
1
- Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
1
+ # frozen_string_literal: true
2
+ Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
4
5
  end
@@ -9,14 +10,28 @@ Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
9
10
  end
10
11
  expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
11
12
  end
12
-
13
+
13
14
  it "should accept the alert if the text matches" do
14
15
  @session.accept_alert 'Alert opened' do
15
16
  @session.click_link('Open alert')
16
17
  end
17
18
  expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
18
19
  end
19
-
20
+
21
+ it 'should accept the alert if text contains "special" Regex characters' do
22
+ @session.accept_alert 'opened [*Yay?*]' do
23
+ @session.click_link('Open alert')
24
+ end
25
+ expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
26
+ end
27
+
28
+ it "should accept the alert if the text matches a regexp" do
29
+ @session.accept_alert(/op.{2}ed/) do
30
+ @session.click_link('Open alert')
31
+ end
32
+ expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
33
+ end
34
+
20
35
  it "should not accept the alert if the text doesnt match" do
21
36
  expect do
22
37
  @session.accept_alert 'Incorrect Text' do
@@ -29,7 +44,15 @@ Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
29
44
  message = @session.accept_alert do
30
45
  @session.click_link('Open alert')
31
46
  end
32
- expect(message).to eq('Alert opened')
47
+ expect(message).to eq('Alert opened [*Yay?*]')
48
+ end
49
+
50
+ it "should handle the alert if the page changes" do
51
+ @session.accept_alert do
52
+ @session.click_link('Alert page change')
53
+ sleep 1 # ensure page change occurs before the accept_alert block exits
54
+ end
55
+ expect(@session).to have_current_path('/with_html')
33
56
  end
34
57
 
35
58
  context "with an asynchronous alert" do
@@ -46,12 +69,12 @@ Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
46
69
  end
47
70
  expect(message).to eq('Delayed alert opened')
48
71
  end
49
-
72
+
50
73
  it "should allow to adjust the delay" do
51
- @session.accept_alert wait: 4 do
74
+ @session.accept_alert wait: 10 do
52
75
  @session.click_link('Open slow alert')
53
76
  end
54
77
  expect(@session).to have_xpath("//a[@id='open-slow-alert' and @opened='true']")
55
78
  end
56
79
  end
57
- end
80
+ end
@@ -1,4 +1,5 @@
1
- Capybara::SpecHelper.spec '#accept_confirm', :requires => [:modals] do
1
+ # frozen_string_literal: true
2
+ Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
4
5
  end
@@ -16,4 +17,15 @@ Capybara::SpecHelper.spec '#accept_confirm', :requires => [:modals] do
16
17
  end
17
18
  expect(message).to eq('Confirm opened')
18
19
  end
19
- end
20
+
21
+ it "should work with nested modals" do
22
+ expect {
23
+ @session.dismiss_confirm 'Are you really sure?' do
24
+ @session.accept_confirm 'Are you sure?' do
25
+ @session.click_link('Open check twice')
26
+ end
27
+ end
28
+ }.not_to raise_error
29
+ expect(@session).to have_xpath("//a[@id='open-twice' and @confirmed='false']")
30
+ end
31
+ end
@@ -1,4 +1,5 @@
1
- Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
1
+ # frozen_string_literal: true
2
+ Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
2
3
  before do
3
4
  @session.visit('/with_js')
4
5
  end
@@ -10,27 +11,56 @@ Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
10
11
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='']")
11
12
  end
12
13
 
14
+ it "should accept the prompt with no message when there is a default" do
15
+ @session.accept_prompt do
16
+ @session.click_link('Open defaulted prompt')
17
+ end
18
+ expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='Default value!']")
19
+ end
20
+
13
21
  it "should return the message presented" do
14
22
  message = @session.accept_prompt do
15
23
  @session.click_link('Open prompt')
16
24
  end
17
25
  expect(message).to eq('Prompt opened')
18
26
  end
19
-
27
+
20
28
  it "should accept the prompt with a response" do
21
29
  @session.accept_prompt with: 'the response' do
22
30
  @session.click_link('Open prompt')
23
31
  end
24
32
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='the response']")
25
33
  end
26
-
34
+
35
+ it "should accept the prompt with a response when there is a default" do
36
+ @session.accept_prompt with: 'the response' do
37
+ @session.click_link('Open defaulted prompt')
38
+ end
39
+ expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='the response']")
40
+ end
41
+
42
+ it "should accept the prompt with a blank response when there is a default" do
43
+ pending "Geckodriver doesn't set a blank response currently" if marionette?(@session)
44
+ @session.accept_prompt with: '' do
45
+ @session.click_link('Open defaulted prompt')
46
+ end
47
+ expect(@session).to have_xpath("//a[@id='open-prompt-with-default' and @response='']")
48
+ end
49
+
50
+ it "should allow special characters in the reponse" do
51
+ @session.accept_prompt with: '\'the\' \b "response"' do
52
+ @session.click_link('Open prompt')
53
+ end
54
+ expect(@session).to have_xpath(%{//a[@id='open-prompt' and @response=concat("'the' ", '\\b "response"')]})
55
+ end
56
+
27
57
  it "should accept the prompt if the message matches" do
28
58
  @session.accept_prompt 'Prompt opened', with: 'matched' do
29
59
  @session.click_link('Open prompt')
30
60
  end
31
61
  expect(@session).to have_xpath("//a[@id='open-prompt' and @response='matched']")
32
62
  end
33
-
63
+
34
64
  it "should not accept the prompt if the message doesn't match" do
35
65
  expect do
36
66
  @session.accept_prompt 'Incorrect Text', with: 'not matched' do
@@ -38,7 +68,6 @@ Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
38
68
  end
39
69
  end.to raise_error(Capybara::ModalNotFound)
40
70
  end
41
-
42
71
 
43
72
  it "should return the message presented" do
44
73
  message = @session.accept_prompt with: 'the response' do
@@ -46,4 +75,4 @@ Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
46
75
  end
47
76
  expect(message).to eq('Prompt opened')
48
77
  end
49
- end
78
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#all" do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -6,7 +7,7 @@ Capybara::SpecHelper.spec "#all" do
6
7
  it "should find all elements using the given locator" do
7
8
  expect(@session.all('//p').size).to eq(3)
8
9
  expect(@session.all('//h1').first.text).to eq('This is a test')
9
- expect(@session.all("//input[@id='test_field']").first[:value]).to eq('monkey')
10
+ expect(@session.all("//input[@id='test_field']").first.value).to eq('monkey')
10
11
  end
11
12
 
12
13
  it "should return an empty array when nothing was found" do
@@ -15,19 +16,20 @@ Capybara::SpecHelper.spec "#all" do
15
16
 
16
17
  it "should accept an XPath instance" do
17
18
  @session.visit('/form')
18
- @xpath = XPath::HTML.fillable_field('Name')
19
+ @xpath = Capybara::Selector.all[:fillable_field].call('Name')
20
+ expect(@xpath).to be_a(::XPath::Union)
19
21
  @result = @session.all(@xpath).map { |r| r.value }
20
22
  expect(@result).to include('Smith', 'John', 'John Smith')
21
23
  end
22
24
 
23
25
  it "should raise an error when given invalid options" do
24
- expect { @session.all('//p', :schmoo => "foo") }.to raise_error(ArgumentError)
26
+ expect { @session.all('//p', schmoo: "foo") }.to raise_error(ArgumentError)
25
27
  end
26
28
 
27
29
  context "with css selectors" do
28
30
  it "should find all elements using the given selector" do
29
31
  expect(@session.all(:css, 'h1').first.text).to eq('This is a test')
30
- expect(@session.all(:css, "input[id='test_field']").first[:value]).to eq('monkey')
32
+ expect(@session.all(:css, "input[id='test_field']").first.value).to eq('monkey')
31
33
  end
32
34
 
33
35
  it "should find all elements when given a list of selectors" do
@@ -38,7 +40,7 @@ Capybara::SpecHelper.spec "#all" do
38
40
  context "with xpath selectors" do
39
41
  it "should find the first element using the given locator" do
40
42
  expect(@session.all(:xpath, '//h1').first.text).to eq('This is a test')
41
- expect(@session.all(:xpath, "//input[@id='test_field']").first[:value]).to eq('monkey')
43
+ expect(@session.all(:xpath, "//input[@id='test_field']").first.value).to eq('monkey')
42
44
  end
43
45
  end
44
46
 
@@ -46,17 +48,17 @@ Capybara::SpecHelper.spec "#all" do
46
48
  before { Capybara.default_selector = :css }
47
49
  it "should find the first element using the given locator" do
48
50
  expect(@session.all('h1').first.text).to eq('This is a test')
49
- expect(@session.all("input[id='test_field']").first[:value]).to eq('monkey')
51
+ expect(@session.all("input[id='test_field']").first.value).to eq('monkey')
50
52
  end
51
53
  end
52
54
 
53
55
  context "with visible filter" do
54
56
  it "should only find visible nodes when true" do
55
- expect(@session.all(:css, "a.simple", :visible => true).size).to eq(1)
57
+ expect(@session.all(:css, "a.simple", visible: true).size).to eq(1)
56
58
  end
57
59
 
58
60
  it "should find nodes regardless of whether they are invisible when false" do
59
- expect(@session.all(:css, "a.simple", :visible => false).size).to eq(2)
61
+ expect(@session.all(:css, "a.simple", visible: false).size).to eq(2)
60
62
  end
61
63
 
62
64
  it "should default to Capybara.ignore_hidden_elements" do
@@ -65,73 +67,84 @@ Capybara::SpecHelper.spec "#all" do
65
67
  Capybara.ignore_hidden_elements = false
66
68
  expect(@session.all(:css, "a.simple").size).to eq(2)
67
69
  end
70
+
71
+ context "with per session config", requires: [:psc] do
72
+ it "should use the sessions ignore_hidden_elements", psc: true do
73
+ Capybara.ignore_hidden_elements = true
74
+ @session.config.ignore_hidden_elements = false
75
+ expect(Capybara.ignore_hidden_elements).to eq(true)
76
+ expect(@session.all(:css, "a.simple").size).to eq(2)
77
+ @session.config.ignore_hidden_elements = true
78
+ expect(@session.all(:css, "a.simple").size).to eq(1)
79
+ end
80
+ end
68
81
  end
69
82
 
70
83
  context 'with element count filters' do
71
84
  context ':count' do
72
85
  it 'should succeed when the number of elements founds matches the expectation' do
73
- expect { @session.all(:css, 'h1, p', :count => 4) }.to_not raise_error
86
+ expect { @session.all(:css, 'h1, p', count: 4) }.to_not raise_error
74
87
  end
75
88
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
76
- expect { @session.all(:css, 'h1, p', :count => 5) }.to raise_error(Capybara::ExpectationNotMet)
89
+ expect { @session.all(:css, 'h1, p', count: 5) }.to raise_error(Capybara::ExpectationNotMet)
77
90
  end
78
91
  end
79
92
  context ':minimum' do
80
93
  it 'should succeed when the number of elements founds matches the expectation' do
81
- expect { @session.all(:css, 'h1, p', :minimum => 0) }.to_not raise_error
94
+ expect { @session.all(:css, 'h1, p', minimum: 0) }.to_not raise_error
82
95
  end
83
96
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
84
- expect { @session.all(:css, 'h1, p', :minimum => 5) }.to raise_error(Capybara::ExpectationNotMet)
97
+ expect { @session.all(:css, 'h1, p', minimum: 5) }.to raise_error(Capybara::ExpectationNotMet)
85
98
  end
86
99
  end
87
100
  context ':maximum' do
88
101
  it 'should succeed when the number of elements founds matches the expectation' do
89
- expect { @session.all(:css, 'h1, p', :maximum => 4) }.to_not raise_error
102
+ expect { @session.all(:css, 'h1, p', maximum: 4) }.to_not raise_error
90
103
  end
91
104
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
92
- expect { @session.all(:css, 'h1, p', :maximum => 0) }.to raise_error(Capybara::ExpectationNotMet)
105
+ expect { @session.all(:css, 'h1, p', maximum: 0) }.to raise_error(Capybara::ExpectationNotMet)
93
106
  end
94
107
  end
95
108
  context ':between' do
96
109
  it 'should succeed when the number of elements founds matches the expectation' do
97
- expect { @session.all(:css, 'h1, p', :between => 2..7) }.to_not raise_error
110
+ expect { @session.all(:css, 'h1, p', between: 2..7) }.to_not raise_error
98
111
  end
99
112
  it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
100
- expect { @session.all(:css, 'h1, p', :between => 0..3) }.to raise_error(Capybara::ExpectationNotMet)
113
+ expect { @session.all(:css, 'h1, p', between: 0..3) }.to raise_error(Capybara::ExpectationNotMet)
101
114
  end
102
115
  end
103
116
 
104
117
  context 'with multiple count filters' do
105
118
  it 'ignores other filters when :count is specified' do
106
- o = {:count => 4,
107
- :minimum => 5,
108
- :maximum => 0,
109
- :between => 0..3}
119
+ o = {count: 4,
120
+ minimum: 5,
121
+ maximum: 0,
122
+ between: 0..3}
110
123
  expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
111
124
  end
112
125
  context 'with no :count expectation' do
113
126
  it 'fails if :minimum is not met' do
114
- o = {:minimum => 5,
115
- :maximum => 4,
116
- :between => 2..7}
127
+ o = {minimum: 5,
128
+ maximum: 4,
129
+ between: 2..7}
117
130
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
118
131
  end
119
132
  it 'fails if :maximum is not met' do
120
- o = {:minimum => 0,
121
- :maximum => 0,
122
- :between => 2..7}
133
+ o = {minimum: 0,
134
+ maximum: 0,
135
+ between: 2..7}
123
136
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
124
137
  end
125
138
  it 'fails if :between is not met' do
126
- o = {:minimum => 0,
127
- :maximum => 4,
128
- :between => 0..3}
139
+ o = {minimum: 0,
140
+ maximum: 4,
141
+ between: 0..3}
129
142
  expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
130
143
  end
131
144
  it 'succeeds if all combineable expectations are met' do
132
- o = {:minimum => 0,
133
- :maximum => 4,
134
- :between => 2..7}
145
+ o = {minimum: 0,
146
+ maximum: 4,
147
+ between: 2..7}
135
148
  expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
136
149
  end
137
150
  end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ Capybara::SpecHelper.spec '#ancestor' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ after do
8
+ Capybara::Selector.remove(:monkey)
9
+ end
10
+
11
+ it "should find the ancestor element using the given locator" do
12
+ el = @session.find(:css, '#first_image')
13
+ expect(el.ancestor('//p')).to have_text('Lorem ipsum dolor')
14
+ expect(el.ancestor("//a")[:'aria-label']).to eq('Go to simple')
15
+ end
16
+
17
+ it "should find the ancestor element using the given locator and options" do
18
+ el = @session.find(:css, '#child')
19
+ expect(el.ancestor('//div', text: 'Ancestor Ancestor Ancestor')[:id]).to eq('ancestor3')
20
+ end
21
+
22
+ it "should raise an error if there are multiple matches" do
23
+ el = @session.find(:css, '#child')
24
+ expect { el.ancestor('//div') }.to raise_error(Capybara::Ambiguous)
25
+ expect { el.ancestor('//div', text: 'Ancestor') }.to raise_error(Capybara::Ambiguous)
26
+ end
27
+
28
+ context "with css selectors" do
29
+ it "should find the first element using the given locator" do
30
+ el = @session.find(:css, '#first_image')
31
+ expect(el.ancestor(:css, 'p')).to have_text('Lorem ipsum dolor')
32
+ expect(el.ancestor(:css, 'a')[:'aria-label']).to eq('Go to simple')
33
+ end
34
+
35
+ it "should support pseudo selectors" do
36
+ el = @session.find(:css, '#button_img')
37
+ expect(el.ancestor(:css, 'button:disabled')[:id]).to eq('ancestor_button')
38
+ end
39
+ end
40
+
41
+ context "with xpath selectors" do
42
+ it "should find the first element using the given locator" do
43
+ el = @session.find(:css, '#first_image')
44
+ expect(el.ancestor(:xpath, '//p')).to have_text('Lorem ipsum dolor')
45
+ expect(el.ancestor(:xpath, "//a")[:'aria-label']).to eq('Go to simple')
46
+ end
47
+ end
48
+
49
+ context "with custom selector" do
50
+ it "should use the custom selector" do
51
+ Capybara.add_selector(:level) do
52
+ xpath { |num| ".//*[@id='ancestor#{num}']" }
53
+ end
54
+ el = @session.find(:css, '#child')
55
+ expect(el.ancestor(:level, 1).text).to eq('Ancestor Child')
56
+ expect(el.ancestor(:level, 3).text).to eq('Ancestor Ancestor Ancestor Child')
57
+ end
58
+ end
59
+
60
+
61
+ it "should raise ElementNotFound with a useful default message if nothing was found" do
62
+ el = @session.find(:css, '#child')
63
+ expect do
64
+ el.ancestor(:xpath, '//div[@id="nosuchthing"]')
65
+ end.to raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\" that is an ancestor of visible css \"#child\"")
66
+ end
67
+
68
+
69
+
70
+ context "within a scope" do
71
+ it "should limit the ancestors to inside the scope" do
72
+ @session.within(:css, '#ancestor2') do
73
+ el = @session.find(:css, '#child')
74
+ expect(el.ancestor(:css,'div', text: 'Ancestor')[:id]).to eq('ancestor1')
75
+ end
76
+ end
77
+ end
78
+
79
+ it "should raise if selector type is unknown" do
80
+ el = @session.find(:css, '#child')
81
+ expect do
82
+ el.ancestor(:unknown, '//h1')
83
+ end.to raise_error(ArgumentError)
84
+ end
85
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+ Capybara::SpecHelper.spec '#assert_all_of_selectors' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should be true if the given selectors are on the page" do
8
+ @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two" )
9
+ end
10
+
11
+ it "should be false if any of the given selectors are not on the page" do
12
+ expect { @session.assert_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one")}.to raise_error(Capybara::ElementNotFound)
13
+ end
14
+
15
+ it "should use default selector" do
16
+ Capybara.default_selector = :css
17
+ expect { @session.assert_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one")}.to raise_error(Capybara::ElementNotFound)
18
+ @session.assert_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one" )
19
+ end
20
+
21
+ context "should respect scopes" do
22
+ it "when used with `within`" do
23
+ @session.within "//p[@id='first']" do
24
+ @session.assert_all_of_selectors(".//a[@id='foo']")
25
+ expect { @session.assert_all_of_selectors(".//a[@id='red']") }.to raise_error(Capybara::ElementNotFound)
26
+ end
27
+ end
28
+
29
+ it "when called on elements" do
30
+ el = @session.find "//p[@id='first']"
31
+ el.assert_all_of_selectors(".//a[@id='foo']")
32
+ expect { el.assert_all_of_selectors(".//a[@id='red']") }.to raise_error(Capybara::ElementNotFound)
33
+ end
34
+ end
35
+
36
+ context "with options" do
37
+ it "should apply options to all locators" do
38
+ @session.assert_all_of_selectors(:field, 'normal', 'additional_newline', type: :textarea)
39
+ expect { @session.assert_all_of_selectors(:field, 'normal', 'test_field', 'additional_newline', type: :textarea) }.to raise_error(Capybara::ElementNotFound)
40
+ end
41
+ end
42
+
43
+ context "with wait", requires: [:js] do
44
+ it "should not raise error if all the elements appear before given wait duration" do
45
+ Capybara.using_wait_time(0.1) do
46
+ @session.visit('/with_js')
47
+ @session.click_link('Click me')
48
+ @session.assert_all_of_selectors(:css, "a#clickable", "a#has-been-clicked", '#drag', wait: 0.9)
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ Capybara::SpecHelper.spec '#assert_none_of_selectors' do
55
+ before do
56
+ @session.visit('/with_html')
57
+ end
58
+
59
+ it "should be false if any of the given locators are on the page" do
60
+ expect { @session.assert_none_of_selectors(:xpath, "//p", "//a") }.to raise_error(Capybara::ElementNotFound)
61
+ expect { @session.assert_none_of_selectors(:xpath, "//abbr", "//a") }.to raise_error(Capybara::ElementNotFound)
62
+ expect { @session.assert_none_of_selectors(:css, "p a#foo") }.to raise_error(Capybara::ElementNotFound)
63
+ end
64
+
65
+ it "should be true if none of the given locators are on the page" do
66
+ @session.assert_none_of_selectors(:xpath, "//abbr", "//td" )
67
+ @session.assert_none_of_selectors(:css, "p a#doesnotexist", "abbr")
68
+ end
69
+
70
+ it "should use default selector" do
71
+ Capybara.default_selector = :css
72
+ @session.assert_none_of_selectors("p a#doesnotexist", "abbr")
73
+ expect { @session.assert_none_of_selectors("abbr", "p a#foo") }.to raise_error(Capybara::ElementNotFound)
74
+ end
75
+
76
+ context "should respect scopes" do
77
+ it "when used with `within`" do
78
+ @session.within "//p[@id='first']" do
79
+ expect { @session.assert_none_of_selectors(".//a[@id='foo']") }.to raise_error(Capybara::ElementNotFound)
80
+ @session.assert_none_of_selectors(".//a[@id='red']")
81
+ end
82
+ end
83
+
84
+ it "when called on an element" do
85
+ el = @session.find "//p[@id='first']"
86
+ expect { el.assert_none_of_selectors(".//a[@id='foo']") }.to raise_error(Capybara::ElementNotFound)
87
+ el.assert_none_of_selectors(".//a[@id='red']")
88
+ end
89
+ end
90
+
91
+ context "with options" do
92
+ it "should apply the options to all locators" do
93
+ expect { @session.assert_none_of_selectors("//p//a", text: "Redirect") }.to raise_error(Capybara::ElementNotFound)
94
+ @session.assert_none_of_selectors("//p", text: "Doesnotexist")
95
+ end
96
+
97
+ it "should discard all matches where the given regexp is matched" do
98
+ expect { @session.assert_none_of_selectors("//p//a", text: /re[dab]i/i, count: 1) }.to raise_error(Capybara::ElementNotFound)
99
+ @session.assert_none_of_selectors("//p//a", text: /Red$/)
100
+ end
101
+ end
102
+
103
+ context "with wait", requires: [:js] do
104
+ it "should not find elements if they appear after given wait duration" do
105
+ @session.visit('/with_js')
106
+ @session.click_link('Click me')
107
+ @session.assert_none_of_selectors(:css, "#new_field", "a#has-been-clicked", wait: 0.1)
108
+ end
109
+ end
110
+ end