Source code for cfme.web_ui.listaccordion

"""A set of functions for dealing with accordions in the UI.

Usage:

    Using Accordions is simply a case of either selecting it to return the element,
    or using the built in click method. As shown below::

      acc = web_ui.accordion

      acc.click('Diagnostics')
      acc.is_active('Diagnostics')

Note:
    Inactive links are not available in any way.
"""
from xml.sax.saxutils import quoteattr


import cfme.fixtures.pytest_selenium as sel
from cfme.exceptions import ListAccordionLinkNotFound
from cfme.utils.pretty import Pretty

LOCATOR = "|".join([
    # The older one
    '//div[contains(@class, "dhx_acc_item") or @class="topbar"]'
    '/*[contains(@data-remote, "true") and normalize-space(.)={accname}]',
    # The newer one
    "//div[contains(@class, 'panel-group')]/div[contains(@class, 'panel-')]/div/h4"
    "/a[@data-toggle and normalize-space(.)={accname}]"
])


[docs]def locate(name): """ Returns a list-accordion by name Args: name: The name of the accordion. Returns: An xpath locator of the selected accordion. """ return LOCATOR.format(accname=quoteattr(name))
[docs]def click(name): """ Clicks an accordion and returns it Args: name: The name of the accordion. """ xpath = locate(name) el = sel.element(xpath) was_active = is_active(name) sel.click(el) if not was_active: # sel.wait_for_element(cls._content_element(name)) # This is ugly but the above doesn't work import time time.sleep(3)
def _content_element(name): """ Element with content of section specified by name Args: name: The name of the accordion. """ root = sel.element(locate(name)) # Older or newer locator el = sel.element('./../following-sibling::div[1]|' './../../following-sibling::div//ul[contains(@class, "nav-stack")]', root=root) return el
[docs]def is_active(name): """ Checks if an accordion is currently open Args: name: The name of the accordion. Returns: ``True`` if the button is depressed, ``False`` if not. """ return sel.is_displayed(_content_element(name))
def _get_link(name, link_title_or_text, by_title=True, partial=False): """Retrieves the ListAccordionLink object for given accordion name and title Args: name: Name of the accordion. link_title_or_text: Title or text of link in expanded accordion section. by_title: Whether to search by title or by text. """ if not is_active(name): click(name) link_root = _content_element(name) return ListAccordionLink(link_title_or_text, link_root, by_title, partial=partial)
[docs]def select(name, link_title_or_text, by_title=True, partial=False): """ Clicks an active link in accordion section Args: name: Name of the accordion. link_title_or_text: Title or text of link in expanded accordion section. by_title: Whether to search by title or by text. """ return _get_link(name, link_title_or_text, by_title, partial).click()
[docs]def is_selected(name, link_title_or_text, by_title=True, partial=False): """ Checks if the link in accordion section is selected Args: name: Name of the accordion. link_title_or_text: Title or text of link in expanded accordion section. by_title: Whether to search by title or by text. """ return _get_link(name, link_title_or_text, by_title, partial=partial).is_selected()