capybara 3.37.1 → 3.39.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 +54 -4
- data/README.md +23 -11
- data/lib/capybara/helpers.rb +5 -1
- data/lib/capybara/node/actions.rb +4 -4
- data/lib/capybara/node/base.rb +2 -1
- data/lib/capybara/node/finders.rb +2 -0
- data/lib/capybara/node/whitespace_normalizer.rb +81 -0
- data/lib/capybara/queries/base_query.rb +2 -2
- data/lib/capybara/queries/selector_query.rb +4 -2
- data/lib/capybara/queries/text_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +8 -2
- data/lib/capybara/rack_test/form.rb +29 -7
- data/lib/capybara/rack_test/node.rb +18 -15
- data/lib/capybara/registrations/drivers.rb +3 -3
- data/lib/capybara/registrations/servers.rb +30 -10
- data/lib/capybara/rspec/matcher_proxies.rb +3 -3
- data/lib/capybara/rspec/matchers/base.rb +8 -6
- data/lib/capybara/rspec/matchers/compound.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +2 -1
- data/lib/capybara/selector/definition.rb +1 -1
- data/lib/capybara/selector/filter_set.rb +4 -5
- data/lib/capybara/selector/regexp_disassembler.rb +2 -5
- data/lib/capybara/selenium/driver.rb +6 -3
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +8 -4
- data/lib/capybara/selenium/extensions/html5_drag.rb +5 -4
- data/lib/capybara/selenium/logger_suppressor.rb +4 -0
- data/lib/capybara/selenium/node.rb +60 -25
- data/lib/capybara/selenium/nodes/chrome_node.rb +5 -1
- data/lib/capybara/selenium/nodes/edge_node.rb +24 -2
- data/lib/capybara/selenium/nodes/firefox_node.rb +2 -2
- data/lib/capybara/selenium/nodes/safari_node.rb +2 -2
- data/lib/capybara/selenium/patches/action_pauser.rb +3 -3
- data/lib/capybara/selenium/patches/atoms.rb +1 -1
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -1
- data/lib/capybara/server/animation_disabler.rb +21 -22
- data/lib/capybara/server/middleware.rb +1 -1
- data/lib/capybara/session/config.rb +3 -1
- data/lib/capybara/session.rb +11 -9
- data/lib/capybara/spec/public/test.js +4 -0
- data/lib/capybara/spec/session/all_spec.rb +1 -1
- data/lib/capybara/spec/session/attach_file_spec.rb +6 -0
- data/lib/capybara/spec/session/check_spec.rb +1 -0
- data/lib/capybara/spec/session/click_link_spec.rb +11 -0
- data/lib/capybara/spec/session/current_scope_spec.rb +1 -1
- data/lib/capybara/spec/session/fill_in_spec.rb +6 -0
- data/lib/capybara/spec/session/find_link_spec.rb +10 -0
- data/lib/capybara/spec/session/find_spec.rb +2 -2
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +2 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +5 -5
- data/lib/capybara/spec/session/has_ancestor_spec.rb +2 -2
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +2 -2
- data/lib/capybara/spec/session/has_button_spec.rb +6 -0
- data/lib/capybara/spec/session/has_current_path_spec.rb +1 -1
- data/lib/capybara/spec/session/has_link_spec.rb +10 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
- data/lib/capybara/spec/session/has_select_spec.rb +6 -0
- data/lib/capybara/spec/session/has_text_spec.rb +4 -8
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -0
- data/lib/capybara/spec/session/node_spec.rb +40 -1
- data/lib/capybara/spec/session/reset_session_spec.rb +13 -0
- data/lib/capybara/spec/session/scroll_spec.rb +3 -1
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
- data/lib/capybara/spec/session/within_spec.rb +13 -0
- data/lib/capybara/spec/spec_helper.rb +8 -2
- data/lib/capybara/spec/test_app.rb +25 -6
- data/lib/capybara/spec/views/form.erb +17 -0
- data/lib/capybara/spec/views/with_html.erb +3 -3
- data/lib/capybara/spec/views/with_scope.erb +2 -2
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +4 -2
- data/spec/capybara_spec.rb +12 -0
- data/spec/counter_spec.rb +35 -0
- data/spec/css_builder_spec.rb +1 -1
- data/spec/css_splitter_spec.rb +1 -1
- data/spec/dsl_spec.rb +2 -0
- data/spec/minitest_spec.rb +4 -0
- data/spec/minitest_spec_spec.rb +4 -0
- data/spec/per_session_config_spec.rb +1 -1
- data/spec/rack_test_spec.rb +10 -2
- data/spec/rspec/scenarios_spec.rb +1 -1
- data/spec/rspec/shared_spec_matchers.rb +1 -1
- data/spec/rspec_matchers_spec.rb +25 -0
- data/spec/rspec_spec.rb +2 -2
- data/spec/sauce_spec_chrome.rb +1 -1
- data/spec/selector_spec.rb +2 -2
- data/spec/selenium_spec_chrome.rb +7 -6
- data/spec/selenium_spec_chrome_remote.rb +8 -8
- data/spec/selenium_spec_edge.rb +12 -6
- data/spec/selenium_spec_firefox.rb +20 -8
- data/spec/selenium_spec_firefox_remote.rb +19 -4
- data/spec/selenium_spec_ie.rb +4 -2
- data/spec/selenium_spec_safari.rb +3 -1
- data/spec/server_spec.rb +2 -2
- data/spec/shared_selenium_session.rb +5 -5
- data/spec/spec_helper.rb +33 -0
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab39ff6da58cbd3edd267cec393f613a79bbabd1092e7929ad32f352ee46c914
|
4
|
+
data.tar.gz: c61ad6d311f09fba5878e865133adfe5c8f16b65b3f1a184e2ef95655f7f7685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e449ab4b9d7750df25bc5a2c4afb0391f825fa27c2b0cd86b34f1b903245e28268b55265b4d9a066616bcd40ed3f598b96701873e83d7da1ebafb8eb6e8568cd
|
7
|
+
data.tar.gz: beeba4a6862e5e51c93cbf530e2353ac3d5862fe818f192c18411133a17b836e634495d8d58a8a7215c9f153ba3a56c92b7b506b951868012b8661b05eeb5381
|
data/History.md
CHANGED
@@ -1,5 +1,55 @@
|
|
1
|
+
# Version 3.39.0
|
2
|
+
Release date: 2023-04-02
|
3
|
+
|
4
|
+
### Added
|
5
|
+
|
6
|
+
* Support `:target` filter option on `:link` selector [Yudai Takada]
|
7
|
+
* Experimental Rack 3 support
|
8
|
+
* Text normalization performance improvements [Brandon Weaver]
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
* MS Edge button click [Brian J. Bayer]
|
13
|
+
* Options/Capabilities choosing based on Selenium versions
|
14
|
+
* Support for base versions [Matijs van Zuijlen]
|
15
|
+
* ExpectedError not defined in Selenium 4+
|
16
|
+
* Filter block forwarding to a number of matchers [Christophe Bliard]
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
* Dropped support for rack 1.x
|
20
|
+
|
21
|
+
# Version 3.38.0
|
22
|
+
Release date: 2022-11-03
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
|
26
|
+
* Capybara.w3c_click_offset now defaults to true. If you need click offsets to be from the elements top left corner set it to false in your config
|
27
|
+
|
28
|
+
### Added
|
29
|
+
|
30
|
+
* Support Selenium 4.3 changes to click offset calculations
|
31
|
+
* `click`, `double_click`, `right_click` can now be called on the session to click the currently scoped element (or document)
|
32
|
+
* `Session#within` now passes the scoped element to the block
|
33
|
+
* Support rack-test 2+
|
34
|
+
* Retry interval is now configurable [Masahiro NOMOTO]
|
35
|
+
* Support Puma 6 - Issue #2590
|
36
|
+
* Selenium: DetachedShadowRootError is treated as an invalid element error [Perryn Fowler]
|
37
|
+
* Selenium: When inspected shadow roots will have a tag name of "ShadowRoot"
|
38
|
+
* `evaluate_async_script` added to Session::DSL_METHODS [Henry Blyth]
|
39
|
+
|
40
|
+
### Fixed
|
41
|
+
|
42
|
+
* Use higher precision clock in Capybara::Helpers::Timer if available
|
43
|
+
* rack-test driver behavior with \r\n - Issue #2547 [Stefan Hoffmann]
|
44
|
+
* Updated for deprecation of positional parameters in Selenium::WebDriver::ActionBuilder#pause
|
45
|
+
* Explicitly set cause on server raised errors
|
46
|
+
* Options no longer duplicated in have_xxx invalid option error message [Yudai Takada]
|
47
|
+
* Animation disabler is now threadsafe [Daniel Sheppard]
|
48
|
+
* Server connection count tracking [Oleksandr K.]
|
49
|
+
* Ensure scopes are reset when session is [Henry Blyth]
|
50
|
+
|
1
51
|
# Version 3.37.1
|
2
|
-
|
52
|
+
Release date: 2022-05-09
|
3
53
|
|
4
54
|
### Fixed
|
5
55
|
|
@@ -810,7 +860,7 @@ Release date: 2018-03-23
|
|
810
860
|
|
811
861
|
### Changed
|
812
862
|
|
813
|
-
*
|
863
|
+
* Visible text whitespace is no longer fully normalized in favor of being more in line with the WebDriver spec for visible text
|
814
864
|
* Drivers are expected to close extra windows when resetting the session
|
815
865
|
* Selenium driver supports Date/Time when filling in date/time/datetime-local inputs
|
816
866
|
* `current_url` returns the url for the top level browsing context
|
@@ -1216,7 +1266,7 @@ Release date: 2016-01-27
|
|
1216
1266
|
|
1217
1267
|
# Version 2.6.0
|
1218
1268
|
|
1219
|
-
|
1269
|
+
Release date: 2016-01-17
|
1220
1270
|
|
1221
1271
|
### Fixed
|
1222
1272
|
|
@@ -1280,7 +1330,7 @@ Release date: 2014-10-13
|
|
1280
1330
|
|
1281
1331
|
# Version 2.4.3
|
1282
1332
|
|
1283
|
-
|
1333
|
+
Release date: 2014-09-21
|
1284
1334
|
|
1285
1335
|
### Fixed
|
1286
1336
|
|
data/README.md
CHANGED
@@ -161,7 +161,7 @@ You can now write your specs like so:
|
|
161
161
|
```ruby
|
162
162
|
describe "the signin process", type: :feature do
|
163
163
|
before :each do
|
164
|
-
User.
|
164
|
+
User.create(email: 'user@example.com', password: 'password')
|
165
165
|
end
|
166
166
|
|
167
167
|
it "signs me in" do
|
@@ -192,7 +192,7 @@ Capybara also comes with a built in DSL for creating descriptive acceptance test
|
|
192
192
|
```ruby
|
193
193
|
feature "Signing in" do
|
194
194
|
background do
|
195
|
-
User.
|
195
|
+
User.create(email: 'user@example.com', password: 'caplin')
|
196
196
|
end
|
197
197
|
|
198
198
|
scenario "Signing in with correct credentials" do
|
@@ -205,7 +205,7 @@ feature "Signing in" do
|
|
205
205
|
expect(page).to have_content 'Success'
|
206
206
|
end
|
207
207
|
|
208
|
-
given(:other_user) { User.
|
208
|
+
given(:other_user) { User.create(email: 'other@example.com', password: 'rous') }
|
209
209
|
|
210
210
|
scenario "Signing in as another user" do
|
211
211
|
visit '/sessions/new'
|
@@ -336,7 +336,7 @@ By default, Capybara uses the `:rack_test` driver, which is fast but limited: it
|
|
336
336
|
does not support JavaScript, nor is it able to access HTTP resources outside of
|
337
337
|
your Rack application, such as remote APIs and OAuth services. To get around
|
338
338
|
these limitations, you can set up a different default driver for your features.
|
339
|
-
For example if you'd prefer to run everything in Selenium, you could do:
|
339
|
+
For example, if you'd prefer to run everything in Selenium, you could do:
|
340
340
|
|
341
341
|
```ruby
|
342
342
|
Capybara.default_driver = :selenium # :selenium_chrome and :selenium_chrome_headless are also registered
|
@@ -630,7 +630,7 @@ JS
|
|
630
630
|
|
631
631
|
### <a name="modals"></a>Modals
|
632
632
|
|
633
|
-
In drivers which support it, you can accept, dismiss and respond to alerts, confirms and prompts.
|
633
|
+
In drivers which support it, you can accept, dismiss and respond to alerts, confirms, and prompts.
|
634
634
|
|
635
635
|
You can accept or dismiss alert messages by wrapping the code that produces an alert in a block:
|
636
636
|
|
@@ -781,7 +781,7 @@ expect(page).to have_content('baz')
|
|
781
781
|
If clicking on the *foo* link triggers an asynchronous process, such as
|
782
782
|
an Ajax request, which, when complete will add the *bar* link to the page,
|
783
783
|
clicking on the *bar* link would be expected to fail, since that link doesn't
|
784
|
-
exist yet. However Capybara is smart enough to retry finding the link for a
|
784
|
+
exist yet. However, Capybara is smart enough to retry finding the link for a
|
785
785
|
brief period of time before giving up and throwing an error. The same is true of
|
786
786
|
the next line, which looks for the content *baz* on the page; it will retry
|
787
787
|
looking for that content for a brief time. You can adjust how long this period
|
@@ -795,13 +795,25 @@ Be aware that because of this behaviour, the following two statements are **not*
|
|
795
795
|
equivalent, and you should **always** use the latter!
|
796
796
|
|
797
797
|
```ruby
|
798
|
-
|
799
|
-
|
798
|
+
# Given use of a driver where the page is loaded when visit returns
|
799
|
+
# and that Capybara.predicates_wait is `true`
|
800
|
+
# consider a page where the `a` tag is removed through AJAX after 1s
|
801
|
+
visit(some_path)
|
802
|
+
!page.has_xpath?('a') # is false
|
803
|
+
page.has_no_xpath?('a') # is true
|
800
804
|
```
|
801
805
|
|
802
|
-
|
803
|
-
|
804
|
-
|
806
|
+
First expression:
|
807
|
+
- `has_xpath?('a')` is called right after `visit` returns. It is `true` because the link has not yet been removed
|
808
|
+
- Capybara does not wait upon successful predicates/assertions, therefore **has_xpath? returns `true` immediately**
|
809
|
+
- The expression returns `false` (because it is negated with the leading `!`)
|
810
|
+
|
811
|
+
Second expression:
|
812
|
+
- `has_no_xpath?('a')` is called right after `visit` returns. It is `false` because the link has not yet been removed.
|
813
|
+
- Capybara waits upon failed predicates/assertions, therefore **has_no_xpath? does not return `false` immediately**
|
814
|
+
- Capybara will periodically re-check the predicate/assertion up to the `default_max_wait_time` defined
|
815
|
+
- after 1s, the predicate becomes `true` (because the link has been removed)
|
816
|
+
- The expression returns `true`
|
805
817
|
|
806
818
|
Capybara's RSpec matchers, however, are smart enough to handle either form.
|
807
819
|
The two following statements are functionally equivalent:
|
data/lib/capybara/helpers.rb
CHANGED
@@ -85,7 +85,11 @@ module Capybara
|
|
85
85
|
Kernel.warn(message, uplevel: uplevel)
|
86
86
|
end
|
87
87
|
|
88
|
-
if defined?(Process::
|
88
|
+
if defined?(Process::CLOCK_MONOTONIC_RAW)
|
89
|
+
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC_RAW; end
|
90
|
+
elsif defined?(Process::CLOCK_MONOTONIC_PRECISE)
|
91
|
+
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC_PRECISE; end
|
92
|
+
elsif defined?(Process::CLOCK_MONOTONIC)
|
89
93
|
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end
|
90
94
|
else
|
91
95
|
def monotonic_time; Time.now.to_f; end
|
@@ -383,7 +383,7 @@ module Capybara
|
|
383
383
|
end
|
384
384
|
end
|
385
385
|
|
386
|
-
UPDATE_STYLE_SCRIPT = <<~
|
386
|
+
UPDATE_STYLE_SCRIPT = <<~JS
|
387
387
|
this.capybara_style_cache = this.style.cssText;
|
388
388
|
var css = arguments[0];
|
389
389
|
for (var prop in css){
|
@@ -393,20 +393,20 @@ module Capybara
|
|
393
393
|
}
|
394
394
|
JS
|
395
395
|
|
396
|
-
RESET_STYLE_SCRIPT = <<~
|
396
|
+
RESET_STYLE_SCRIPT = <<~JS
|
397
397
|
if (this.hasOwnProperty('capybara_style_cache')) {
|
398
398
|
this.style.cssText = this.capybara_style_cache;
|
399
399
|
delete this.capybara_style_cache;
|
400
400
|
}
|
401
401
|
JS
|
402
402
|
|
403
|
-
DATALIST_OPTIONS_SCRIPT = <<~
|
403
|
+
DATALIST_OPTIONS_SCRIPT = <<~JS
|
404
404
|
Array.prototype.slice.call((this.list||{}).options || []).
|
405
405
|
filter(function(el){ return !el.disabled }).
|
406
406
|
map(function(el){ return { "value": el.value, "label": el.label} })
|
407
407
|
JS
|
408
408
|
|
409
|
-
CAPTURE_FILE_ELEMENT_SCRIPT = <<~
|
409
|
+
CAPTURE_FILE_ELEMENT_SCRIPT = <<~JS
|
410
410
|
document.addEventListener('click', function file_catcher(e){
|
411
411
|
if (e.target.matches("input[type='file']")) {
|
412
412
|
window._capybara_clicked_file_input = e.target;
|
data/lib/capybara/node/base.rb
CHANGED
@@ -77,6 +77,7 @@ module Capybara
|
|
77
77
|
return yield if session.synchronized
|
78
78
|
|
79
79
|
seconds = session_options.default_max_wait_time if [nil, true].include? seconds
|
80
|
+
interval = session_options.default_retry_interval
|
80
81
|
session.synchronized = true
|
81
82
|
timer = Capybara::Helpers.timer(expire_in: seconds)
|
82
83
|
begin
|
@@ -88,7 +89,7 @@ module Capybara
|
|
88
89
|
if driver.wait?
|
89
90
|
raise e if timer.expired?
|
90
91
|
|
91
|
-
sleep
|
92
|
+
sleep interval
|
92
93
|
reload if session_options.automatic_reload
|
93
94
|
else
|
94
95
|
old_base = @base
|
@@ -149,6 +149,8 @@ module Capybara
|
|
149
149
|
# @option options [String, Regexp] id Match links with the id provided
|
150
150
|
# @option options [String] title Match links with the title provided
|
151
151
|
# @option options [String] alt Match links with a contained img element whose alt matches
|
152
|
+
# @option options [String, Boolean] download Match links with the download provided
|
153
|
+
# @option options [String] target Match links with the target provided
|
152
154
|
# @option options [String, Array<String>, Regexp] class Match links that match the class(es) provided
|
153
155
|
# @return [Capybara::Node::Element] The found element
|
154
156
|
#
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module Node
|
5
|
+
##
|
6
|
+
#
|
7
|
+
# {Capybara::Node::WhitespaceNormalizer} provides methods that
|
8
|
+
# help to normalize the spacing of text content inside of
|
9
|
+
# {Capybara::Node::Element}s by removing various unicode
|
10
|
+
# spacing and directional markings.
|
11
|
+
#
|
12
|
+
module WhitespaceNormalizer
|
13
|
+
# Unicode for NBSP, or
|
14
|
+
NON_BREAKING_SPACE = "\u00a0"
|
15
|
+
LINE_SEPERATOR = "\u2028"
|
16
|
+
PARAGRAPH_SEPERATOR = "\u2029"
|
17
|
+
|
18
|
+
# All spaces except for NBSP
|
19
|
+
BREAKING_SPACES = "[[:space:]&&[^#{NON_BREAKING_SPACE}]]"
|
20
|
+
|
21
|
+
# Whitespace we want to substitute with plain spaces
|
22
|
+
SQUEEZED_SPACES = " \n\f\t\v#{LINE_SEPERATOR}#{PARAGRAPH_SEPERATOR}"
|
23
|
+
|
24
|
+
# Any whitespace at the front of text
|
25
|
+
LEADING_SPACES = /\A#{BREAKING_SPACES}+/.freeze
|
26
|
+
|
27
|
+
# Any whitespace at the end of text
|
28
|
+
TRAILING_SPACES = /#{BREAKING_SPACES}+\z/.freeze
|
29
|
+
|
30
|
+
# "Invisible" space character
|
31
|
+
ZERO_WIDTH_SPACE = "\u200b"
|
32
|
+
|
33
|
+
# Signifies text is read left to right
|
34
|
+
LEFT_TO_RIGHT_MARK = "\u200e"
|
35
|
+
|
36
|
+
# Signifies text is read right to left
|
37
|
+
RIGHT_TO_LEFT_MARK = "\u200f"
|
38
|
+
|
39
|
+
# Characters we want to truncate from text
|
40
|
+
REMOVED_CHARACTERS = [ZERO_WIDTH_SPACE, LEFT_TO_RIGHT_MARK, RIGHT_TO_LEFT_MARK].join
|
41
|
+
|
42
|
+
# Matches multiple empty lines
|
43
|
+
EMPTY_LINES = /[\ \n]*\n[\ \n]*/.freeze
|
44
|
+
|
45
|
+
##
|
46
|
+
#
|
47
|
+
# Normalizes the spacing of a node's text to be similar to
|
48
|
+
# what matchers might expect.
|
49
|
+
#
|
50
|
+
# @param text [String]
|
51
|
+
# @return [String]
|
52
|
+
#
|
53
|
+
def normalize_spacing(text)
|
54
|
+
text
|
55
|
+
.delete(REMOVED_CHARACTERS)
|
56
|
+
.tr(SQUEEZED_SPACES, ' ')
|
57
|
+
.squeeze(' ')
|
58
|
+
.sub(LEADING_SPACES, '')
|
59
|
+
.sub(TRAILING_SPACES, '')
|
60
|
+
.tr(NON_BREAKING_SPACE, ' ')
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
#
|
65
|
+
# Variant on {Capybara::Node::Normalizer#normalize_spacing} that
|
66
|
+
# targets the whitespace of visible elements only.
|
67
|
+
#
|
68
|
+
# @param text [String]
|
69
|
+
# @return [String]
|
70
|
+
#
|
71
|
+
def normalize_visible_spacing(text)
|
72
|
+
text
|
73
|
+
.squeeze(' ')
|
74
|
+
.gsub(EMPTY_LINES, "\n")
|
75
|
+
.sub(LEADING_SPACES, '')
|
76
|
+
.sub(TRAILING_SPACES, '')
|
77
|
+
.tr(NON_BREAKING_SPACE, ' ')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -79,8 +79,8 @@ module Capybara
|
|
79
79
|
if count
|
80
80
|
message << " #{occurrences count}"
|
81
81
|
elsif between
|
82
|
-
message << " between #{between.begin ? between.first : 1} and" \
|
83
|
-
"
|
82
|
+
message << " between #{between.begin ? between.first : 1} and " \
|
83
|
+
"#{between.end ? between.last : 'infinite'} times"
|
84
84
|
elsif maximum
|
85
85
|
message << " at most #{occurrences maximum}"
|
86
86
|
elsif minimum
|
@@ -272,7 +272,7 @@ module Capybara
|
|
272
272
|
end
|
273
273
|
|
274
274
|
def valid_keys
|
275
|
-
VALID_KEYS + custom_keys
|
275
|
+
(VALID_KEYS + custom_keys).uniq
|
276
276
|
end
|
277
277
|
|
278
278
|
def matches_node_filters?(node, errors)
|
@@ -570,7 +570,9 @@ module Capybara
|
|
570
570
|
when :visible
|
571
571
|
node.initial_cache[:visible] || (node.initial_cache[:visible].nil? && node.visible?)
|
572
572
|
when :hidden
|
573
|
-
|
573
|
+
# TODO: check why the 'visbile' cache spelling mistake wasn't caught in a test
|
574
|
+
# (node.initial_cache[:visible] == false) || (node.initial_cache[:visbile].nil? && !node.visible?)
|
575
|
+
(node.initial_cache[:visible] == false) || (node.initial_cache[:visible].nil? && !node.visible?)
|
574
576
|
else
|
575
577
|
true
|
576
578
|
end
|
@@ -13,7 +13,7 @@ module Capybara
|
|
13
13
|
self.session_options = session_options
|
14
14
|
|
15
15
|
if expected_text.nil? && !exact?
|
16
|
-
warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. '\
|
16
|
+
warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. ' \
|
17
17
|
"Please specify a string or regexp instead. #{Capybara::Helpers.filter_backtrace(caller)}"
|
18
18
|
end
|
19
19
|
|
@@ -31,11 +31,17 @@ class Capybara::RackTest::Browser
|
|
31
31
|
request(last_request.fullpath, last_request.env)
|
32
32
|
end
|
33
33
|
|
34
|
-
def submit(method, path, attributes)
|
34
|
+
def submit(method, path, attributes, content_type: nil)
|
35
35
|
path = request_path if path.nil? || path.empty?
|
36
36
|
uri = build_uri(path)
|
37
37
|
uri.query = '' if method.to_s.casecmp('get').zero?
|
38
|
-
process_and_follow_redirects(
|
38
|
+
process_and_follow_redirects(
|
39
|
+
method,
|
40
|
+
uri.to_s,
|
41
|
+
attributes,
|
42
|
+
'HTTP_REFERER' => referer_url,
|
43
|
+
'CONTENT_TYPE' => content_type
|
44
|
+
)
|
39
45
|
end
|
40
46
|
|
41
47
|
def follow(method, path, **attributes)
|
@@ -16,6 +16,8 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
|
|
16
16
|
def path; @empty_file.path; end
|
17
17
|
def size; 0; end
|
18
18
|
def read; ''; end
|
19
|
+
def append_to(_); end
|
20
|
+
def set_encoding(_); end # rubocop:disable Naming/AccessorMethodName
|
19
21
|
end
|
20
22
|
|
21
23
|
def params(button)
|
@@ -28,19 +30,31 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
|
|
28
30
|
|
29
31
|
form_elements = native.xpath(form_elements_xpath).reject { |el| submitter?(el) && (el != button.native) }
|
30
32
|
|
31
|
-
form_elements.each_with_object(
|
33
|
+
form_params = form_elements.each_with_object({}.compare_by_identity) do |field, params|
|
32
34
|
case field.name
|
33
35
|
when 'input', 'button' then add_input_param(field, params)
|
34
36
|
when 'select' then add_select_param(field, params)
|
35
37
|
when 'textarea' then add_textarea_param(field, params)
|
36
38
|
end
|
39
|
+
end
|
40
|
+
|
41
|
+
form_params.each_with_object(make_params) do |(name, value), params|
|
42
|
+
merge_param!(params, name, value)
|
37
43
|
end.to_params_hash
|
44
|
+
|
45
|
+
# form_elements.each_with_object(make_params) do |field, params|
|
46
|
+
# case field.name
|
47
|
+
# when 'input', 'button' then add_input_param(field, params)
|
48
|
+
# when 'select' then add_select_param(field, params)
|
49
|
+
# when 'textarea' then add_textarea_param(field, params)
|
50
|
+
# end
|
51
|
+
# end.to_params_hash
|
38
52
|
end
|
39
53
|
|
40
54
|
def submit(button)
|
41
55
|
action = button&.[]('formaction') || native['action']
|
42
56
|
method = button&.[]('formmethod') || request_method
|
43
|
-
driver.submit(method, action.to_s, params(button))
|
57
|
+
driver.submit(method, action.to_s, params(button), content_type: native['enctype'])
|
44
58
|
end
|
45
59
|
|
46
60
|
def multipart?
|
@@ -86,6 +100,8 @@ private
|
|
86
100
|
|
87
101
|
Capybara::RackTest::Node.new(driver, field).value.to_s
|
88
102
|
when 'file'
|
103
|
+
return if value.empty? && params.keys.include?(name) && Rack::Test::VERSION.to_f >= 2.0 # rubocop:disable Performance/InefficientHashSearch
|
104
|
+
|
89
105
|
if multipart?
|
90
106
|
file_to_upload(value)
|
91
107
|
else
|
@@ -94,7 +110,8 @@ private
|
|
94
110
|
else
|
95
111
|
value
|
96
112
|
end
|
97
|
-
merge_param!(params, name, value)
|
113
|
+
# merge_param!(params, name, value)
|
114
|
+
params[name] = value
|
98
115
|
end
|
99
116
|
|
100
117
|
def file_to_upload(filename)
|
@@ -107,18 +124,23 @@ private
|
|
107
124
|
end
|
108
125
|
|
109
126
|
def add_select_param(field, params)
|
127
|
+
name = field['name']
|
110
128
|
if field.has_attribute?('multiple')
|
111
|
-
field.xpath('.//option[@selected]').
|
112
|
-
merge_param!(params, field['name'], (option['value'] || option.text).to_s)
|
129
|
+
value = field.xpath('.//option[@selected]').map do |option|
|
130
|
+
# merge_param!(params, field['name'], (option['value'] || option.text).to_s)
|
131
|
+
(option['value'] || option.text).to_s
|
113
132
|
end
|
133
|
+
params[name] = value unless value.empty?
|
114
134
|
else
|
115
135
|
option = field.xpath('.//option[@selected]').first || field.xpath('.//option').first
|
116
|
-
merge_param!(params, field['name'], (option['value'] || option.text).to_s) if option
|
136
|
+
# merge_param!(params, field['name'], (option['value'] || option.text).to_s) if option
|
137
|
+
params[name] = (option['value'] || option.text).to_s if option
|
117
138
|
end
|
118
139
|
end
|
119
140
|
|
120
141
|
def add_textarea_param(field, params)
|
121
|
-
merge_param!(params, field['name'], field['_capybara_raw_value'].to_s.gsub(/\n/, "\r\n"))
|
142
|
+
# merge_param!(params, field['name'], field['_capybara_raw_value'].to_s.gsub(/\r?\n/, "\r\n"))
|
143
|
+
params[field['name']] = field['_capybara_raw_value'].to_s.gsub(/\r?\n/, "\r\n")
|
122
144
|
end
|
123
145
|
|
124
146
|
def submitter?(el)
|
@@ -1,25 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'capybara/rack_test/errors'
|
4
|
+
require 'capybara/node/whitespace_normalizer'
|
4
5
|
|
5
6
|
class Capybara::RackTest::Node < Capybara::Driver::Node
|
7
|
+
include Capybara::Node::WhitespaceNormalizer
|
8
|
+
|
6
9
|
BLOCK_ELEMENTS = %w[p h1 h2 h3 h4 h5 h6 ol ul pre address blockquote dl div fieldset form hr noscript table].freeze
|
7
10
|
|
8
11
|
def all_text
|
9
|
-
native.text
|
10
|
-
.gsub(/[\u200b\u200e\u200f]/, '')
|
11
|
-
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, ' ')
|
12
|
-
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
|
13
|
-
.gsub(/[[:space:]&&[^\u00a0]]+\z/, '')
|
14
|
-
.tr("\u00a0", ' ')
|
12
|
+
normalize_spacing(native.text)
|
15
13
|
end
|
16
14
|
|
17
15
|
def visible_text
|
18
|
-
displayed_text
|
19
|
-
.gsub(/[\ \n]*\n[\ \n]*/, "\n")
|
20
|
-
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
|
21
|
-
.gsub(/[[:space:]&&[^\u00a0]]+\z/, '')
|
22
|
-
.tr("\u00a0", ' ')
|
16
|
+
normalize_visible_spacing(displayed_text)
|
23
17
|
end
|
24
18
|
|
25
19
|
def [](name)
|
@@ -153,9 +147,11 @@ protected
|
|
153
147
|
if !string_node.visible?(check_ancestor)
|
154
148
|
''
|
155
149
|
elsif native.text?
|
156
|
-
native
|
157
|
-
|
158
|
-
|
150
|
+
native
|
151
|
+
.text
|
152
|
+
.delete(REMOVED_CHARACTERS)
|
153
|
+
.tr(SQUEEZED_SPACES, ' ')
|
154
|
+
.squeeze(' ')
|
159
155
|
elsif native.element?
|
160
156
|
text = native.children.map do |child|
|
161
157
|
Capybara::RackTest::Node.new(driver, child).displayed_text(check_ancestor: false)
|
@@ -235,7 +231,14 @@ private
|
|
235
231
|
end
|
236
232
|
native.remove
|
237
233
|
else
|
238
|
-
|
234
|
+
value.to_s.tap do |set_value|
|
235
|
+
if set_value.end_with?("\n") && form&.css('input, textarea')&.count
|
236
|
+
native['value'] = set_value.to_s.chop
|
237
|
+
Capybara::RackTest::Form.new(driver, form).submit(self)
|
238
|
+
else
|
239
|
+
native['value'] = set_value
|
240
|
+
end
|
241
|
+
end
|
239
242
|
end
|
240
243
|
end
|
241
244
|
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
Capybara.register_driver :selenium_headless do |app|
|
12
12
|
version = Capybara::Selenium::Driver.load_selenium
|
13
13
|
options_key = Capybara::Selenium::Driver::CAPS_VERSION.satisfied_by?(version) ? :capabilities : :options
|
14
|
-
browser_options =
|
14
|
+
browser_options = Selenium::WebDriver::Firefox::Options.new.tap do |opts|
|
15
15
|
opts.add_argument '-headless'
|
16
16
|
end
|
17
17
|
Capybara::Selenium::Driver.new(app, **{ :browser => :firefox, options_key => browser_options })
|
@@ -20,7 +20,7 @@ end
|
|
20
20
|
Capybara.register_driver :selenium_chrome do |app|
|
21
21
|
version = Capybara::Selenium::Driver.load_selenium
|
22
22
|
options_key = Capybara::Selenium::Driver::CAPS_VERSION.satisfied_by?(version) ? :capabilities : :options
|
23
|
-
browser_options =
|
23
|
+
browser_options = Selenium::WebDriver::Chrome::Options.new.tap do |opts|
|
24
24
|
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
|
25
25
|
opts.add_argument('--disable-site-isolation-trials')
|
26
26
|
end
|
@@ -31,7 +31,7 @@ end
|
|
31
31
|
Capybara.register_driver :selenium_chrome_headless do |app|
|
32
32
|
version = Capybara::Selenium::Driver.load_selenium
|
33
33
|
options_key = Capybara::Selenium::Driver::CAPS_VERSION.satisfied_by?(version) ? :capabilities : :options
|
34
|
-
browser_options =
|
34
|
+
browser_options = Selenium::WebDriver::Chrome::Options.new.tap do |opts|
|
35
35
|
opts.add_argument('--headless')
|
36
36
|
opts.add_argument('--disable-gpu') if Gem.win_platform?
|
37
37
|
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
|
@@ -5,12 +5,24 @@ Capybara.register_server :default do |app, port, _host|
|
|
5
5
|
end
|
6
6
|
|
7
7
|
Capybara.register_server :webrick do |app, port, host, **options|
|
8
|
-
|
8
|
+
base_class = begin
|
9
|
+
require 'rack/handler/webrick'
|
10
|
+
Rack
|
11
|
+
rescue LoadError
|
12
|
+
# Rack 3 separated out the webrick handle - no way test currently in Capybaras automated
|
13
|
+
# tests due to Sinatra not yet supporting Rack 3 - experimental
|
14
|
+
require 'rackup/handler/webrick'
|
15
|
+
Rackup
|
16
|
+
end
|
9
17
|
options = { Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log.new(nil, 0) }.merge(options)
|
10
|
-
|
18
|
+
base_class::Handler::WEBrick.run(app, **options)
|
11
19
|
end
|
12
20
|
|
13
|
-
Capybara.register_server :puma do |app, port, host, **options|
|
21
|
+
Capybara.register_server :puma do |app, port, host, **options| # rubocop:disable Metrics/BlockLength
|
22
|
+
begin
|
23
|
+
require 'rackup'
|
24
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
25
|
+
end
|
14
26
|
begin
|
15
27
|
require 'rack/handler/puma'
|
16
28
|
rescue LoadError
|
@@ -29,17 +41,25 @@ Capybara.register_server :puma do |app, port, host, **options|
|
|
29
41
|
|
30
42
|
conf = Rack::Handler::Puma.config(app, options)
|
31
43
|
conf.clamp
|
32
|
-
events = conf.options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
|
33
44
|
|
34
45
|
puma_ver = Gem::Version.new(Puma::Const::PUMA_VERSION)
|
35
46
|
require_relative 'patches/puma_ssl' if Gem::Requirement.new('>=4.0.0', '< 4.1.0').satisfied_by?(puma_ver)
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
|
48
|
+
logger = (defined?(Puma::LogWriter) ? Puma::LogWriter : Puma::Events).then do |cls|
|
49
|
+
conf.options[:Silent] ? cls.strings : cls.stdio
|
50
|
+
end
|
51
|
+
conf.options[:log_writer] = logger
|
52
|
+
|
53
|
+
logger.log 'Capybara starting Puma...'
|
54
|
+
logger.log "* Version #{Puma::Const::PUMA_VERSION} , codename: #{Puma::Const::CODE_NAME}"
|
55
|
+
logger.log "* Min threads: #{conf.options[:min_threads]}, max threads: #{conf.options[:max_threads]}"
|
40
56
|
|
41
|
-
Puma::Server.new(
|
42
|
-
|
43
|
-
|
57
|
+
Puma::Server.new(
|
58
|
+
conf.app,
|
59
|
+
defined?(Puma::LogWriter) ? nil : logger,
|
60
|
+
conf.options
|
61
|
+
).tap do |s|
|
62
|
+
s.binder.parse conf.options[:binds], (s.log_writer rescue s.events) # rubocop:disable Style/RescueModifier
|
63
|
+
s.min_threads, s.max_threads = conf.options[:min_threads], conf.options[:max_threads] if s.respond_to? :min_threads=
|
44
64
|
end.run.join
|
45
65
|
end
|
@@ -36,7 +36,7 @@ if RUBY_ENGINE == 'jruby'
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
if defined?(
|
39
|
+
if defined?(RSpec::Matchers)
|
40
40
|
module ::RSpec::Matchers
|
41
41
|
def self.included(base)
|
42
42
|
base.send(:include, ::Capybara::RSpecMatcherProxies) if base.include?(::Capybara::DSL)
|
@@ -76,7 +76,7 @@ else
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
Capybara::DSL.prepend
|
79
|
+
Capybara::DSL.prepend Capybara::DSLRSpecProxyInstaller
|
80
80
|
|
81
|
-
|
81
|
+
RSpec::Matchers.prepend Capybara::RSpecMatcherProxyInstaller if defined?(RSpec::Matchers)
|
82
82
|
end
|