Skip to content

attribute_element

django_spire.testing.playwright.components.attribute_element

AttributeElement

Playwright component for django_spire/element/attribute_element.html

Source code in django_spire/testing/playwright/components/attribute_element.py
def __init__(self, page: Page, container_selector: str = 'body') -> None:
    self.container_selector = container_selector
    self.page = page

container_selector = container_selector instance-attribute

page = page instance-attribute

container property

get_attribute_by_title

Source code in django_spire/testing/playwright/components/attribute_element.py
def get_attribute_by_title(self, title: str) -> Locator:
    return self.container.locator(f'.fs-7.text-app-attribute-color:has-text("{title}")').locator('..')

get_value_by_title

Source code in django_spire/testing/playwright/components/attribute_element.py
def get_value_by_title(self, title: str) -> str:
    attribute = self.get_attribute_by_title(title)
    return attribute.locator('.fs-6, a').inner_text()

get_value_href_by_title

Source code in django_spire/testing/playwright/components/attribute_element.py
def get_value_href_by_title(self, title: str) -> str | None:
    attribute = self.get_attribute_by_title(title)
    link = attribute.locator('a')

    if link.count() > 0:
        return link.get_attribute('href')

    return None

has_attribute

Source code in django_spire/testing/playwright/components/attribute_element.py
def has_attribute(self, title: str) -> bool:
    return self.get_attribute_by_title(title).count() > 0
Source code in django_spire/testing/playwright/components/attribute_element.py
def is_value_link(self, title: str) -> bool:
    attribute = self.get_attribute_by_title(title)
    return attribute.locator('a').count() > 0

AttributeList

Helper for pages with multiple attribute elements

Source code in django_spire/testing/playwright/components/attribute_element.py
def __init__(self, page: Page, container_selector: str = 'body') -> None:
    self.container_selector = container_selector
    self.page = page

container_selector = container_selector instance-attribute

page = page instance-attribute

container property

attributes property

get_all_titles

Source code in django_spire/testing/playwright/components/attribute_element.py
def get_all_titles(self) -> list[str]:
    count = self.attributes.count()
    return [self.attributes.nth(i).inner_text() for i in range(count)]

get_attribute_count

Source code in django_spire/testing/playwright/components/attribute_element.py
def get_attribute_count(self) -> int:
    return self.attributes.count()

get_values_dict

Source code in django_spire/testing/playwright/components/attribute_element.py
def get_values_dict(self) -> dict[str, str]:
    result = {}
    attr_element = AttributeElement(self.page, self.container_selector)

    for title in self.get_all_titles():
        result[title] = attr_element.get_value_by_title(title)

    return result