pub enum EffectExpectation {
SelectorAppears {
selector: String,
timeout_ms: u64,
},
SelectorDisappears {
selector: String,
timeout_ms: u64,
},
SelectorTextContains {
selector: String,
substring: String,
timeout_ms: u64,
},
DomChanged {
timeout_ms: u64,
},
}Expand description
What the runtime should observe after an action lands to confirm the side-effect actually materialised.
Cortex polls the page (via CDP Runtime.evaluate) until the
expectation holds or the timeout fires. The result is reported back
in the action’s ActionResult so the planner sees not just
“dispatched ok” but “dispatched ok AND observed the expected change”.
Closes the “click reported ok but page didn’t react” gap:
e.preventDefault() from a validation handler, a remounted DOM node
the click landed on but is no longer wired up, an animation that
swallowed the click — all previously reported ok and forced the
planner to verify state from screenshots after the fact. With
expect_after the runtime knows immediately the side-effect didn’t
materialise and surfaces an EffectMissing error to the planner.
All variants carry a timeout_ms with a sensible default
(2_000 ms) — long enough for animations / debounced handlers, short
enough not to add real latency on the happy path (most expectations
resolve in one CDP round-trip when the action actually fired).
Variants§
SelectorAppears
A new element matching selector becomes visible
(offsetParent !== null). Use for “after submit, success
message appears”, “after open, modal appears” patterns.
SelectorDisappears
An element matching selector becomes invisible (detached or
offsetParent === null). Use for “after close, modal disappears”,
“after delete, row goes away” patterns.
SelectorTextContains
An element matching selector contains the given text. Use for
state changes like “button label flips from ‘Approve’ to
‘Approved ✓’”, or “row gains an ‘Approved’ status cell”.
DomChanged
The page DOM changed in any meaningful way after the action. Compares a “before” snapshot (captured at dispatch entry) to a “after” snapshot polled until either differs or the timeout fires. The snapshot is small + cheap: visible text length, interactive element count, and current URL.
Use when the post-state isn’t a single named selector but you know the action SHOULD cause SOME visible change — e.g.: • a delete button that removes a row (count decreases), • a tab switch that swaps the entire content panel, • a submit that navigates to a thank-you page (URL changes), • a “load more” that appends results (text length grows).
Strictly weaker than SelectorAppears/Disappears/TextContains
— those tell you EXACTLY what should change, this just tells
you SOMETHING did. Use the selector-based variants when you
have a verbatim selector="..." from perception; fall back
to DomChanged when you don’t.
False-positive risk: pages with timestamp tickers / animated counters / live data feeds produce diffs every tick. The 2s default timeout is short enough that most non-action-triggered changes don’t have time to land — but if you’re on a chatty page, prefer a selector-based variant if you can name one.
Trait Implementations§
Source§impl Clone for EffectExpectation
impl Clone for EffectExpectation
Source§fn clone(&self) -> EffectExpectation
fn clone(&self) -> EffectExpectation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EffectExpectation
impl Debug for EffectExpectation
Source§impl<'de> Deserialize<'de> for EffectExpectation
impl<'de> Deserialize<'de> for EffectExpectation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for EffectExpectation
Source§impl PartialEq for EffectExpectation
impl PartialEq for EffectExpectation
Source§fn eq(&self, other: &EffectExpectation) -> bool
fn eq(&self, other: &EffectExpectation) -> bool
self and other values to be equal, and is used by ==.