capybara 2.6.1 → 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 +47 -16
  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 +5 -4
  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
@@ -1,7 +1,8 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <h1>This page is used for testing number options of has_text?</h1>
2
3
 
3
4
  <p>count1</p>
4
5
  <div>
5
6
  <p>2 count</p>
6
7
  <p>Count</p>
7
- </div>
8
+ </div>
@@ -1,3 +1,4 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
2
3
  <head>
3
4
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
@@ -14,4 +15,4 @@
14
15
  <div class="hidden_until_hover">Here I am</div>
15
16
  </div>
16
17
  </body>
17
- </html>
18
+ </html>
@@ -1,3 +1,4 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <div id="referrer"><%= referrer %></div>
2
3
  <h1>This is a test</h1>
3
4
 
@@ -10,6 +11,7 @@
10
11
  <h2 class="head">Header Class Test Five</h2>
11
12
 
12
13
  <span class="number">42</span>
14
+ <span>Other span</span>
13
15
 
14
16
  <p class="para" id="first">
15
17
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
@@ -109,6 +111,7 @@ banana</textarea>
109
111
  </div>
110
112
 
111
113
  <input type="text" disabled="disabled" name="disabled_text" value="This is disabled"/>
114
+ <input type="hidden" id="hidden_input" name="hidden_input" value="This is a hidden input"/>
112
115
 
113
116
  <div>
114
117
  <a id="link_placeholder">No href</a>
@@ -1 +1,2 @@
1
+ <%# frozen_string_literal: true %>
1
2
  Encoding with &mdash; html entities &raquo;
@@ -1,3 +1,4 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
2
3
  <head>
3
4
  <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
@@ -93,6 +94,10 @@
93
94
  <a href="#" id="open-prompt">Open prompt</a>
94
95
  </p>
95
96
 
97
+ <p>
98
+ <input id="disable-on-click"/>
99
+ </p>
100
+
96
101
  <p>
97
102
  <a href="#" id="delayed-page-change">Change page</a>
98
103
  <a href="/with_html?options[]=things">Non-escaped query options</a>
@@ -1,3 +1,4 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <h1>This page is used for testing various scopes</h1>
2
3
 
3
4
  <p id="for_foo">
@@ -1 +1,2 @@
1
- Bar
1
+ <%# frozen_string_literal: true %>
2
+ Bar
@@ -0,0 +1,17 @@
1
+ <html>
2
+ <head>
3
+ <script>
4
+ function delay_unload() {
5
+ var start = new Date();
6
+ var i = 0;
7
+ while ((new Date()) - start < 1000){ i = i + 1; };
8
+ return null;
9
+ }
10
+ window.onbeforeunload = delay_unload;
11
+ window.onunload = delay_unload;
12
+ </script>
13
+ </head>
14
+ <body>
15
+ <div>This delays unload by 2 seconds</div>
16
+ </body>
17
+ </html>
@@ -1,4 +1,5 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <title>Test Title</title>
2
3
  <body>
3
4
  <svg><title>abcdefg</title></svg>
4
- </body>
5
+ </body>
@@ -0,0 +1,12 @@
1
+ <html>
2
+ <head>
3
+ <script>
4
+ window.onbeforeunload = function(e) {
5
+ return 'Unload?';
6
+ };
7
+ </script>
8
+ </head>
9
+ <body>
10
+ <div>This triggers an alert on unload</div>
11
+ </body>
12
+ </html>
@@ -1,3 +1,4 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <html>
2
3
  <head>
3
4
  <title>With Windows</title>
@@ -1,3 +1,4 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <html>
2
3
  <head>
3
4
  <title>With Frames</title>
@@ -8,4 +9,4 @@
8
9
  <iframe src="/frame_two" id="frameTwo"></iframe>
9
10
  <iframe src="/frame_parent" id="parentFrame"></iframe>
10
11
  </body>
11
- </html>
12
+ </html>
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
- VERSION = '2.6.1'
3
+ VERSION = '2.7.0'
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Capybara
2
3
  ##
3
4
  # The Window class represents a browser window.
data/lib/capybara.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'timeout'
2
3
  require 'nokogiri'
3
4
  require 'xpath'
@@ -22,8 +23,10 @@ module Capybara
22
23
  attr_accessor :asset_host, :app_host, :run_server, :default_host, :always_include_port
23
24
  attr_accessor :server_port, :exact, :match, :exact_options, :visible_text_only
24
25
  attr_accessor :default_selector, :default_max_wait_time, :ignore_hidden_elements
