Skip to main content

seleniumbase-rs-plugin-testing has recording fakes of PageHandle and BrowserHandle: they write down every command, script and expression a plugin sends, so a test checks what a hook did, without a browser. It is in the plugins repository, crates/seleniumbase-rs-plugin-testing/src/lib.rs, and depends only on the API crate. To run the real launch steps of seleniumbase-rs against a scripted browser instead, see the Mock browser tab of Test it without a browser.

Depend on it#

Cargo.toml

Take it at the same rev as seleniumbase-rs-plugin, so both name one copy of the API crate.

Call#

enum seleniumbase_rs_plugin_testing::Call

One thing a plugin asked a fake handle to do. Compare calls() with a list of them.

Callenum#

RecordingPage#

struct seleniumbase_rs_plugin_testing::RecordingPage

A fake tab that records what a plugin asks of it. Every method of PageHandle records its call first, then answers:

MethodRecordsAnswers
engine()nothingthe engine it was made with
send(method, params)Call::Send(method, params)the reply set for method, or null
add_init_script(source)Call::InitScript(source)Ok(())
evaluate(expression)Call::Evaluate(expression)the reply set for "evaluate", or null

A method made to fail with failing answers PluginError::Other("METHOD failed (fake)") instead, after recording.

RecordingPage::new#

fn
returnRecordingPage#

A fake tab of the pure CDP engine (Engine::Cdp); also RecordingPage::default().

RecordingPage::on#

fn
engineEnginerequired#

The engine engine() reports, such as Engine::WebDriver.

returnRecordingPage#

A fake tab of engine.

RecordingPage::failing#

fn
method&strrequired#

A DevTools method name for send, or "add_init_script" or "evaluate".

returnRecordingPage#

The fake, with method answering PluginError::Other("METHOD failed (fake)"). One method fails at a time: a second call replaces the first.

RecordingPage::replying#

fn
method&strrequired#

A DevTools method name for send, or "evaluate".

replyserde_json::Valuerequired#

What it answers. Each method has its own reply; a later one replaces an earlier one.

returnRecordingPage#

The fake, with method answering reply (otherwise null).

RecordingPage::calls#

fn
returnVec<Call>#

Everything the plugins asked for, in order: a copy, so the fake keeps recording.

RecordingBrowser#

struct seleniumbase_rs_plugin_testing::RecordingBrowser

A fake browser that records what a plugin asks of it. engine() and family() report what it was made with; send(method, params) records Call::Send(method, params) and answers null. It has no failing or replying.

RecordingBrowser::new#

fn
returnRecordingBrowser#

A fake Chromium browser on the pure CDP engine; also RecordingBrowser::default().

RecordingBrowser::of#

fn
engineEnginerequired#

The engine it reports.

familyBrowserFamilyrequired#

The family it reports, such as BrowserFamily::Firefox.

returnRecordingBrowser#

A fake browser of family on engine.

RecordingBrowser::calls#

fn
returnVec<Call>#

Everything the plugins asked for, in order.

block_on#

fn seleniumbase_rs_plugin_testing::block_on

futureimpl Futurerequired#

A future to run, such as set.on_page_created(&page).

returnF::Output#

Its output.

Runs a future to completion on the current thread, for tests and examples that do not want a runtime: it polls with a no-op waker and yields the thread between polls. The fakes never wait, so nothing else is needed. It drives no I/O and no timers: a future that needs a runtime’s reactor, such as tokio’s, does not complete under it. Test those against the mock browser of seleniumbase-rs with #[tokio::test].