Module: Browserctl::Driver::PageDriver
- Included in:
- FerrumPageDriver
- Defined in:
- lib/browserctl/driver/page_driver.rb
Overview
PageDriver is the interface every handler in ‘lib/browserctl/server/handlers/` talks to instead of touching a raw Ferrum page. It exists so unit tests can swap in a `FakePageDriver` (see `spec/support/fake_page_driver.rb`) without spawning a real browser.
This module is intentionally a thin contract: Ruby has no real interfaces, so the implementation is duck-typed. The method list below is the entire public surface handlers may use. New entries here require a corresponding implementation in FerrumPageDriver and the test double, plus a handler that justifies them — do not add methods speculatively.
Element-returning methods (currently only #at_css) return whatever the underlying driver returns. The fake driver returns stub objects with matching duck-typed methods (‘focus`, `type`, `click`, `evaluate`, `select_file`). Handlers should treat these as opaque element handles.
PageDriver lives in the Extension zone of the public surface (see ‘docs/reference/api-stability.md`). It is a testing seam, not an invitation to ship a non-Ferrum backend — that path is explicitly a non-goal of v0.15 (`docs/plans/v0.15-lock.md`).
Instance Method Summary collapse
-
#activate ⇒ Object
Bring the page tab to the foreground (headed mode only).
-
#at_css(selector) ⇒ Object?
Find the first element matching the CSS selector.
-
#body ⇒ String
The current page body HTML.
-
#close ⇒ Object
Close the underlying page/tab.
-
#cookies_all ⇒ Hash{String => Object}
All cookies for the page, keyed by cookie name, with each value responding to ‘to_h`.
-
#cookies_clear ⇒ Object
Clear every cookie on the page.
-
#cookies_set ⇒ Object
Set a cookie.
-
#current_url ⇒ String
The current top-frame URL.
-
#evaluate(expression) ⇒ Object
Evaluate a JS expression in the page context.
-
#go_to(url) ⇒ Object
Navigate the page to the given URL.
-
#keyboard_down(key) ⇒ Object
Press a key down.
-
#keyboard_up(key) ⇒ Object
Release a key.
-
#mouse_move(x:, y:) ⇒ Object
Move the mouse pointer to viewport coordinates.
-
#off(event, id) ⇒ Object
Remove a subscription created by #on.
-
#on(event) ⇒ Object
Subscribe to a page event (currently only ‘:dialog`).
-
#screenshot(path:, full: false) ⇒ Object
Capture a screenshot to disk.
-
#target_id ⇒ Object
Underlying CDP target id; used by the devtools handler.
Instance Method Details
#activate ⇒ Object
Bring the page tab to the foreground (headed mode only).
53 |
# File 'lib/browserctl/driver/page_driver.rb', line 53 def activate = raise NotImplementedError |
#at_css(selector) ⇒ Object?
Find the first element matching the CSS selector.
45 |
# File 'lib/browserctl/driver/page_driver.rb', line 45 def at_css(selector) = raise NotImplementedError |
#body ⇒ String
Returns the current page body HTML.
34 |
# File 'lib/browserctl/driver/page_driver.rb', line 34 def body = raise NotImplementedError |
#close ⇒ Object
Close the underlying page/tab.
56 |
# File 'lib/browserctl/driver/page_driver.rb', line 56 def close = raise NotImplementedError |
#cookies_all ⇒ Hash{String => Object}
Returns all cookies for the page, keyed by cookie name, with each value responding to ‘to_h`.
76 |
# File 'lib/browserctl/driver/page_driver.rb', line 76 def = raise NotImplementedError |
#cookies_clear ⇒ Object
Clear every cookie on the page.
83 |
# File 'lib/browserctl/driver/page_driver.rb', line 83 def = raise NotImplementedError |
#cookies_set ⇒ Object
Set a cookie. Accepts ‘name:`, `value:`, `domain:`, `path:`, and any of `httponly:`, `secure:`, `expires:`.
80 |
# File 'lib/browserctl/driver/page_driver.rb', line 80 def (**) = raise NotImplementedError |
#current_url ⇒ String
Returns the current top-frame URL.
31 |
# File 'lib/browserctl/driver/page_driver.rb', line 31 def current_url = raise NotImplementedError |
#evaluate(expression) ⇒ Object
Evaluate a JS expression in the page context.
39 |
# File 'lib/browserctl/driver/page_driver.rb', line 39 def evaluate(expression) = raise NotImplementedError |
#go_to(url) ⇒ Object
Navigate the page to the given URL. Blocks until load completes.
28 |
# File 'lib/browserctl/driver/page_driver.rb', line 28 def go_to(url) = raise NotImplementedError |
#keyboard_down(key) ⇒ Object
Press a key down. Pair with #keyboard_up.
66 |
# File 'lib/browserctl/driver/page_driver.rb', line 66 def keyboard_down(key) = raise NotImplementedError |
#keyboard_up(key) ⇒ Object
Release a key.
69 |
# File 'lib/browserctl/driver/page_driver.rb', line 69 def keyboard_up(key) = raise NotImplementedError |
#mouse_move(x:, y:) ⇒ Object
Move the mouse pointer to viewport coordinates.
72 |
# File 'lib/browserctl/driver/page_driver.rb', line 72 def mouse_move(x:, y:) = raise NotImplementedError # rubocop:disable Naming/MethodParameterName |
#off(event, id) ⇒ Object
Remove a subscription created by #on.
63 |
# File 'lib/browserctl/driver/page_driver.rb', line 63 def off(event, id) = raise NotImplementedError |
#on(event) ⇒ Object
Subscribe to a page event (currently only ‘:dialog`).
60 |
# File 'lib/browserctl/driver/page_driver.rb', line 60 def on(event, &) = raise NotImplementedError |
#screenshot(path:, full: false) ⇒ Object
Capture a screenshot to disk.
50 |
# File 'lib/browserctl/driver/page_driver.rb', line 50 def screenshot(path:, full: false) = raise NotImplementedError |
#target_id ⇒ Object
Underlying CDP target id; used by the devtools handler. Backends that do not expose CDP should raise.
87 |
# File 'lib/browserctl/driver/page_driver.rb', line 87 def target_id = raise NotImplementedError |