ddp_utils.browser.facade.dialogs

import ddp_utils.browser.facade.dialogs

Backend-neutral JavaScript dialog service.

class ddp_utils.browser.facade.dialogs.BrowserDialog(kind: str, message: str, default_value: str, accepted: bool, prompt_text: str | None = None)

Bases: object

Describe one handled JavaScript dialog.

Parameters

Name

Type

Description

kind

str

Dialog kind such as alert, confirm, or prompt.

message

str

Visible dialog message.

default_value

str

Provider-reported prompt default value.

accepted

bool

Whether the facade accepted the dialog.

prompt_text

str | None

Text submitted to a prompt.

Examples

Assert that a confirmation was accepted:

result = browser.dialogs.handle(trigger, accept=True)
assert result.accepted
class ddp_utils.browser.facade.dialogs.BrowserDialogs(browser: Browser)

Bases: object

Handle JavaScript dialogs around the action that creates them.

Parameters

Name

Type

Description

browser

Browser

Owning browser facade.

Examples

Dismiss a confirmation without provider-specific listeners:

result = browser.dialogs.handle(delete_button.click, accept=False)

Bind dialog handling to one browser session.

Parameters

Name

Type

Description

browser

Browser

Owning browser facade.

Examples

Browser creates this service once:

dialogs = BrowserDialogs(browser)
property current: BrowserDialog | None

Return the currently open dialog without handling it.

Returns

Current dialog descriptor or None.

Examples

dialog = browser.dialogs.current.

wait(*, kind: str | None = None, text: str | None = None, timeout: float) → BrowserDialog

Wait for a matching open dialog.

Parameters

Name

Type

Description

kind

str | None

Optional dialog kind.

text

str | None

Optional message fragment.

timeout

float

Deadline in seconds.

Returns

Type

Description

BrowserDialog

Matching dialog descriptor.

Examples

dialog = browser.dialogs.wait(kind="confirm", timeout=10).

accept(*, prompt_text: str | None = None) → None

Accept the current dialog.

Parameters

Name

Type

Description

prompt_text

str | None

Optional prompt response.

Raises

Exception

Description

WaitTimeoutError

No dialog is open.

Examples

browser.dialogs.accept(prompt_text="Fulton").

dismiss() → None

Dismiss the current dialog.

Raises

Exception

Description

WaitTimeoutError

No dialog is open.

Examples

browser.dialogs.dismiss().

on(callback: Callable[[BrowserDialog], Any], *, auto: str = 'none') → BrowserSubscription

Subscribe to dialog observations.

Parameters

Name

Type

Description

callback

Callable[[BrowserDialog], Any]

Dialog callback.

auto

str

none, accept, or dismiss.

Returns

Type

Description

BrowserSubscription

Removable subscription.

Raises

Exception

Description

ValueError

If auto is not "none", "accept" or "dismiss".

Examples

sub = browser.dialogs.on(log_dialog, auto="dismiss").

off(subscription: BrowserSubscription) → None

Remove a dialog subscription.

Parameters

Name

Type

Description

subscription

BrowserSubscription

Subscription returned by on().

Examples

browser.dialogs.off(sub).

handle(trigger: Callable[[], Any], *, accept: bool = True, prompt_text: str | None = None, timeout: float | None = None) → BrowserDialog

Run an action, wait for its dialog, and accept or dismiss it.

Parameters

Name

Type

Description

trigger

Callable[[], Any]

Zero-argument action expected to create a dialog.

accept

bool

Accept when true; dismiss when false.

prompt_text

str | None

Optional text submitted before accepting a prompt.

timeout

float | None

Wait budget in seconds. The configured condition timeout is used when omitted.

Returns

Type

Description

BrowserDialog

Immutable handled-dialog description.

Raises

Exception

Description

WaitTimeoutError

No dialog appears before the deadline.

UnsupportedCapabilityError

Dialog handling is unavailable.

Examples

Submit a prompt value:

dialog = browser.dialogs.handle(
    open_prompt, accept=True, prompt_text="Fulton"
)