Skip to content

limelight.components.confirm

Confirm

A driver for the inline prompt that stands between an action and its effect.

This class clicks the button that carries the action through, and waits for the button to appear before drawing anything over it. The search considers only visible buttons, because a page that renders one prompt per row keeps each unopened prompt in the markup.

The click is left unbarriered on purpose. A prompt sits in front of anything from a form post to a background write, so the caller wraps the accept in the barrier that proves its own effect landed.

trigger_until_response(
    page,
    lambda: Confirm(demo).accept('Delete'),
    method=HTTPMethod.POST,
)

The constructor for the Confirm class.

Parameters:

  • demo (Demo) –

    The demo driving the browser.

  • root (Locator | None, default: None ) –

    The region holding the prompt, or None for the whole page.

Source code in limelight/components/confirm.py
def __init__(self, demo: Demo, root: Locator | None = None) -> None:
    """
    The constructor for the Confirm class.

    :param demo: The demo driving the browser.
    :param root: The region holding the prompt, or None for the whole page.
    """

    self.demo = demo
    self.root = root

button_selector = 'button' class-attribute instance-attribute

demo = demo instance-attribute

root = root instance-attribute

accept

A method that carries the action through.

Parameters:

  • text (str, default: '' ) –

    The text on the button, or an empty string for the only one.

  • label (str, default: '' ) –

    The spotlight caption, defaulting to the button text.

Raises:

  • AssertionError –

    If the button never appears.

Source code in limelight/components/confirm.py
def accept(self, text: str = '', *, label: str = '') -> None:
    """
    A method that carries the action through.

    :param text: The text on the button, or an empty string for the only one.
    :param label: The spotlight caption, defaulting to the button text.
    :raises AssertionError: If the button never appears.
    """

    button = self.button(text)

    expect(button).to_be_visible(timeout=ELEMENT_WAIT_TIMEOUT_MS)

    caption = label or text

    if caption:
        self.demo.spotlight(button, label=caption)

    self.demo.click(button)

button

A method that gets the button that carries the action through.

Parameters:

  • text (str, default: '' ) –

    The text on the button, or an empty string for the only one.

Returns:

  • Locator –

    The locator for the button.

Source code in limelight/components/confirm.py
def button(self, text: str = '') -> Locator:
    """
    A method that gets the button that carries the action through.

    :param text: The text on the button, or an empty string for the only one.
    :return: The locator for the button.
    """

    scope = self.root if self.root is not None else self.demo.page
    buttons = scope.locator(self.button_selector).filter(visible=True)

    if text:
        buttons = buttons.filter(has_text=text)

    return buttons.first