25
- attr_accessor :save_and_open_page_path, :wait_on_first_by_default, :automatic_reload, :raise_server_errors, :server_errors
26
+ attr_accessor :save_path, :wait_on_first_by_default, :automatic_reload
27
+ attr_accessor :reuse_server, :raise_server_errors, :server_errors
26
28
  attr_writer :default_driver, :current_driver, :javascript_driver, :session_name, :server_host
29
+ attr_reader :save_and_open_page_path
27
30
  attr_accessor :app
28
31
 
29
32
  ##
@@ -47,8 +50,9 @@ module Capybara
47
50
  # [default_max_wait_time = Numeric] The maximum number of seconds to wait for asynchronous processes to finish (Default: 2)
48
51
  # [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: true)
49
52
  # [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true)
50
- # [save_and_open_page_path = String] Where to put pages saved through save_and_open_page (Default: Dir.pwd)
53
+ # [save_path = String] Where to put pages saved through save_(page|screenshot), save_and_open_(page|screenshot) (Default: Dir.pwd)
51
54
  # [wait_on_first_by_default = Boolean] Whether Node#first defaults to Capybara waiting behavior for at least 1 element to match (Default: false)
55
+ # [reuse_server = Boolean] Reuse the server thread between multiple sessions using the same app object (Default: true)
52
56
  # === DSL Options
53
57
  #
54
58
  # when using capybara/dsl, the following options are also available:
@@ -77,6 +81,26 @@ module Capybara
77
81
  drivers[name] = block
78
82
  end
79
83
 
84
+ ##
85
+ #
86
+ # Register a new server for Capybara.
87
+ #
88
+ # Capybara.register_server :webrick do |app, port, host|
89
+ # require 'rack/handler/webrick'
90
+ # Rack::Handler::WEBrick.run(app, ...)
91
+ # end
92
+ #
93
+ # @param [Symbol] name The name of the new driver
94
+ # @yield [app, port, host] This block takes a rack app and a port and returns a rack server listening on that port
95
+ # @yieldparam [<Rack>] app The rack application that this server will contain.
96
+ # @yieldparam port The port number the server should listen on
97
+ # @yieldparam host The host/ip to bind to
98
+ # @yieldreturn [Capybara::Driver::Base] A Capybara driver instance
99
+ #
100
+ def register_server(name, &block)
101
+ servers[name.to_sym] = block
102
+ end
103
+
80
104
  ##
81
105
  #
82
106
  # Add a new selector to Capybara. Selectors can be used by various methods in Capybara
@@ -111,11 +135,11 @@ module Capybara
111
135
 
112
136
  ##
113
137
  #
114
- # Modify a selector previously craeated by {Capybara.add_selector}.
138
+ # Modify a selector previously created by {Capybara.add_selector}.
115
139
  # For example modifying the :button selector to also find divs styled
116
140
  # to look like buttons might look like this
117
141
  #
118
- # Capybara.modfiy_selector(:button) do
142
+ # Capybara.modify_selector(:button) do
119
143
  # xpath { |locator| XPath::HTML.button(locator).or(XPath::css('div.btn')[XPath::string.n.is(locator)]) }
120
144
  # end
121
145
  #
@@ -130,27 +154,49 @@ module Capybara
130
154
  @drivers ||= {}
131
155
  end
132
156
 
157
+ def servers
158
+ @servers ||= {}
159
+ end
160
+
133
161
  ##
134
162
  #
135
163
  # Register a proc that Capybara will call to run the Rack application.
136
164
  #
137
- # Capybara.server do |app, port|
165
+ # Capybara.server do |app, port, host|
138
166
  # require 'rack/handler/mongrel'
139
167
  # Rack::Handler::Mongrel.run(app, :Port => port)
140
168
  # end
141
169
  #
142
170
  # By default, Capybara will try to run webrick.
143
171
  #
144
- # @yield [app, port] This block receives a rack app and port and should run a Rack handler
172
+ # @yield [app, port, host] This block receives a rack app, port, and host/ip and should run a Rack handler
145
173
  #
146
174
  def server(&block)
147
175
  if block_given?
176
+ warn "DEPRECATED: Passing a block to Capybara::server is deprecated, please use Capybara::register_server instead"
148
177
  @server = block
149
178
  else
150
179
  @server
151
180
  end
152
181
  end
153
182
 
183
+ ##
184
+ #
185
+ # Set the server to use.
186
+ #
187
+ # Capybara.server = :webrick
188
+ #
189
+ # @param [Symbol] name Name of the server type to use
190
+ # @see register_server
191
+ #
192
+ def server=(name)
193
+ @server = if name.respond_to? :call
194
+ name
195
+ else
196
+ servers[name.to_sym]
197
+ end
198
+ end
199
+
154
200
  ##
