Skip to content

toast

django_spire.testing.playwright.components.toast

Toast

Playwright component for django_spire/messages/messages.html

Source code in django_spire/testing/playwright/components/toast.py
def __init__(self, page: Page) -> None:
    self.page = page

page = page instance-attribute

container property

toasts property

get_toast

Source code in django_spire/testing/playwright/components/toast.py
def get_toast(self, index: int = 0) -> Locator:
    return self.toasts.nth(index)

get_toast_count

Source code in django_spire/testing/playwright/components/toast.py
def get_toast_count(self) -> int:
    return self.toasts.count()

get_toast_icon

Source code in django_spire/testing/playwright/components/toast.py
def get_toast_icon(self, index: int = 0) -> Locator:
    return self.get_toast(index).locator('i.bi').first

get_toast_message

Source code in django_spire/testing/playwright/components/toast.py
def get_toast_message(self, index: int = 0) -> str:
    return self.get_toast(index).locator('[x-text="notification.message"]').inner_text()

get_toast_type

Source code in django_spire/testing/playwright/components/toast.py
def get_toast_type(self, index: int = 0) -> str:
    toast = self.get_toast(index)
    classes = toast.get_attribute('class') or ''

    if 'border-app-success' in classes:
        return 'success'

    if 'border-app-warning' in classes:
        return 'warning'

    if 'border-app-danger' in classes:
        return 'error'

    if 'border-app-primary' in classes:
        return 'info'

    return 'unknown'

close_toast

Source code in django_spire/testing/playwright/components/toast.py
def close_toast(self, index: int = 0) -> None:
    self.get_toast(index).locator('.bi-x-lg').click()

has_success_toast

Source code in django_spire/testing/playwright/components/toast.py
def has_success_toast(self) -> bool:
    return self.page.locator('.border-app-success').count() > 0

has_warning_toast

Source code in django_spire/testing/playwright/components/toast.py
def has_warning_toast(self) -> bool:
    return self.page.locator('.border-app-warning').count() > 0

has_error_toast

Source code in django_spire/testing/playwright/components/toast.py
def has_error_toast(self) -> bool:
    return self.page.locator('.border-app-danger').count() > 0

has_info_toast

Source code in django_spire/testing/playwright/components/toast.py
def has_info_toast(self) -> bool:
    return self.page.locator('.border-app-primary').count() > 0

wait_for_toast

Source code in django_spire/testing/playwright/components/toast.py
def wait_for_toast(self, timeout: int = 5000) -> None:
    self.toasts.first.wait_for(state='visible', timeout=timeout)

wait_for_toast_to_disappear

Source code in django_spire/testing/playwright/components/toast.py
def wait_for_toast_to_disappear(self, timeout: int = 10000) -> None:
    self.toasts.first.wait_for(state='hidden', timeout=timeout)