capybara 2.18.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +55 -1
- data/README.md +18 -17
- data/lib/capybara/config.rb +11 -58
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +15 -16
- data/lib/capybara/driver/node.rb +5 -4
- data/lib/capybara/dsl.rb +1 -0
- data/lib/capybara/helpers.rb +19 -29
- data/lib/capybara/minitest/spec.rb +15 -14
- data/lib/capybara/minitest.rb +139 -138
- data/lib/capybara/node/actions.rb +60 -81
- data/lib/capybara/node/base.rb +11 -18
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +8 -8
- data/lib/capybara/node/element.rb +30 -40
- data/lib/capybara/node/finders.rb +62 -70
- data/lib/capybara/node/matchers.rb +50 -71
- data/lib/capybara/node/simple.rb +11 -17
- data/lib/capybara/queries/ancestor_query.rb +11 -7
- data/lib/capybara/queries/base_query.rb +22 -18
- data/lib/capybara/queries/current_path_query.rb +8 -24
- data/lib/capybara/queries/match_query.rb +3 -7
- data/lib/capybara/queries/selector_query.rb +92 -95
- data/lib/capybara/queries/sibling_query.rb +4 -4
- data/lib/capybara/queries/text_query.rb +35 -35
- data/lib/capybara/queries/title_query.rb +8 -11
- data/lib/capybara/rack_test/browser.rb +15 -18
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +6 -10
- data/lib/capybara/rack_test/form.rb +50 -40
- data/lib/capybara/rack_test/node.rb +93 -63
- data/lib/capybara/rails.rb +2 -6
- data/lib/capybara/result.rb +22 -22
- data/lib/capybara/rspec/compound.rb +5 -10
- data/lib/capybara/rspec/features.rb +17 -48
- data/lib/capybara/rspec/matcher_proxies.rb +31 -15
- data/lib/capybara/rspec/matchers.rb +70 -61
- data/lib/capybara/rspec.rb +5 -10
- data/lib/capybara/selector/css.rb +6 -11
- data/lib/capybara/selector/filter.rb +1 -17
- data/lib/capybara/selector/filter_set.rb +18 -15
- data/lib/capybara/selector/filters/base.rb +7 -6
- data/lib/capybara/selector/filters/expression_filter.rb +6 -23
- data/lib/capybara/selector/filters/node_filter.rb +2 -12
- data/lib/capybara/selector/selector.rb +28 -34
- data/lib/capybara/selector.rb +129 -117
- data/lib/capybara/selenium/driver.rb +131 -125
- data/lib/capybara/selenium/node.rb +197 -115
- data/lib/capybara/server.rb +3 -2
- data/lib/capybara/session/config.rb +47 -67
- data/lib/capybara/session/matchers.rb +8 -7
- data/lib/capybara/session.rb +138 -224
- data/lib/capybara/spec/public/test.js +25 -4
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
- data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/all_spec.rb +31 -18
- data/lib/capybara/spec/session/ancestor_spec.rb +6 -8
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
- data/lib/capybara/spec/session/assert_current_path.rb +12 -11
- data/lib/capybara/spec/session/assert_selector.rb +1 -0
- data/lib/capybara/spec/session/assert_text.rb +23 -23
- data/lib/capybara/spec/session/assert_title.rb +13 -3
- data/lib/capybara/spec/session/attach_file_spec.rb +51 -30
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +7 -6
- data/lib/capybara/spec/session/choose_spec.rb +5 -4
- data/lib/capybara/spec/session/click_button_spec.rb +24 -32
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
- data/lib/capybara/spec/session/click_link_spec.rb +8 -7
- data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
- data/lib/capybara/spec/session/current_url_spec.rb +17 -6
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
- data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
- data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
- data/lib/capybara/spec/session/fill_in_spec.rb +30 -5
- data/lib/capybara/spec/session/find_button_spec.rb +4 -3
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
- data/lib/capybara/spec/session/find_field_spec.rb +9 -15
- data/lib/capybara/spec/session/find_link_spec.rb +6 -5
- data/lib/capybara/spec/session/find_spec.rb +37 -31
- data/lib/capybara/spec/session/first_spec.rb +60 -33
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
- data/lib/capybara/spec/session/go_back_spec.rb +1 -0
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
- data/lib/capybara/spec/session/has_button_spec.rb +2 -1
- data/lib/capybara/spec/session/has_css_spec.rb +3 -2
- data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
- data/lib/capybara/spec/session/has_field_spec.rb +4 -3
- data/lib/capybara/spec/session/has_link_spec.rb +1 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/has_select_spec.rb +30 -29
- data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
- data/lib/capybara/spec/session/has_table_spec.rb +2 -1
- data/lib/capybara/spec/session/has_text_spec.rb +9 -13
- data/lib/capybara/spec/session/has_title_spec.rb +1 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
- data/lib/capybara/spec/session/headers.rb +2 -1
- data/lib/capybara/spec/session/html_spec.rb +1 -0
- data/lib/capybara/spec/session/node_spec.rb +91 -56
- data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
- data/lib/capybara/spec/session/refresh_spec.rb +6 -2
- data/lib/capybara/spec/session/reset_session_spec.rb +19 -0
- data/lib/capybara/spec/session/response_code.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
- data/lib/capybara/spec/session/save_page_spec.rb +1 -17
- data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -3
- data/lib/capybara/spec/session/select_spec.rb +20 -20
- data/lib/capybara/spec/session/selectors_spec.rb +2 -2
- data/lib/capybara/spec/session/sibling_spec.rb +1 -1
- data/lib/capybara/spec/session/text_spec.rb +17 -3
- data/lib/capybara/spec/session/title_spec.rb +11 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
- data/lib/capybara/spec/session/unselect_spec.rb +6 -5
- data/lib/capybara/spec/session/visit_spec.rb +9 -3
- data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_spec.rb +12 -12
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
- data/lib/capybara/spec/session/window/within_window_spec.rb +15 -71
- data/lib/capybara/spec/session/within_spec.rb +1 -0
- data/lib/capybara/spec/spec_helper.rb +34 -18
- data/lib/capybara/spec/test_app.rb +17 -9
- data/lib/capybara/spec/views/form.erb +7 -0
- data/lib/capybara/spec/views/with_html.erb +23 -1
- data/lib/capybara/spec/views/within_frames.erb +4 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +6 -10
- data/lib/capybara.rb +28 -25
- data/spec/basic_node_spec.rb +1 -0
- data/spec/capybara_spec.rb +11 -50
- data/spec/dsl_spec.rb +5 -13
- data/spec/filter_set_spec.rb +5 -4
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
- data/spec/minitest_spec.rb +4 -3
- data/spec/minitest_spec_spec.rb +3 -2
- data/spec/per_session_config_spec.rb +9 -8
- data/spec/rack_test_spec.rb +21 -20
- data/spec/result_spec.rb +17 -16
- data/spec/rspec/features_spec.rb +17 -14
- data/spec/rspec/scenarios_spec.rb +5 -7
- data/spec/rspec/shared_spec_matchers.rb +96 -99
- data/spec/rspec/views_spec.rb +2 -1
- data/spec/rspec_matchers_spec.rb +18 -2
- data/spec/rspec_spec.rb +11 -15
- data/spec/selector_spec.rb +5 -6
- data/spec/selenium_spec_chrome.rb +9 -4
- data/spec/selenium_spec_edge.rb +27 -0
- data/spec/selenium_spec_ie.rb +31 -0
- data/spec/selenium_spec_marionette.rb +28 -12
- data/spec/server_spec.rb +33 -33
- data/spec/session_spec.rb +2 -1
- data/spec/shared_selenium_session.rb +36 -22
- data/spec/spec_helper.rb +3 -6
- metadata +68 -85
- data/lib/capybara/query.rb +0 -7
- data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "rspec"
|
3
4
|
require "rspec/expectations"
|
4
5
|
require "capybara"
|
@@ -6,15 +7,6 @@ require "capybara/rspec" # Required here instead of in rspec_spec to avoid RSpec
|
|
6
7
|
require "capybara/spec/test_app"
|
7
8
|
require "nokogiri"
|
8
9
|
|
9
|
-
# Alias be_truthy/be_falsey if not already defined to be able to use in RSpec 2 and 3
|
10
|
-
unless RSpec::Matchers.method_defined?(:be_truthy)
|
11
|
-
RSpec::Matchers.module_eval do
|
12
|
-
alias be_truthy be_true
|
13
|
-
alias be_falsey be_false
|
14
|
-
alias be_falsy be_false
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
10
|
module Capybara
|
19
11
|
module SpecHelper
|
20
12
|
class << self
|
@@ -33,13 +25,9 @@ module Capybara
|
|
33
25
|
Capybara.default_max_wait_time = 1
|
34
26
|
Capybara.ignore_hidden_elements = true
|
35
27
|
Capybara.exact = false
|
36
|
-
# `exact_options` is deprecated - set instancce var directly so we
|
37
|
-
# don't generate message every reset
|
38
|
-
Capybara.send(:config).session_options.instance_variable_set('@exact_options', false)
|
39
28
|
Capybara.raise_server_errors = true
|
40
29
|
Capybara.visible_text_only = false
|
41
30
|
Capybara.match = :smart
|
42
|
-
Capybara.wait_on_first_by_default = false
|
43
31
|
Capybara.enable_aria_label = false
|
44
32
|
reset_threadsafe
|
45
33
|
end
|
@@ -59,7 +47,7 @@ module Capybara
|
|
59
47
|
@specs << [name, options, block]
|
60
48
|
end
|
61
49
|
|
62
|
-
def run_specs(session, name, options
|
50
|
+
def run_specs(session, name, **options)
|
63
51
|
specs = @specs
|
64
52
|
RSpec.describe Capybara::Session, name, options do
|
65
53
|
include Capybara::SpecHelper
|
@@ -80,6 +68,10 @@ module Capybara
|
|
80
68
|
SpecHelper.reset_threadsafe(false, @session)
|
81
69
|
end
|
82
70
|
|
71
|
+
before :each, :exact_false do
|
72
|
+
Capybara.exact = false
|
73
|
+
end
|
74
|
+
|
83
75
|
specs.each do |spec_name, spec_options, block|
|
84
76
|
describe spec_name, *spec_options do
|
85
77
|
class_eval(&block)
|
@@ -94,7 +86,7 @@ module Capybara
|
|
94
86
|
session = session.current_session if session.respond_to?(:current_session)
|
95
87
|
session.instance_variable_set(:@config, nil) if session
|
96
88
|
end
|
97
|
-
end
|
89
|
+
end
|
98
90
|
|
99
91
|
def silence_stream(stream)
|
100
92
|
old_stream = stream.dup
|
@@ -119,11 +111,35 @@ module Capybara
|
|
119
111
|
end
|
120
112
|
|
121
113
|
def marionette?(session)
|
122
|
-
session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?)
|
114
|
+
session.respond_to?(:driver) && session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?)
|
115
|
+
end
|
116
|
+
|
117
|
+
def marionette_lt?(version, session)
|
118
|
+
marionette?(session) && (session.driver.browser.capabilities[:browser_version].to_f < version)
|
119
|
+
end
|
120
|
+
|
121
|
+
def marionette_gte?(version, session)
|
122
|
+
marionette?(session) && (session.driver.browser.capabilities[:browser_version].to_f >= version)
|
123
|
+
end
|
124
|
+
|
125
|
+
def chrome?(session)
|
126
|
+
session.respond_to?(:driver) && session.driver.respond_to?(:chrome?, true) && session.driver.send(:chrome?)
|
127
|
+
end
|
128
|
+
|
129
|
+
def chrome_lt?(version, session)
|
130
|
+
chrome?(session) && (session.driver.browser.capabilities[:version].to_f < version)
|
131
|
+
end
|
132
|
+
|
133
|
+
def chrome_gte?(version, session)
|
134
|
+
chrome?(session) && (session.driver.browser.capabilities[:version].to_f >= version)
|
135
|
+
end
|
136
|
+
|
137
|
+
def edge?(session)
|
138
|
+
session.respond_to?(:driver) && session.driver.respond_to?(:edge?, true) && session.driver.send(:edge?)
|
123
139
|
end
|
124
140
|
|
125
|
-
def
|
126
|
-
|
141
|
+
def ie?(session)
|
142
|
+
session.respond_to?(:driver) && session.driver.respond_to?(:ie?, true) && session.driver.send(:ie?)
|
127
143
|
end
|
128
144
|
end
|
129
145
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'sinatra/base'
|
3
4
|
require 'tilt/erb'
|
4
5
|
require 'rack'
|
@@ -21,7 +22,7 @@ class TestApp < Sinatra::Base
|
|
21
22
|
# Also check lib/capybara/spec/views/*.erb for pages not listed here
|
22
23
|
|
23
24
|
get '/' do
|
24
|
-
response.set_cookie('capybara',
|
25
|
+
response.set_cookie('capybara', value: 'root cookie', domain: request.host, path: request.path)
|
25
26
|
'Hello world! <a href="with_html">Relative</a>'
|
26
27
|
end
|
27
28
|
|
@@ -38,8 +39,8 @@ class TestApp < Sinatra::Base
|
|
38
39
|
end
|
39
40
|
|
40
41
|
get '/referer_base' do
|
41
|
-
'<a href="/get_referer">direct link</a>'
|
42
|
-
'<a href="/redirect_to_get_referer">link via redirect</a>'
|
42
|
+
'<a href="/get_referer">direct link</a>' \
|
43
|
+
'<a href="/redirect_to_get_referer">link via redirect</a>' \
|
43
44
|
'<form action="/get_referer" method="get"><input type="submit"></form>'
|
44
45
|
end
|
45
46
|
|
@@ -69,7 +70,7 @@ class TestApp < Sinatra::Base
|
|
69
70
|
end
|
70
71
|
|
71
72
|
get '/with-quotes' do
|
72
|
-
%q
|
73
|
+
%q("No," he said, "you can't do that.")
|
73
74
|
end
|
74
75
|
|
75
76
|
get '/form/get' do
|
@@ -143,13 +144,22 @@ class TestApp < Sinatra::Base
|
|
143
144
|
erb :with_html, locals: { referrer: request.referrer }
|
144
145
|
end
|
145
146
|
|
147
|
+
get '/with_title' do
|
148
|
+
<<-HTML
|
149
|
+
<title>#{params[:title] || 'Test Title'}</title>
|
150
|
+
<body>
|
151
|
+
<svg><title>abcdefg</title></svg>
|
152
|
+
</body>
|
153
|
+
HTML
|
154
|
+
end
|
155
|
+
|
146
156
|
get '/:view' do |view|
|
147
157
|
erb view.to_sym, locals: { referrer: request.referrer }
|
148
158
|
end
|
149
159
|
|
150
160
|
post '/form' do
|
151
161
|
@@form_post_count += 1
|
152
|
-
'<pre id="results">' + params[:form].merge(
|
162
|
+
'<pre id="results">' + params[:form].merge("post_count" => @@form_post_count).to_yaml + '</pre>'
|
153
163
|
end
|
154
164
|
|
155
165
|
post '/upload_empty' do
|
@@ -173,7 +183,7 @@ class TestApp < Sinatra::Base
|
|
173
183
|
|
174
184
|
post '/upload_multiple' do
|
175
185
|
begin
|
176
|
-
buffer = [
|
186
|
+
buffer = [params[:form][:multiple_documents].size.to_s]
|
177
187
|
params[:form][:multiple_documents].each do |doc|
|
178
188
|
buffer << "Content-type: #{doc[:type]}"
|
179
189
|
buffer << "File content: #{doc[:tempfile].read}"
|
@@ -185,6 +195,4 @@ class TestApp < Sinatra::Base
|
|
185
195
|
end
|
186
196
|
end
|
187
197
|
|
188
|
-
if
|
189
|
-
Rack::Handler::WEBrick.run TestApp, Port: 8070
|
190
|
-
end
|
198
|
+
Rack::Handler::Puma.run TestApp, Port: 8070 if $PROGRAM_NAME == __FILE__
|
@@ -186,6 +186,7 @@ New line after and before textarea tag
|
|
186
186
|
<input type="checkbox" value="pagani" name="form[cars][]" id="form_cars_pagani" style="position: absolute; left: -9999px"/>
|
187
187
|
<label for="form_cars_pagani">Pagani</label>
|
188
188
|
<input type="checkbox" value="ariel" name="form[cars][]" id="form_cars_ariel" style="display: none"/>
|
189
|
+
<input type="checkbox" value="porsche" name="form[cars][]" id="form_cars_porsche" checked="checked" style="display: none"/>
|
189
190
|
<label>
|
190
191
|
McLaren
|
191
192
|
<input type="checkbox" value="mclaren" name="form[cars][]" id="form_cars_mclaren" style="display: none"/>
|
@@ -425,6 +426,12 @@ New line after and before textarea tag
|
|
425
426
|
<input type="button" disabled="disabled" value="Disabled button"/>
|
426
427
|
</p>
|
427
428
|
|
429
|
+
<p>
|
430
|
+
<input type="date" name="form[date]" id="form_date"/>
|
431
|
+
<input type="time" name="form[time]" id="form_time"/>
|
432
|
+
<input type="datetime-local" name="form[datetime]" id="form_datetime">
|
433
|
+
</p>
|
434
|
+
|
428
435
|
<p>
|
429
436
|
<input id="readonly" name="form[readonly_test]" readonly/>
|
430
437
|
<input id="not_readonly" name="form[readonly_test]" />
|
@@ -150,4 +150,26 @@ banana</textarea>
|
|
150
150
|
<div data-pre=true>Pre Sibling</div>
|
151
151
|
<div data-post=true>Post Sibling</div>
|
152
152
|
</div>
|
153
|
-
</div>
|
153
|
+
</div>
|
154
|
+
|
155
|
+
<div id='1escape.me' class="2escape">needs escaping</div>
|
156
|
+
|
157
|
+
<div id="normalized">
|
158
|
+
Some text<div>More text</div>
|
159
|
+
<div> And more text</div>
|
160
|
+
Even more text
|
161
|
+
|
162
|
+
on multiple lines
|
163
|
+
</div>
|
164
|
+
|
165
|
+
<div id="non_visible_normalized" style="display: none">
|
166
|
+
Some text<div>More text</div>
|
167
|
+
<div> And more text</div>
|
168
|
+
Even more text
|
169
|
+
|
170
|
+
on multiple lines
|
171
|
+
</div>
|
172
|
+
|
173
|
+
<div id="ws">
|
174
|
+
                   
|
175
|
+
</div>
|
@@ -4,7 +4,10 @@
|
|
4
4
|
<title>With Frames</title>
|
5
5
|
</head>
|
6
6
|
<body>
|
7
|
-
<div id="divInMainWindow">
|
7
|
+
<div id="divInMainWindow">
|
8
|
+
This is the text for divInMainWindow
|
9
|
+
<iframe src="/frame_parent" id="innerParentFrame"></iframe>
|
10
|
+
</div>
|
8
11
|
<iframe src="/frame_one" id="frameOne" name="my frame one"></iframe>
|
9
12
|
<iframe src="/frame_two" id="frameTwo"></iframe>
|
10
13
|
<iframe src="/frame_parent" id="parentFrame"></iframe>
|
data/lib/capybara/version.rb
CHANGED
data/lib/capybara/window.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Capybara
|
3
4
|
##
|
4
5
|
# The Window class represents a browser window.
|
@@ -101,7 +102,7 @@ module Capybara
|
|
101
102
|
end
|
102
103
|
|
103
104
|
def eql?(other)
|
104
|
-
other.
|
105
|
+
other.is_a?(self.class) && @session == other.session && @handle == other.handle
|
105
106
|
end
|
106
107
|
alias_method :==, :eql?
|
107
108
|
|
@@ -113,9 +114,9 @@ module Capybara
|
|
113
114
|
"#<Window @handle=#{@handle.inspect}>"
|
114
115
|
end
|
115
116
|
|
116
|
-
|
117
|
+
private
|
117
118
|
|
118
|
-
def wait_for_stable_size(seconds=session.config.default_max_wait_time)
|
119
|
+
def wait_for_stable_size(seconds = session.config.default_max_wait_time)
|
119
120
|
res = yield if block_given?
|
120
121
|
prev_size = size
|
121
122
|
start_time = Capybara::Helpers.monotonic_time
|
@@ -125,16 +126,11 @@ module Capybara
|
|
125
126
|
return res if cur_size == prev_size
|
126
127
|
prev_size = cur_size
|
127
128
|
end while (Capybara::Helpers.monotonic_time - start_time) < seconds
|
128
|
-
|
129
|
-
#raise Capybara::WindowError, "Window size not stable."
|
130
|
-
warn "Window size not stable in #{seconds} seconds. This will raise an exception in a future version of Capybara"
|
131
|
-
return res
|
129
|
+
raise Capybara::WindowError, "Window size not stable within #{seconds} seconds."
|
132
130
|
end
|
133
131
|
|
134
132
|
def raise_unless_current(what)
|
135
|
-
unless current?
|
136
|
-
raise Capybara::WindowError, "#{what} not current window is not possible."
|
137
|
-
end
|
133
|
+
raise Capybara::WindowError, "#{what} not current window is not possible." unless current?
|
138
134
|
end
|
139
135
|
end
|
140
136
|
end
|
data/lib/capybara.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'timeout'
|
3
4
|
require 'nokogiri'
|
4
5
|
require 'xpath'
|
@@ -21,7 +22,6 @@ module Capybara
|
|
21
22
|
class WindowError < CapybaraError; end
|
22
23
|
class ReadOnlyElementError < CapybaraError; end
|
23
24
|
|
24
|
-
|
25
25
|
class << self
|
26
26
|
extend Forwardable
|
27
27
|
|
@@ -51,8 +51,6 @@ module Capybara
|
|
51
51
|
# See {Capybara.configure}
|
52
52
|
# @!method always_include_port
|
53
53
|
# See {Capybara.configure}
|
54
|
-
# @!method wait_on_first_by_default
|
55
|
-
# See {Capybara.configure}
|
56
54
|
SessionConfig::OPTIONS.each do |method|
|
57
55
|
def_delegators :config, method, "#{method}="
|
58
56
|
end
|
@@ -79,7 +77,6 @@ module Capybara
|
|
79
77
|
# [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: true)
|
80
78
|
# [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true)
|
81
79
|
# [save_path = String] Where to put pages saved through save_(page|screenshot), save_and_open_(page|screenshot) (Default: Dir.pwd)
|
82
|
-
# [wait_on_first_by_default = Boolean] Whether Node#first defaults to Capybara waiting behavior for at least 1 element to match (Default: false)
|
83
80
|
# [automatic_label_click = Boolean] Whether Node#choose, Node#check, Node#uncheck will attempt to click the associated label element if the checkbox/radio button are non-visible (Default: false)
|
84
81
|
# [enable_aria_label = Boolean] Whether fields, links, and buttons will match against aria-label attribute (Default: false)
|
85
82
|
# [reuse_server = Boolean] Reuse the server thread between multiple sessions using the same app object (Default: true)
|
@@ -94,7 +91,7 @@ module Capybara
|
|
94
91
|
# [javascript_driver = Symbol] The name of a driver to use for JavaScript enabled tests. (Default: :selenium)
|
95
92
|
#
|
96
93
|
def configure
|
97
|
-
yield
|
94
|
+
yield config
|
98
95
|
end
|
99
96
|
|
100
97
|
##
|
@@ -128,7 +125,6 @@ module Capybara
|
|
128
125
|
# @yieldparam [<Rack>] app The rack application that this server will contain.
|
129
126
|
# @yieldparam port The port number the server should listen on
|
130
127
|
# @yieldparam host The host/ip to bind to
|
131
|
-
# @yieldreturn [Capybara::Driver::Base] A Capybara driver instance
|
132
128
|
#
|
133
129
|
def register_server(name, &block)
|
134
130
|
servers[name.to_sym] = block
|
@@ -192,8 +188,6 @@ module Capybara
|
|
192
188
|
@servers ||= {}
|
193
189
|
end
|
194
190
|
|
195
|
-
##
|
196
|
-
#
|
197
191
|
# Wraps the given string, which should contain an HTML document or fragment
|
198
192
|
# in a {Capybara::Node::Simple} which exposes all {Capybara::Node::Matchers},
|
199
193
|
# {Capybara::Node::Finders} and {Capybara::Node::DocumentMatchers}. This allows you to query
|
@@ -238,7 +232,7 @@ module Capybara
|
|
238
232
|
# @param [Integer] port The port to run the application on
|
239
233
|
#
|
240
234
|
def run_default_server(app, port)
|
241
|
-
servers[:
|
235
|
+
servers[:puma].call(app, port, server_host)
|
242
236
|
end
|
243
237
|
|
244
238
|
##
|
@@ -310,7 +304,7 @@ module Capybara
|
|
310
304
|
# as cookies.
|
311
305
|
#
|
312
306
|
def reset_sessions!
|
313
|
-
#reset in reverse so sessions that started servers are reset last
|
307
|
+
# reset in reverse so sessions that started servers are reset last
|
314
308
|
session_pool.reverse_each { |_mode, session| session.reset! }
|
315
309
|
end
|
316
310
|
alias_method :reset!, :reset_sessions!
|
@@ -364,10 +358,10 @@ module Capybara
|
|
364
358
|
# @param [String] html The raw html
|
365
359
|
# @return [Nokogiri::HTML::Document] HTML document
|
366
360
|
#
|
367
|
-
def HTML(html)
|
361
|
+
def HTML(html) # rubocop:disable Naming/MethodName
|
368
362
|
Nokogiri::HTML(html).tap do |document|
|
369
363
|
document.xpath('//textarea').each do |textarea|
|
370
|
-
textarea['_capybara_raw_value'] = textarea.content.sub(/\A\n/,'')
|
364
|
+
textarea['_capybara_raw_value'] = textarea.content.sub(/\A\n/, '')
|
371
365
|
end
|
372
366
|
end
|
373
367
|
end
|
@@ -376,12 +370,8 @@ module Capybara
|
|
376
370
|
config.session_options
|
377
371
|
end
|
378
372
|
|
379
|
-
def included(base)
|
380
|
-
base.send(:include, Capybara::DSL)
|
381
|
-
warn "`include Capybara` is deprecated. Please use `include Capybara::DSL` instead."
|
382
|
-
end
|
383
|
-
|
384
373
|
private
|
374
|
+
|
385
375
|
def config
|
386
376
|
@config ||= Capybara::Config.new
|
387
377
|
end
|
@@ -415,7 +405,6 @@ module Capybara
|
|
415
405
|
require 'capybara/queries/match_query'
|
416
406
|
require 'capybara/queries/ancestor_query'
|
417
407
|
require 'capybara/queries/sibling_query'
|
418
|
-
require 'capybara/query'
|
419
408
|
|
420
409
|
require 'capybara/node/finders'
|
421
410
|
require 'capybara/node/matchers'
|
@@ -443,14 +432,29 @@ Capybara.register_server :default do |app, port, _host|
|
|
443
432
|
Capybara.run_default_server(app, port)
|
444
433
|
end
|
445
434
|
|
446
|
-
Capybara.register_server :webrick do |app, port, host, options
|
435
|
+
Capybara.register_server :webrick do |app, port, host, **options|
|
447
436
|
require 'rack/handler/webrick'
|
448
|
-
Rack::Handler::WEBrick.run(app, {Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log
|
437
|
+
Rack::Handler::WEBrick.run(app, { Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log.new(nil, 0) }.merge(options))
|
449
438
|
end
|
450
439
|
|
451
|
-
Capybara.register_server :puma do |app, port, host, options
|
440
|
+
Capybara.register_server :puma do |app, port, host, **options|
|
452
441
|
require 'rack/handler/puma'
|
453
|
-
|
442
|
+
# If we just run the Puma Rack handler it installs signal handlers which prevent us from being able to interrupt tests.
|
443
|
+
# Therefore construct and run the Server instance ourselves.
|
444
|
+
# Rack::Handler::Puma.run(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))
|
445
|
+
|
446
|
+
conf = Rack::Handler::Puma.config(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))
|
447
|
+
events = conf.options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
|
448
|
+
|
449
|
+
events.log "Capybara starting Puma..."
|
450
|
+
events.log "* Version #{Puma::Const::PUMA_VERSION} , codename: #{Puma::Const::CODE_NAME}"
|
451
|
+
events.log "* Min threads: #{conf.options[:min_threads]}, max threads: #{conf.options[:max_threads]}"
|
452
|
+
|
453
|
+
Puma::Server.new(conf.app, events, conf.options).tap do |s|
|
454
|
+
s.binder.parse conf.options[:binds], s.events
|
455
|
+
s.min_threads = conf.options[:min_threads]
|
456
|
+
s.max_threads = conf.options[:max_threads]
|
457
|
+
end.run.join
|
454
458
|
end
|
455
459
|
|
456
460
|
Capybara.configure do |config|
|
@@ -468,7 +472,6 @@ Capybara.configure do |config|
|
|
468
472
|
config.raise_server_errors = true
|
469
473
|
config.server_errors = [StandardError]
|
470
474
|
config.visible_text_only = false
|
471
|
-
config.wait_on_first_by_default = false
|
472
475
|
config.automatic_label_click = false
|
473
476
|
config.enable_aria_label = false
|
474
477
|
config.reuse_server = true
|
@@ -483,11 +486,11 @@ Capybara.register_driver :selenium do |app|
|
|
483
486
|
end
|
484
487
|
|
485
488
|
Capybara.register_driver :selenium_chrome do |app|
|
486
|
-
Capybara::Selenium::Driver.new(app, :
|
489
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
487
490
|
end
|
488
491
|
|
489
492
|
Capybara.register_driver :selenium_chrome_headless do |app|
|
490
|
-
browser_options = ::Selenium::WebDriver::Chrome::Options.new
|
493
|
+
browser_options = ::Selenium::WebDriver::Chrome::Options.new
|
491
494
|
browser_options.args << '--headless'
|
492
495
|
browser_options.args << '--disable-gpu'
|
493
496
|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
|
data/spec/basic_node_spec.rb
CHANGED
data/spec/capybara_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara do
|
@@ -12,15 +13,6 @@ RSpec.describe Capybara do
|
|
12
13
|
Capybara.default_max_wait_time = 5
|
13
14
|
expect(Capybara.default_max_wait_time).to eq(5)
|
14
15
|
end
|
15
|
-
|
16
|
-
it "should be accesible as the deprecated default_wait_time" do
|
17
|
-
expect(Capybara.send(:config)).to receive(:warn).ordered.with('DEPRECATED: #default_wait_time= is deprecated, please use #default_max_wait_time= instead')
|
18
|
-
expect(Capybara.send(:config)).to receive(:warn).ordered.with('DEPRECATED: #default_wait_time is deprecated, please use #default_max_wait_time instead')
|
19
|
-
@previous_default_time = Capybara.default_max_wait_time
|
20
|
-
Capybara.default_wait_time = 5
|
21
|
-
expect(Capybara.default_wait_time).to eq(5)
|
22
|
-
expect(Capybara.default_max_wait_time).to eq(5)
|
23
|
-
end
|
24
16
|
end
|
25
17
|
|
26
18
|
describe '.register_driver' do
|
@@ -37,7 +29,7 @@ RSpec.describe Capybara do
|
|
37
29
|
describe '.register_server' do
|
38
30
|
it "should add a new server" do
|
39
31
|
handler = double("handler")
|
40
|
-
Capybara.register_server :blob do |
|
32
|
+
Capybara.register_server :blob do |_app, _port, _host|
|
41
33
|
handler.run
|
42
34
|
end
|
43
35
|
|
@@ -46,12 +38,8 @@ RSpec.describe Capybara do
|
|
46
38
|
end
|
47
39
|
|
48
40
|
describe ".server" do
|
49
|
-
before do
|
50
|
-
@old_server = Capybara.server
|
51
|
-
end
|
52
|
-
|
53
41
|
after do
|
54
|
-
Capybara.server
|
42
|
+
Capybara.server = :default
|
55
43
|
end
|
56
44
|
|
57
45
|
it "should default to a proc that calls run_default_server" do
|
@@ -61,33 +49,18 @@ RSpec.describe Capybara do
|
|
61
49
|
end
|
62
50
|
|
63
51
|
it "should return a custom server proc" do
|
64
|
-
server =
|
65
|
-
Capybara.
|
52
|
+
server = ->(_app, _port) {}
|
53
|
+
Capybara.register_server :custom, &server
|
54
|
+
Capybara.server = :custom
|
66
55
|
expect(Capybara.server).to eq(server)
|
67
56
|
end
|
68
57
|
|
69
58
|
it "should have :webrick registered" do
|
70
|
-
|
71
|
-
mock_app = double('app')
|
72
|
-
Capybara.server = :webrick
|
73
|
-
expect(Rack::Handler::WEBrick).to receive(:run)
|
74
|
-
Capybara.server.call(mock_app, 8000)
|
59
|
+
expect(Capybara.servers[:webrick]).not_to be_nil
|
75
60
|
end
|
76
61
|
|
77
62
|
it "should have :puma registered" do
|
78
|
-
|
79
|
-
mock_app = double('app')
|
80
|
-
Capybara.server = :puma
|
81
|
-
expect(Rack::Handler::Puma).to receive(:run).with(mock_app, hash_including(Host: nil, Port: 8000))
|
82
|
-
Capybara.server.call(mock_app, 8000)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should pass options to server" do
|
86
|
-
require 'rack/handler/puma'
|
87
|
-
mock_app = double('app')
|
88
|
-
Capybara.server = :puma, { Silent: true }
|
89
|
-
expect(Rack::Handler::Puma).to receive(:run).with(mock_app, hash_including(Host: nil, Port: 9000, Silent: true))
|
90
|
-
Capybara.server.call(mock_app, 9000)
|
63
|
+
expect(Capybara.servers[:puma]).not_to be_nil
|
91
64
|
end
|
92
65
|
end
|
93
66
|
|
@@ -116,7 +89,7 @@ RSpec.describe Capybara do
|
|
116
89
|
Capybara.default_host = old_default
|
117
90
|
end
|
118
91
|
|
119
|
-
it "should
|
92
|
+
it "should raise if not a valid URL" do
|
120
93
|
expect { Capybara.default_host = "www.example.com" }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/)
|
121
94
|
end
|
122
95
|
|
@@ -124,26 +97,14 @@ RSpec.describe Capybara do
|
|
124
97
|
expect { Capybara.default_host = "http://www.example.com" }.not_to raise_error
|
125
98
|
end
|
126
99
|
end
|
127
|
-
|
128
|
-
describe "configure" do
|
129
|
-
it 'deprecates calling non configuration option methods in configure' do
|
130
|
-
expect_any_instance_of(Kernel).to receive(:warn).
|
131
|
-
with('Calling register_driver from Capybara.configure is deprecated - please call it on Capybara directly ( Capybara.register_driver(...) )')
|
132
|
-
Capybara.configure do |config|
|
133
|
-
config.register_driver(:random_name) do
|
134
|
-
#just a random block
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
100
|
end
|
140
101
|
|
141
102
|
RSpec.describe Capybara::Session do
|
142
103
|
context 'with nonexistent driver' do
|
143
104
|
it "should raise an error" do
|
144
|
-
expect
|
105
|
+
expect do
|
145
106
|
Capybara::Session.new(:quox, TestApp).driver
|
146
|
-
|
107
|
+
end.to raise_error(Capybara::DriverNotFoundError)
|
147
108
|
end
|
148
109
|
end
|
149
110
|
end
|
data/spec/dsl_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'capybara/dsl'
|
4
5
|
|
@@ -6,17 +7,8 @@ class TestClass
|
|
6
7
|
include Capybara::DSL
|
7
8
|
end
|
8
9
|
|
9
|
-
Capybara::SpecHelper.run_specs TestClass.new, "DSL", capybara_skip: [
|
10
|
-
|
11
|
-
:modals,
|
12
|
-
:screenshot,
|
13
|
-
:frames,
|
14
|
-
:windows,
|
15
|
-
:send_keys,
|
16
|
-
:server,
|
17
|
-
:hover,
|
18
|
-
:about_scheme,
|
19
|
-
:psc
|
10
|
+
Capybara::SpecHelper.run_specs TestClass.new, "DSL", capybara_skip: %i[
|
11
|
+
js modals screenshot frames windows send_keys server hover about_scheme psc
|
20
12
|
]
|
21
13
|
|
22
14
|
RSpec.describe Capybara::DSL do
|
@@ -93,7 +85,7 @@ RSpec.describe Capybara::DSL do
|
|
93
85
|
driver_before_block = Capybara.current_driver
|
94
86
|
begin
|
95
87
|
Capybara.using_driver(:selenium) { raise "ohnoes!" }
|
96
|
-
rescue Exception
|
88
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
97
89
|
end
|
98
90
|
expect(Capybara.current_driver).to eq(driver_before_block)
|
99
91
|
end
|
@@ -211,7 +203,7 @@ RSpec.describe Capybara::DSL do
|
|
211
203
|
Capybara.using_session(:raise) do
|
212
204
|
raise
|
213
205
|
end
|
214
|
-
rescue Exception
|
206
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
215
207
|
end
|
216
208
|
expect(Capybara.session_name).to eq(:default)
|
217
209
|
end
|
data/spec/filter_set_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara::Selector::FilterSet do
|
@@ -8,8 +9,8 @@ RSpec.describe Capybara::Selector::FilterSet do
|
|
8
9
|
|
9
10
|
it "allows node filters" do
|
10
11
|
fs = Capybara::Selector::FilterSet.add(:test) do
|
11
|
-
filter(:node_test, :boolean) { |
|
12
|
-
expression_filter(:expression_test, :boolean) { |
|
12
|
+
filter(:node_test, :boolean) { |_node, _value| true }
|
13
|
+
expression_filter(:expression_test, :boolean) { |_expr, _value| true }
|
13
14
|
end
|
14
15
|
|
15
16
|
expect(fs.node_filters.keys).to include(:node_test)
|
@@ -18,8 +19,8 @@ RSpec.describe Capybara::Selector::FilterSet do
|
|
18
19
|
|
19
20
|
it "allows expression filters" do
|
20
21
|
fs = Capybara::Selector::FilterSet.add(:test) do
|
21
|
-
filter(:node_test, :boolean) { |
|
22
|
-
expression_filter(:expression_test, :boolean) { |
|
22
|
+
filter(:node_test, :boolean) { |_node, _value| true }
|
23
|
+
expression_filter(:expression_test, :boolean) { |_expr, _value| true }
|
23
24
|
end
|
24
25
|
|
25
26
|
expect(fs.expression_filters.keys).to include(:expression_test)
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'selenium-webdriver'
|
4
5
|
|
5
6
|
RSpec.describe Capybara::Selenium::Driver do
|
6
7
|
it "should exit with a non-zero exit status" do
|
7
8
|
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
8
|
-
options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false) if ENV['LEGACY_FIREFOX']
|
9
9
|
browser = Capybara::Selenium::Driver.new(TestApp, options).browser
|
10
|
+
expect(browser).to be
|
10
11
|
expect(true).to eq(false)
|
11
12
|
end
|
12
13
|
end
|