Stateful scenarios¶
Stateful, keyless browser scenarios with portable checkpoint evidence.
- class layoutlens.scenarios.Scenario(source, *, base_url=None, steps=())[source]¶
A sequence whose chained methods return new scenarios.
Navigate in the existing browser context, retaining cookies and storage.
- checkpoint(name)[source]¶
Capture the current rendered state without resetting focus or media settings.
- expect_focus(target)[source]¶
Require the named element to receive focus, including inside open shadow DOM.
Require a target to become hidden or detached, for example after dismissal.
- expect_text(target, text)[source]¶
Require the target’s rendered text to match an explicit content contract.
- expect_count(target, count)[source]¶
Require a locator count, for example one modal instead of stacked dialogs.
- expect_style(target, property_name, value)[source]¶
Require a computed CSS property, such as the expected focus-ring outline.
- expect_clickable(target)[source]¶
Require Playwright’s click actionability checks to pass without clicking.
- expect_tab_reaches(target, *, max_tabs=20)[source]¶
Require a target to be reachable within a bounded forward keyboard sequence.
- classmethod from_dict(data, *, base_url=None)[source]¶
Load a declarative scenario; arbitrary script execution is unsupported.
Portable interaction receipts and checkpoint artifacts.
- class layoutlens.scenarios.models.Step(*, action, target=None, value=None)[source]¶
One declarative browser action or explicit expectation.
- Parameters:
action (Literal['tab', 'press', 'type', 'fill', 'click', 'hover', 'drag', 'navigate', 'resize', 'pointer_move', 'pointer_down', 'pointer_up', 'checkpoint', 'expect_focus', 'expect_visible', 'expect_hidden', 'expect_url', 'expect_text', 'expect_count', 'expect_style', 'expect_clickable', 'expect_tab_reaches'])
target (str | None)
value (Any)
- validate_arguments()[source]¶
Reject malformed declarative steps before any browser action runs.
- Return type:
- model_config = {'allow_inf_nan': False, 'extra': 'forbid', 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class layoutlens.scenarios.models.Event(*, sequence, step, time_ms, kind, url, detail=<factory>)[source]¶
An observed event, with run-relative time and the active step index.
- model_config = {'allow_inf_nan': False, 'extra': 'forbid', 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class layoutlens.scenarios.models.StepResult(*, index, action, target=None, status='pass', before=<factory>, after=<factory>, evidence=<factory>, error=None)[source]¶
Action outcome, focus transition, and measured expectation evidence.
- Parameters:
- model_config = {'allow_inf_nan': False, 'extra': 'forbid', 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class layoutlens.scenarios.models.InteractionFinding(*, step, defect_class, element, evidence, exceptions=<factory>, level='candidate')[source]¶
A reproducible observation matching a reviewable interaction predicate.
- Parameters:
- model_config = {'allow_inf_nan': False, 'extra': 'forbid', 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class layoutlens.scenarios.models.ScenarioReport(*, schema_version=1, source, policy='qualified', definition_fingerprint, planned_steps, steps=<factory>, events=<factory>, findings=<factory>, checkpoints=<factory>, incomplete_reasons=<factory>)[source]¶
A complete or interrupted run, retaining its ordered evidence.
- Parameters:
schema_version (Literal[1])
source (str)
policy (GatePolicy)
definition_fingerprint (str)
planned_steps (int)
steps (list[StepResult])
findings (list[InteractionFinding])
checkpoints (dict[str, RenderState])
- property gate_status: Literal['pass', 'fail', 'incomplete']¶
Keep execution gaps distinct from failed, explicitly requested contracts.
- to_json()[source]¶
Serialize receipts and checkpoint metadata, excluding screenshot bytes.
- Return type:
- classmethod load(path)[source]¶
Load saved receipts and reject corrupt or escaping checkpoint references.
- Parameters:
- Return type:
- diff(after, **options)[source]¶
Compare corresponding named checkpoints across two scenario runs.
- Parameters:
after (ScenarioReport)
options (Any)
- Return type:
- model_config = {'allow_inf_nan': False, 'extra': 'forbid', 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class layoutlens.scenarios.models.ScenarioDiff(*, checkpoints, transitions=<factory>, failed_expectations=<factory>, incomplete_reasons=<factory>)[source]¶
Checkpoint regressions and changed observed focus transitions.
- Parameters:
- property gate_status: Literal['pass', 'fail', 'incomplete']¶
Require comparable complete checkpoints before reporting a passing gate.
- model_config = {'allow_inf_nan': False, 'extra': 'forbid', 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].