webdriver_test_tools.pageobject.nav module

class webdriver_test_tools.pageobject.nav.NavLinkObject(driver, link_dict, site_config)[source]

Bases: webdriver_test_tools.pageobject.base.BasePage

Page object prototype for nav links

class ActionTypes[source]

Bases: object

Link click/hover action types

PAGE = 'page'
SECTION = 'section'
MENU = 'menu'
NONE = 'none'
CLICK_ACTIONS = ['page', 'section', 'menu', 'none', None]
HOVER_ACTIONS = ['menu', 'none', None]
REQUIRES_TARGET = ['page', 'section']

Returns the WebElement object located by self.locator

Shorthand for self.find_element(self.locator)

Returns

WebElement object for the link

Click the link

Parameters

scroll_to – (Default: False) If True, scroll to the link first before clicking (used for non-fixed navs)

Returns

Return value depends on self.click_action:

  • ’page’: Returns the URL to the link target

  • ’section’: Returns the target section ID (prefixed with ‘#’)

  • ’menu’: Returns a NavMenuObject instance

  • None: Returns None

Hover over the link element

Parameters

scroll_to – (Default: False) If True, scroll to the link first before hovering (used for non-fixed navs)

Returns

NavMenuObject instance (or None if no hover action is defined)

class webdriver_test_tools.pageobject.nav.NavMenuObject(driver, menu_dict, site_config)[source]

Bases: webdriver_test_tools.pageobject.base.BasePage

Page object prototype for dropdown/collapsible nav menus

find_menu_element()[source]

Returns the WebElement object located by self.locator

Shorthand for self.find_element(self.locator)

Returns

WebElement object for the menu

Click a link in the menu

Parameters

link_name – Name of the link (specified in YAML or link dictionary) i.e. a valid key in self.links

Returns

The returned value of clicking the link. See NavLinkObject.click_link() for possible values

Raises

KeyError – If link_name is not a valid key in self.links

Hover over a link in the menu

Parameters

link_name – Name of the link (specified in YAML or link dictionary) i.e. a valid key in self.links

Returns

The returned value of hovering over the link. See NavLinkObject.hover_over_link() for possible values

Raises

KeyError – If link_name is not a valid key in self.links

is_visible()[source]

Check if the menu element is visible

Returns

True if the element is displayed, False if not

class webdriver_test_tools.pageobject.nav.NavObject(driver)[source]

Bases: webdriver_test_tools.pageobject.yaml.YAMLParsingPageObject

Page object prototype for navbars

Subclasses should set the following attributes:

Variables
  • NavObject.YAML_FILE – Path to a YAML file representing the navbar

  • NavObject.SITE_CONFIG – Test project’s SiteConfig class. Used for NavLinkObject instances to determine any relative URLs specified for link targets

The following attributes are determined based on the contents of YAML_FILE (or should be set in subclasses if YAML_FILE is None):

Variables

For collapsible navs, these additional attributes should also be specified in YAML_FILE (or should be set in subclasses if YAML_FILE is None):

Variables

Note

MENU_LOCATOR, EXPAND_BUTTON_LOCATOR, and COLLAPSE_BUTTON_LOCATOR will only be parsed from YAML if not already set in the subclass. This allows for a non-collapsible nav that parses YAML to be extended in a subclass with COLLAPSIBLE = True without re-writing the YAML file. The subclass would only need to set MENU_LOCATOR, EXPAND_BUTTON_LOCATOR, and (optionally) COLLAPSE_BUTTON_LOCATOR

The following attribute is set based on the ‘links’ key parsed from YAML_FILE (or parsed from LINK_DICTS, which should be set in subclasses if YAML_FILE is None):

Variables

NavObject.links – A dictionary mapping link names to the corresponding NavLinkObject instances. The keys correspond with the name keys in the YAML representation of the navbar (or the ‘name’ keys in LINK_DICTS if YAML_FILE is None)

If YAML_FILE is None, subclasses must set the following attribute:

Variables

NavObject.LINK_DICTS – List of link dictionaries. These are used to initialize the NavLinkObject instances in links at runtime. These dictionaries use the same syntax as YAML links

SITE_CONFIG = None
FIXED = True
COLLAPSIBLE = False
MENU_LOCATOR = None
COLLAPSE_BUTTON_LOCATOR = None
EXPAND_BUTTON_LOCATOR = None
parse_yaml(file_path)[source]

Parse a YAML representation of the nav object and set attributes accordingly

See YAML NavObjects doc for details on syntax.

Parameters

file_path – Full path to the YAML file

no_yaml_init()[source]

Initialize self.links using values in LINK_DICTS

Click a link on the navbar

Parameters

link_name – Name of the link (specified in YAML or link dictionary) i.e. a valid key in self.links

Returns

The returned value of clicking the link. See NavLinkObject.click_link() for possible values

Raises

KeyError – If link_name is not a valid key in self.links

Hover over a link in the navbar

Parameters

link_name – Name of the link (specified in YAML or link dictionary) i.e. a valid key in self.links

Returns

The returned value of hovering over the link. See NavLinkObject.hover_over_link() for possible values

Raises

KeyError – If link_name is not a valid key in self.links

click_expand_button()[source]

Click the button to expand the nav menu

Note

For collapsible navs only. If COLLAPSIBLE is False, a warning will be raised and the method will return

click_collapse_button()[source]

Click the button to collapse the nav menu

Note

For collapsible navs only. If COLLAPSIBLE is False, a warning will be raised and the method will return

is_expanded()[source]

Check if the nav menu is expanded

Note

For collapsible navs only. If COLLAPSIBLE is False, a warning will be raised and the method will return

This method checks if the element located by MENU_LOCATOR exists and is visible. This should be sufficient for many common implementations of collapsible navs, but can be overridden if this isn’t a reliable detection method for an implementation

Returns

True if the nav menu is expanded, False if it’s collapsed