155
201
  #
156
202
  # Wraps the given string, which should contain an HTML document or fragment
@@ -197,8 +243,7 @@ module Capybara
197
243
  # @param [Fixnum] port The port to run the application on
198
244
  #
199
245
  def run_default_server(app, port)
200
- require 'rack/handler/webrick'
201
- Rack::Handler::WEBrick.run(app, :Host => server_host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
246
+ servers[:webrick].call(app, port, server_host)
202
247
  end
203
248
 
204
249
  ##
@@ -335,11 +380,22 @@ module Capybara
335
380
  self.default_max_wait_time = t
336
381
  end
337
382
 
383
+ def save_and_open_page_path=(path)
384
+ warn "DEPRECATED: #save_and_open_page_path is deprecated, please use #save_path instead. \n"\
385
+ "Note: Behavior is slightly different with relative paths - see documentation" unless path.nil?
386
+ @save_and_open_page_path = path
387
+ end
388
+
338
389
  def included(base)
339
390
  base.send(:include, Capybara::DSL)
340
391
  warn "`include Capybara` is deprecated. Please use `include Capybara::DSL` instead."
341
392
  end
342
393
 
394
+ def reuse_server=(bool)
395
+ warn "Capybara.reuse_server == false is a BETA feature and may change in a future version" unless bool
396
+ @reuse_server = bool
397
+ end
398
+
343
399
  def deprecate(method, alternate_method, once=false)
344
400
  @deprecation_notified ||= {}
345
401
  warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once and @deprecation_notified[method]
@@ -370,10 +426,12 @@ module Capybara
370
426
  require 'capybara/version'
371
427
 
372
428
  require 'capybara/queries/base_query'
373
- require 'capybara/query'
429
+ require 'capybara/queries/selector_query'
374
430
  require 'capybara/queries/text_query'
375
431
  require 'capybara/queries/title_query'
376
432
  require 'capybara/queries/current_path_query'
433
+ require 'capybara/queries/match_query'
434
+ require 'capybara/query'
377
435
 
378
436
  require 'capybara/node/finders'
379
437
  require 'capybara/node/matchers'
@@ -397,10 +455,26 @@ module Capybara
397
455
  require 'capybara/selenium/driver'
398
456
  end
399
457
 
458
+ Capybara.register_server :default do |app, port, host|
459
+ Capybara.run_default_server(app, port)
460
+ end
461
+
462
+ Capybara.register_server :webrick do |app, port, host|
463
+ require 'rack/handler/webrick'
464
+ Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
465
+ end
466
+
467
+ Capybara.register_server :puma do |app, port, host|
468
+ require 'puma'
469
+ Puma::Server.new(app).tap do |s|
470
+ s.add_tcp_listener host, port
471
+ end.run.join
472
+ end
473
+
400
474
  Capybara.configure do |config|
401
475
  config.always_include_port = false
402
476
  config.run_server = true
403
- config.server {|app, port| Capybara.run_default_server(app, port)}
477
+ config.server = :default
404
478
  config.default_selector = :css
405
479
  config.default_max_wait_time = 2
406
480
  config.ignore_hidden_elements = true
@@ -412,6 +486,7 @@ Capybara.configure do |config|
412
486
  config.server_errors = [StandardError]
413
487
  config.visible_text_only = false
414
488
  config.wait_on_first_by_default = false
489
+ config.reuse_server = true
415
490
  end
416
491
 
417
492
  Capybara.register_driver :rack_test do |app|
@@ -421,3 +496,4 @@ end
421
496
  Capybara.register_driver :selenium do |app|
422
497
  Capybara::Selenium::Driver.new(app)
423
498
  end
499
+
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Capybara do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Capybara do
@@ -33,9 +34,35 @@ RSpec.describe Capybara do
33
34
  end
34
35
  end
35
36
 
37
+ describe '.register_server' do
38
+ before do
39
+ Capybara.reuse_server = false
40
+ @old_server = Capybara.server
41
+ end
42
+
43
+ after do
44
+ Capybara.server(&@old_server)
45
+ Capybara.reuse_server = true
46
+ end
47
+
48
+ it "should add a new server" do
49
+ Capybara.register_server :blob do |app, port, host|
50
+ Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
51
+ end
52
+ Capybara.server = :blob
53
+ session = Capybara::Session.new(:selenium, TestApp.dup)
54
+ session.visit('/')
55
+ expect(session.body).to include("Hello world!")
56
+ end
57
+ end
58
+
36
59
  describe ".server" do
60
+ before do
61
+ @old_server = Capybara.server
62
+ end
63
+
37
64
  after do
38
- Capybara.server {|app, port| Capybara.run_default_server(app, port)}
65
+ Capybara.server(&@old_server)
39
66
  end
40
67
 
41
68
  it "should default to a proc that calls run_default_server" do
data/spec/dsl_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'capybara/dsl'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Capybara::Selenium::Driver do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Capybara::Selenium::Driver do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  module TestSessions
data/spec/result_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Capybara::Result do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'capybara/rspec'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'capybara/dsl'
3
4
  require 'capybara/rspec/matchers'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'capybara/rspec'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "capybara/rspec", type: :view do
data/spec/rspec_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe 'capybara/rspec', :type => :feature do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Capybara do
@@ -17,6 +18,20 @@ RSpec.describe Capybara do
17
18
  <p class="b">Some Content</p>
18
19
  <p class="b"></p>
19
20
  </div>
21
+ <input type="checkbox"/>
22
+ <input type="radio"/>
23
+ <input type="text"/>
24
+ <input type="file"/>
25
+ <a href="#">link</a>
26
+ <fieldset></fieldset>
27
+ <select>
28
+ <option value="a">A</option>
29
+ <option value="b" disabled>B</option>
30
+ <option value="c" selected>C</option>
31
+ </select>
32
+ <table>
33
+ <tr><td></td></tr>
34
+ </table
20
35
  </body>
21
36
  </html>
22
37
  STRING
@@ -29,7 +44,7 @@ RSpec.describe Capybara do
29
44
  end
30
45
  end
31
46
 
32
- describe "modfiy_selector" do
47
+ describe "modify_selector" do
33
48
  it "allows modifying a selector" do
34
49
  el = string.find(:custom_selector, 'a')
35
50
  expect(el.tag_name).to eq 'div'
@@ -49,5 +64,44 @@ RSpec.describe Capybara do
49
64
  expect(string).to have_selector(:custom_selector, 'b', not_empty: :all, count: 2)
50
65
  end
51
66
  end
67
+
68
+ describe "builtin selectors" do
69
+ context "when locator is nil" do
70
+ it "devolves to just finding element types" do
71
+ selectors = {
72
+ field: ".//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]",
73
+ fieldset: ".//fieldset",
74
+ link: ".//a[./@href]",
75
+ link_or_button: ".//a[./@href] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'] | .//button" ,
76
+ fillable_field: ".//*[self::input | self::textarea][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'radio' or ./@type = 'checkbox' or ./@type = 'hidden' or ./@type = 'file')]",
77
+ radio_button: ".//input[./@type = 'radio']",
78
+ checkbox: ".//input[./@type = 'checkbox']",
79
+ select: ".//select",
80
+ option: ".//option",
81
+ file_field: ".//input[./@type = 'file']",
82
+ table: ".//table"
83
+ }
84
+ selectors.each do |selector, xpath|
85
+ results = string.all(selector,nil).to_a.map &:native
86
+ expect(results.size).to be > 0
87
+ expect(results).to eq string.all(:xpath, xpath).to_a.map(&:native)
88
+ end
89
+ end
90
+ end
91
+
92
+ describe ":option selector" do
93
+ it "finds disabled options" do
94
+ expect(string.find(:option, disabled: true).value).to eq 'b'
95
+ end
96
+
97
+ it "finds selected options" do
98
+ expect(string.find(:option, selected: true).value).to eq 'c'
99
+ end
100
+
101
+ it "finds not selected and not disabled options" do
102
+ expect(string.find(:option, disabled: false, selected: false).value).to eq 'a'
103
+ end
104
+ end
105
+ end
52
106
  end
53
107
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require "selenium-webdriver"
3
4
 
@@ -11,11 +12,14 @@ module TestSessions
11
12
  Selenium = Capybara::Session.new(:selenium_focus, TestApp)
12
13
  end
13
14
 
14
- Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => [
15
+ skipped_tests = [
15
16
  :response_headers,
16
17
  :status_code,
17
18
  :trigger
18
19
  ]
20
+ skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
21
+
22
+ Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
19
23
 
20
24
  RSpec.describe Capybara::Session do
21
25
  context 'with selenium driver' do
@@ -110,7 +114,7 @@ RSpec.describe Capybara::Session do
110
114
  end
111
115
 
112
116
  context "#fill_in with { clear: Array } fill_options" do
113
- it 'should pass the array through to the element', tw: true do
117
+ it 'should pass the array through to the element' do
114
118
  #this is mainly for use with [[:ctrl, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
115
119
  @session.visit('/form')
116
120
  @session.fill_in('form_first_name', :with => 'Harry',
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'selenium-webdriver'
3
4