capybara-dommy 0.12.0 → 0.14.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +47 -0
- data/lib/capybara/dommy/configuration.rb +6 -1
- data/lib/capybara/dommy/driver.rb +102 -8
- data/lib/capybara/dommy/node.rb +78 -7
- data/lib/capybara/dommy/text_extractor.rb +1 -3
- data/lib/capybara/dommy/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc52d93866c788bf33f9ac11fceea40cab43bce8bad33c4e253c33f8c11ec3f8
|
|
4
|
+
data.tar.gz: 89d8a40cc27b5c24782cc6100c2d73d46b236d90f8db819fe3ff945ea36da5a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 935125dffe09162effdfee36f5b8c897c5b7f9b83eb5f9d84cf27049ec455ca4bfe5d6b330ef2c1445c02bb178961e29c89b143133f7264bc445c7c5736c4e05
|
|
7
|
+
data.tar.gz: 506cab775b1c1425fa83488b35754b0ef331aca13cf6e7e01f8fe57524281cdcf1713e5f24527712bb533a521ed1785e4c98177945d75a57ef2ff963d24b72d7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.14.0 — 2026-10-01
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `right_click` and `double_click`, which fire `contextmenu` and `dblclick` after the full pointer and mouse sequence under JavaScript. Without JavaScript `double_click` is a `click`.
|
|
8
|
+
- `shadow_root` returns the element's shadow tree as a node, so `find(...).shadow_root.find(...)` searches inside it.
|
|
9
|
+
- `execute_script` / `evaluate_script` pass their arguments to the script, a Capybara node arriving as its element.
|
|
10
|
+
- A frame with `srcdoc` loads that document, at `about:srcdoc`.
|
|
11
|
+
- `save_screenshot` writes a blank PNG at the path and the page's HTML and visible text next to it, so Rails' failure screenshot no longer raises and hides the real failure.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- `hover` under JavaScript fires `mouseover` and `mouseenter` on the element (and `mouseout` / `mouseleave` on the one it leaves), not only the `:hover` state.
|
|
16
|
+
- `send_keys` without JavaScript applies `:backspace`, `:delete`, `:home` and `:end` at the caret, and `:enter` inserts a newline in a textarea and submits an input's form.
|
|
17
|
+
|
|
18
|
+
## 0.13.0 — 2026-09-23
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `Capybara::Dommy.configuration.raise_js_errors` (default `true`) fails an example on JavaScript the page left unhandled, at the next Capybara command, the way Capybara's own `raise_server_errors` fails one on a server exception. It affects only a `javascript: true` driver.
|
|
23
|
+
- `page.driver.allow_js_errors { ... }` suppresses that failure for a block.
|
|
24
|
+
- README: a "How this differs from a browser driver" section.
|
|
25
|
+
|
|
3
26
|
## 0.12.0 — 2026-09-22
|
|
4
27
|
|
|
5
28
|
Versioned in lockstep with [`dommy`](https://github.com/takahashim/dommy) 0.12.0.
|
data/README.md
CHANGED
|
@@ -46,6 +46,49 @@ By default, `execute_script`, `evaluate_script`, and
|
|
|
46
46
|
turn those calls into no-ops with configuration when migrating tests that call
|
|
47
47
|
JavaScript helpers incidentally.
|
|
48
48
|
|
|
49
|
+
## How this differs from a browser driver
|
|
50
|
+
|
|
51
|
+
Specs written against `capybara-dommy` use the ordinary Capybara DSL, so most
|
|
52
|
+
of them read the same as they would under selenium or cuprite. A few behaviours
|
|
53
|
+
underneath are genuinely different, and they are the ones worth knowing before
|
|
54
|
+
you port a suite.
|
|
55
|
+
|
|
56
|
+
**JavaScript errors fail the example.** A `javascript: true` driver fails on
|
|
57
|
+
anything the page's JavaScript left unhandled, at the next Capybara command, the
|
|
58
|
+
way Capybara's own `raise_server_errors` fails on a server exception. "Unhandled"
|
|
59
|
+
is the page's verdict: an error it cancels in `window.onerror` or in an
|
|
60
|
+
`unhandledrejection` listener never reaches the log, exactly as it never reaches
|
|
61
|
+
a browser console. A real browser driver reports nothing here, so this catches
|
|
62
|
+
breakage those drivers let through — usually a Dommy API the page needs and
|
|
63
|
+
Dommy does not implement yet. Turn it off with
|
|
64
|
+
`config.raise_js_errors = false`, or suppress it for one block with
|
|
65
|
+
`page.driver.allow_js_errors { ... }`.
|
|
66
|
+
|
|
67
|
+
**There are two clocks.** Dommy's timers run on a virtual clock that Capybara's
|
|
68
|
+
retry loop advances a frame at a time, so a debounce or a `setTimeout` resolves
|
|
69
|
+
in a few polls rather than in real time. Nothing advances it outside that loop:
|
|
70
|
+
`sleep` does not, and Rails' `travel_to` does not reach JavaScript's `Date`.
|
|
71
|
+
|
|
72
|
+
**The app runs in the test process.** There is no server thread and no port, so
|
|
73
|
+
`use_transactional_tests` works unchanged and an exception in the app is raised
|
|
74
|
+
directly in the test. In exchange, `Capybara.server` and anything built on a
|
|
75
|
+
separate app thread has no meaning here.
|
|
76
|
+
|
|
77
|
+
**There is no layout.** Visibility comes from HTML-level rules and stylesheet
|
|
78
|
+
`display` / `visibility` / `opacity`, never from geometry, so `obscured?`,
|
|
79
|
+
scroll position and element size are unavailable.
|
|
80
|
+
|
|
81
|
+
**Input is synthesised.** Events are dispatched from Ruby rather than by the OS,
|
|
82
|
+
so `isTrusted` is false and hover, drag and special keys are limited. An
|
|
83
|
+
unanswered `confirm` returns false rather than blocking.
|
|
84
|
+
|
|
85
|
+
**Frames are fetched, not live.** Switching to a frame re-requests its URL; the
|
|
86
|
+
frame's own scripts do not run.
|
|
87
|
+
|
|
88
|
+
**Failure artifacts are different.** `save_screenshot` raises (there is nothing
|
|
89
|
+
to paint). A failing example writes the page HTML and a trace bundle instead,
|
|
90
|
+
which `dommy-rails` wires up automatically.
|
|
91
|
+
|
|
49
92
|
## Installation
|
|
50
93
|
|
|
51
94
|
Add the gem to your application's Gemfile:
|
|
@@ -121,6 +164,7 @@ Capybara::Dommy.configure do |config|
|
|
|
121
164
|
config.max_redirects = 5
|
|
122
165
|
config.visibility = :html
|
|
123
166
|
config.raise_on_unsupported_js = true
|
|
167
|
+
config.raise_js_errors = true
|
|
124
168
|
end
|
|
125
169
|
```
|
|
126
170
|
|
|
@@ -136,6 +180,9 @@ Available options:
|
|
|
136
180
|
visible.
|
|
137
181
|
- `raise_on_unsupported_js`: when `true`, JavaScript methods raise
|
|
138
182
|
`Capybara::NotSupportedByDriverError`; when `false`, they return `nil`.
|
|
183
|
+
- `raise_js_errors`: when `true` (the default), a `javascript: true` driver
|
|
184
|
+
fails the example on JavaScript the page left unhandled. Has no effect on a
|
|
185
|
+
driver that runs no JavaScript. See "How this differs from a browser driver".
|
|
139
186
|
|
|
140
187
|
You can also override driver options per registration:
|
|
141
188
|
|
|
@@ -6,7 +6,7 @@ module Capybara
|
|
|
6
6
|
# when a keyword argument is omitted.
|
|
7
7
|
class Configuration
|
|
8
8
|
attr_accessor :default_host, :follow_redirects, :max_redirects, :visibility,
|
|
9
|
-
:raise_on_unsupported_js, :javascript
|
|
9
|
+
:raise_on_unsupported_js, :javascript, :raise_js_errors
|
|
10
10
|
|
|
11
11
|
def initialize
|
|
12
12
|
@default_host = "http://example.org"
|
|
@@ -15,6 +15,11 @@ module Capybara
|
|
|
15
15
|
@visibility = :html
|
|
16
16
|
@raise_on_unsupported_js = true
|
|
17
17
|
@javascript = false
|
|
18
|
+
# Fail an example on JavaScript the page left unhandled, the way
|
|
19
|
+
# Capybara's own raise_server_errors fails one on a server exception.
|
|
20
|
+
# Only a `javascript: true` driver has any JS to fail on, so this is
|
|
21
|
+
# invisible to a suite migrating from rack_test.
|
|
22
|
+
@raise_js_errors = true
|
|
18
23
|
end
|
|
19
24
|
end
|
|
20
25
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "fileutils"
|
|
4
|
+
|
|
3
5
|
module Capybara
|
|
4
6
|
module Dommy
|
|
5
7
|
# A Capybara driver backed by Dommy::Rack::Session. Implements the
|
|
@@ -11,6 +13,11 @@ module Capybara
|
|
|
11
13
|
class Driver < Capybara::Driver::Base
|
|
12
14
|
VISIBILITY_MODES = %i[all html none].freeze
|
|
13
15
|
|
|
16
|
+
# A 1x1 transparent PNG. There are no pixels to paint, but the path a
|
|
17
|
+
# screenshot is asked to save must still hold a valid image: Rails'
|
|
18
|
+
# screenshot helper reads it back for its inline / artifact output.
|
|
19
|
+
BLANK_PNG = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==".unpack1("m").freeze
|
|
20
|
+
|
|
14
21
|
attr_reader :app, :visibility
|
|
15
22
|
|
|
16
23
|
# --- Deterministic-time seam (used by JS runtimes) ---
|
|
@@ -49,7 +56,15 @@ module Capybara
|
|
|
49
56
|
# hosts (e.g. app_host / multi-server specs), so don't enforce origin.
|
|
50
57
|
enforce_same_origin: false
|
|
51
58
|
}
|
|
52
|
-
|
|
59
|
+
if @javascript
|
|
60
|
+
@session_options[:javascript] = true
|
|
61
|
+
# Everything Capybara does reaches the session through a checkpoint
|
|
62
|
+
# already — a query pumps the clock, a node interaction drains, and
|
|
63
|
+
# reset! disposes — so strictness needs no driver-side checks, just
|
|
64
|
+
# this flag. A JS error then surfaces at the next Capybara command,
|
|
65
|
+
# like a server error under raise_server_errors.
|
|
66
|
+
@session_options[:strict_js_errors] = config.raise_js_errors
|
|
67
|
+
end
|
|
53
68
|
# A JS session needs the virtual clock pumped inside Capybara's
|
|
54
69
|
# synchronize loop, so waiting expectations converge on timer/fetch
|
|
55
70
|
# driven updates. A host-installed pump (the documented seam) wins.
|
|
@@ -69,6 +84,17 @@ module Capybara
|
|
|
69
84
|
nil
|
|
70
85
|
end
|
|
71
86
|
|
|
87
|
+
# Suppress strict-mode failure for JS errors raised inside the block, for
|
|
88
|
+
# a spec that triggers one deliberately. Reaching for `page.driver` is the
|
|
89
|
+
# documented exception to keeping specs driver-agnostic: suppressing an
|
|
90
|
+
# error is inherently driver-specific. A page that handles its own errors
|
|
91
|
+
# (`window.onerror` + preventDefault) needs nothing here.
|
|
92
|
+
def allow_js_errors(&block)
|
|
93
|
+
return yield unless @javascript
|
|
94
|
+
|
|
95
|
+
rack_session.allow_js_errors(&block)
|
|
96
|
+
end
|
|
97
|
+
|
|
72
98
|
# The dommy-rack session. Named `rack_session` to avoid colliding with
|
|
73
99
|
# Capybara::Driver::Base#session (the owning Capybara::Session). Rebuilt
|
|
74
100
|
# when the effective host (Capybara app_host / default_host) changes so
|
|
@@ -138,6 +164,22 @@ module Capybara
|
|
|
138
164
|
rack_session.headers || {}
|
|
139
165
|
end
|
|
140
166
|
|
|
167
|
+
# There is no rendering surface to capture, so a "screenshot" saves the
|
|
168
|
+
# page itself: the serialized HTML and its visible text next to `path`,
|
|
169
|
+
# plus a valid blank image at `path`. Rails' take_failed_screenshot calls
|
|
170
|
+
# this for every failed system test, and letting it raise (the
|
|
171
|
+
# Driver::Base default) would mask the real failure.
|
|
172
|
+
def save_screenshot(path, **_options)
|
|
173
|
+
path = path.to_s
|
|
174
|
+
dir = ::File.dirname(path)
|
|
175
|
+
base = ::File.basename(path, ".*")
|
|
176
|
+
::FileUtils.mkdir_p(dir)
|
|
177
|
+
::File.binwrite(path, BLANK_PNG)
|
|
178
|
+
::File.write(::File.join(dir, "#{base}.html"), html.to_s)
|
|
179
|
+
::File.write(::File.join(dir, "#{base}.txt"), screenshot_text)
|
|
180
|
+
path
|
|
181
|
+
end
|
|
182
|
+
|
|
141
183
|
# --- Query (returns Capybara::Dommy::Node arrays) ---
|
|
142
184
|
|
|
143
185
|
def find_css(query, **_options)
|
|
@@ -229,18 +271,21 @@ module Capybara
|
|
|
229
271
|
# When raise_on_unsupported_js is false these become no-ops, so tests
|
|
230
272
|
# that incidentally call them don't fail.
|
|
231
273
|
|
|
274
|
+
# Arguments become the script's `arguments`; a Capybara node argument
|
|
275
|
+
# crosses as its Dommy element (a JS proxy), so
|
|
276
|
+
# `execute_script("arguments[0].scrollIntoView()", node)` works. A runtime
|
|
277
|
+
# that cannot pass arguments raises (see Session#execute_script), rather
|
|
278
|
+
# than silently dropping them.
|
|
232
279
|
def execute_script(script, *args)
|
|
233
280
|
return unsupported_js!("execute_script") unless @javascript
|
|
234
|
-
raise ArgumentError, "script arguments are not supported" unless args.empty?
|
|
235
281
|
|
|
236
|
-
rack_session.execute_script(script)
|
|
282
|
+
rack_session.execute_script(script, *unwrap_script_args(args))
|
|
237
283
|
end
|
|
238
284
|
|
|
239
285
|
def evaluate_script(script, *args)
|
|
240
286
|
return unsupported_js!("evaluate_script") unless @javascript
|
|
241
|
-
raise ArgumentError, "script arguments are not supported" unless args.empty?
|
|
242
287
|
|
|
243
|
-
rack_session.evaluate_script(script)
|
|
288
|
+
rack_session.evaluate_script(script, *unwrap_script_args(args))
|
|
244
289
|
end
|
|
245
290
|
|
|
246
291
|
def evaluate_async_script(_script, *_args)
|
|
@@ -273,17 +318,32 @@ module Capybara
|
|
|
273
318
|
|
|
274
319
|
private
|
|
275
320
|
|
|
321
|
+
# Advance the virtual clock a slice inside Capybara's retry loop, then
|
|
322
|
+
# report whatever the page's JavaScript left unhandled while it ran.
|
|
323
|
+
#
|
|
324
|
+
# The check belongs here rather than only in the session because a JS
|
|
325
|
+
# runtime may install its own pump (the documented `time_pump` seam), and
|
|
326
|
+
# that pump drives the runtime directly instead of going through
|
|
327
|
+
# `Session#advance_time` — so a timer that throws during a poll would
|
|
328
|
+
# otherwise sit in the ledger until some later command happened to check.
|
|
276
329
|
def pump!
|
|
277
330
|
@time_pump&.call
|
|
331
|
+
rack_session.check_js_errors! if @javascript
|
|
278
332
|
end
|
|
279
333
|
|
|
280
334
|
def frame_stack
|
|
281
335
|
@frame_stack ||= []
|
|
282
336
|
end
|
|
283
337
|
|
|
284
|
-
#
|
|
285
|
-
#
|
|
338
|
+
# A frame's document: its `srcdoc` when present (Dommy builds it from
|
|
339
|
+
# the attribute, so there is nothing to fetch), else its `src` resolved
|
|
340
|
+
# against the enclosing frame's URL so nested relative srcs load
|
|
341
|
+
# correctly.
|
|
286
342
|
def load_frame(iframe_element)
|
|
343
|
+
if (doc = srcdoc_document(iframe_element))
|
|
344
|
+
return {document: doc, url: frame_url}
|
|
345
|
+
end
|
|
346
|
+
|
|
287
347
|
src = iframe_element.get_attribute("src").to_s
|
|
288
348
|
raise Capybara::Dommy::Error, "iframe has no src" if src.empty?
|
|
289
349
|
|
|
@@ -295,6 +355,27 @@ module Capybara
|
|
|
295
355
|
{document: doc, url: url}
|
|
296
356
|
end
|
|
297
357
|
|
|
358
|
+
# The document Dommy already built for a `srcdoc` frame (its URL is
|
|
359
|
+
# about:srcdoc, with the base URL inherited from the enclosing
|
|
360
|
+
# document); nil when the frame has no `srcdoc`.
|
|
361
|
+
def srcdoc_document(iframe_element)
|
|
362
|
+
srcdoc = iframe_element.get_attribute("srcdoc")
|
|
363
|
+
return nil if srcdoc.nil?
|
|
364
|
+
|
|
365
|
+
return iframe_element.content_document if iframe_element.respond_to?(:content_document) && iframe_element.content_document
|
|
366
|
+
|
|
367
|
+
Dommy.parse(srcdoc).document
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
def screenshot_text
|
|
371
|
+
doc = document
|
|
372
|
+
return "" unless doc
|
|
373
|
+
|
|
374
|
+
TextExtractor.new(self).visible_text(doc.body)
|
|
375
|
+
rescue StandardError
|
|
376
|
+
""
|
|
377
|
+
end
|
|
378
|
+
|
|
298
379
|
# Sequential focus navigation: elements with a positive tabindex first
|
|
299
380
|
# (ascending, document order within a value), then the remaining
|
|
300
381
|
# focusables in document order. The page's tab cycle starts over when
|
|
@@ -327,7 +408,7 @@ module Capybara
|
|
|
327
408
|
# standalone driver (no owning Capybara session) still works.
|
|
328
409
|
def effective_host
|
|
329
410
|
options = owning_session_options
|
|
330
|
-
|
|
411
|
+
options&.app_host || options&.default_host || @session_options[:default_host]
|
|
331
412
|
end
|
|
332
413
|
|
|
333
414
|
def owning_session_options
|
|
@@ -340,6 +421,19 @@ module Capybara
|
|
|
340
421
|
(elements || []).map { |element| Node.new(self, element) }
|
|
341
422
|
end
|
|
342
423
|
|
|
424
|
+
# A script argument: a Capybara node becomes the Dommy element it wraps
|
|
425
|
+
# (so it crosses to JS as a proxy), anything else passes through. Arrays
|
|
426
|
+
# are mapped so a list of nodes works too.
|
|
427
|
+
def unwrap_script_args(args)
|
|
428
|
+
args.map do |arg|
|
|
429
|
+
case arg
|
|
430
|
+
when Node then arg.native
|
|
431
|
+
when Array then unwrap_script_args(arg)
|
|
432
|
+
else arg
|
|
433
|
+
end
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
|
|
343
437
|
def unsupported_js!(name)
|
|
344
438
|
return nil unless @raise_on_unsupported_js
|
|
345
439
|
|
data/lib/capybara/dommy/node.rb
CHANGED
|
@@ -70,16 +70,17 @@ module Capybara
|
|
|
70
70
|
# `disabled` only applies to form-associated elements; on anything else
|
|
71
71
|
# (e.g. a link that incorrectly carries the attribute) it has no effect.
|
|
72
72
|
DISABLEABLE_ELEMENTS = %w[button fieldset input optgroup option select textarea].freeze
|
|
73
|
+
OPTION_ELEMENTS = %w[option optgroup].freeze
|
|
73
74
|
|
|
74
75
|
def disabled?
|
|
75
76
|
return false unless DISABLEABLE_ELEMENTS.include?(tag_name)
|
|
76
77
|
return true if native.has_attribute?("disabled")
|
|
77
78
|
|
|
78
|
-
if
|
|
79
|
+
if OPTION_ELEMENTS.include?(tag_name)
|
|
79
80
|
owner = native.xpath(OPTION_OWNER_XPATH).first
|
|
80
81
|
owner ? self.class.new(driver, owner).disabled? : false
|
|
81
82
|
else
|
|
82
|
-
|
|
83
|
+
native.xpath(DISABLED_BY_FIELDSET_XPATH).any?
|
|
83
84
|
end
|
|
84
85
|
end
|
|
85
86
|
|
|
@@ -115,7 +116,7 @@ module Capybara
|
|
|
115
116
|
|
|
116
117
|
return unless native.respond_to?(:value=)
|
|
117
118
|
|
|
118
|
-
state = {chars: native.value.to_s.chars, caret: native.value.to_s.length, shift: false}
|
|
119
|
+
state = {chars: native.value.to_s.chars, caret: native.value.to_s.length, shift: false, submit: false}
|
|
119
120
|
args.each do |arg|
|
|
120
121
|
if arg.is_a?(Array)
|
|
121
122
|
# A chord like [:shift, 'o'] holds its modifiers only for the
|
|
@@ -129,6 +130,9 @@ module Capybara
|
|
|
129
130
|
end
|
|
130
131
|
native.focus if native.respond_to?(:focus)
|
|
131
132
|
native.value = state[:chars].join
|
|
133
|
+
# Enter's default action on an input is its form's implicit submission;
|
|
134
|
+
# a textarea received a newline instead (see #apply_key).
|
|
135
|
+
submit_owning_form if state[:submit]
|
|
132
136
|
end
|
|
133
137
|
|
|
134
138
|
# Computed styles for Capybara's matches_style? / style: filters,
|
|
@@ -157,6 +161,27 @@ module Capybara
|
|
|
157
161
|
end
|
|
158
162
|
end
|
|
159
163
|
|
|
164
|
+
# A secondary-button click. Under JavaScript the full pointer/mouse
|
|
165
|
+
# sequence plus contextmenu runs through the driver; without it, only the
|
|
166
|
+
# virtual :hover state changes (no handlers exist to observe the event).
|
|
167
|
+
def right_click
|
|
168
|
+
if driver.javascript?
|
|
169
|
+
::Dommy::Interaction::EventSynthesis.right_click(native)
|
|
170
|
+
driver.drain_js
|
|
171
|
+
end
|
|
172
|
+
nil
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def double_click
|
|
176
|
+
if driver.javascript?
|
|
177
|
+
::Dommy::Interaction::EventSynthesis.double_click(native)
|
|
178
|
+
driver.drain_js
|
|
179
|
+
else
|
|
180
|
+
click
|
|
181
|
+
end
|
|
182
|
+
nil
|
|
183
|
+
end
|
|
184
|
+
|
|
160
185
|
def set(value, **_options)
|
|
161
186
|
return if disabled? || readonly?
|
|
162
187
|
|
|
@@ -190,15 +215,32 @@ module Capybara
|
|
|
190
215
|
native.selected = false
|
|
191
216
|
end
|
|
192
217
|
|
|
193
|
-
# Move the
|
|
194
|
-
# `matches(":hover")`
|
|
195
|
-
# mouseover/
|
|
196
|
-
#
|
|
218
|
+
# Move the pointer over this element: the virtual :hover state moves (so
|
|
219
|
+
# :hover rules and `matches(":hover")` apply to it and its ancestors), and
|
|
220
|
+
# under JavaScript the mouseover/mouseenter sequence is dispatched so
|
|
221
|
+
# Stimulus/framework hover handlers run. The previously hovered element
|
|
222
|
+
# (if any) is left first, so its mouseout/mouseleave fire.
|
|
197
223
|
def hover
|
|
224
|
+
previous = previous_hovered
|
|
225
|
+
if driver.javascript?
|
|
226
|
+
::Dommy::Interaction::EventSynthesis.unhover(previous, to: native) if previous && !previous.equal?(native)
|
|
227
|
+
::Dommy::Interaction::EventSynthesis.hover(native, from: previous)
|
|
228
|
+
end
|
|
198
229
|
native.owner_document.__internal_set_hovered_element__(native)
|
|
230
|
+
driver.drain_js if driver.javascript?
|
|
199
231
|
nil
|
|
200
232
|
end
|
|
201
233
|
|
|
234
|
+
# The shadow root this element hosts (`attachShadow`), as a Capybara node
|
|
235
|
+
# scoped to that tree — Capybara's `shadow_root`/`within` support. nil
|
|
236
|
+
# when the element has no shadow root.
|
|
237
|
+
def shadow_root
|
|
238
|
+
return nil unless native.respond_to?(:shadow_root)
|
|
239
|
+
|
|
240
|
+
root = native.shadow_root
|
|
241
|
+
root && self.class.new(driver, root)
|
|
242
|
+
end
|
|
243
|
+
|
|
202
244
|
# --- Scoped queries (for `within`) ---
|
|
203
245
|
|
|
204
246
|
def find_css(locator, **_options)
|
|
@@ -233,6 +275,15 @@ module Capybara
|
|
|
233
275
|
|
|
234
276
|
private
|
|
235
277
|
|
|
278
|
+
# The element currently hovering, if any (nil when the pointer is off
|
|
279
|
+
# any element). Used to fire its mouseleave before a new hover.
|
|
280
|
+
def previous_hovered
|
|
281
|
+
doc = native.owner_document
|
|
282
|
+
return nil unless doc.respond_to?(:__internal_hovered_element__)
|
|
283
|
+
|
|
284
|
+
doc.__internal_hovered_element__
|
|
285
|
+
end
|
|
286
|
+
|
|
236
287
|
def apply_key(state, key)
|
|
237
288
|
case key
|
|
238
289
|
when String
|
|
@@ -243,10 +294,30 @@ module Capybara
|
|
|
243
294
|
when :space
|
|
244
295
|
state[:chars].insert(state[:caret], " ")
|
|
245
296
|
state[:caret] += 1
|
|
297
|
+
when :backspace
|
|
298
|
+
return if state[:caret].zero?
|
|
299
|
+
|
|
300
|
+
state[:chars].delete_at(state[:caret] - 1)
|
|
301
|
+
state[:caret] -= 1
|
|
302
|
+
when :delete
|
|
303
|
+
state[:chars].delete_at(state[:caret]) if state[:caret] < state[:chars].length
|
|
246
304
|
when :left
|
|
247
305
|
state[:caret] = [state[:caret] - 1, 0].max
|
|
248
306
|
when :right
|
|
249
307
|
state[:caret] = [state[:caret] + 1, state[:chars].length].min
|
|
308
|
+
when :home
|
|
309
|
+
state[:caret] = 0
|
|
310
|
+
when :end
|
|
311
|
+
state[:caret] = state[:chars].length
|
|
312
|
+
when :enter
|
|
313
|
+
# Newline in a textarea; elsewhere (an input) the form's implicit
|
|
314
|
+
# submission runs once the value is committed.
|
|
315
|
+
if textarea?
|
|
316
|
+
state[:chars].insert(state[:caret], "\n")
|
|
317
|
+
state[:caret] += 1
|
|
318
|
+
elsif input_field?
|
|
319
|
+
state[:submit] = true
|
|
320
|
+
end
|
|
250
321
|
when :shift
|
|
251
322
|
state[:shift] = true
|
|
252
323
|
end
|
|
@@ -32,7 +32,7 @@ module Capybara
|
|
|
32
32
|
private
|
|
33
33
|
|
|
34
34
|
def displayed_text(element)
|
|
35
|
-
element.child_nodes.
|
|
35
|
+
element.child_nodes.filter_map do |child|
|
|
36
36
|
if text_node?(child)
|
|
37
37
|
# Whitespace inside a text node (incl. newlines) collapses to
|
|
38
38
|
# spaces; only block boundaries introduce line breaks.
|
|
@@ -42,8 +42,6 @@ module Capybara
|
|
|
42
42
|
|
|
43
43
|
inner = displayed_text(child)
|
|
44
44
|
block_element?(child) ? "\n#{inner}\n" : inner
|
|
45
|
-
else
|
|
46
|
-
""
|
|
47
45
|
end
|
|
48
46
|
end.join
|
|
49
47
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capybara-dommy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- takahashim
|
|
@@ -29,28 +29,28 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.
|
|
32
|
+
version: 0.14.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.
|
|
39
|
+
version: 0.14.0
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: dommy-rack
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
44
|
- - "~>"
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 0.
|
|
46
|
+
version: 0.14.0
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 0.
|
|
53
|
+
version: 0.14.0
|
|
54
54
|
description: |
|
|
55
55
|
capybara-dommy is a Capybara driver backed by Dommy and dommy-rack. It drives
|
|
56
56
|
Rack/Rails apps through the Capybara DSL without a real browser or JavaScript,
|
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
97
|
requirements: []
|
|
98
|
-
rubygems_version:
|
|
98
|
+
rubygems_version: 4.0.20
|
|
99
99
|
specification_version: 4
|
|
100
100
|
summary: A Dommy-backed Capybara driver
|
|
101
101
|
test_files: []
|