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']¶
-
-
find_link_element
()[source]¶ Returns the
WebElement
object located byself.locator
Shorthand for
self.find_element(self.locator)
- Returns
WebElement
object for the link
-
click_link
(scroll_to=False)[source]¶ 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
instanceNone: Returns
None
-
hover_over_link
(scroll_to=False)[source]¶ 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 (orNone
if no hover action is defined)
-
class
-
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 byself.locator
Shorthand for
self.find_element(self.locator)
- Returns
WebElement
object for the menu
-
click_link
(link_name)[source]¶ 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 inself.links
-
hover_over_link
(link_name)[source]¶ 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 inself.links
-
-
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 forNavLinkObject
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 ifYAML_FILE
isNone
):- Variables
NavObject.FIXED – (Default: True) True if element is a fixed navbar, False otherwise. If set to False in a subclass,
click_page_link()
andhover_over_page_link()
will scroll the target link into view before interacting with itNavObject.COLLAPSIBLE – (Default: False) True if the navbar is collapsible (e.g. for hamburger menus). If set to True,
MENU_LOCATOR
,EXPAND_BUTTON_LOCATOR
, and (optionally)COLLAPSE_BUTTON_LOCATOR
should also be set
For collapsible navs, these additional attributes should also be specified in
YAML_FILE
(or should be set in subclasses ifYAML_FILE
isNone
):- Variables
NavObject.MENU_LOCATOR – (Required for collapsible) Locator for the collapsible menu element
NavObject.EXPAND_BUTTON_LOCATOR – (Required for collapsible) Locator for the button that expands the nav menu
NavObject.COLLAPSE_BUTTON_LOCATOR – (Optional) Locator for the button that collapses the nav menu. If unspecified, this will be set to the same value as
EXPAND_BUTTON_LOCATOR
Note
MENU_LOCATOR
,EXPAND_BUTTON_LOCATOR
, andCOLLAPSE_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 withCOLLAPSIBLE = True
without re-writing the YAML file. The subclass would only need to setMENU_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 fromLINK_DICTS
, which should be set in subclasses ifYAML_FILE
isNone
):- Variables
NavObject.links – A dictionary mapping link names to the corresponding
NavLinkObject
instances. The keys correspond with thename
keys in the YAML representation of the navbar (or the ‘name’ keys inLINK_DICTS
ifYAML_FILE
isNone
)
If
YAML_FILE
isNone
, subclasses must set the following attribute:- Variables
NavObject.LINK_DICTS – List of link dictionaries. These are used to initialize the
NavLinkObject
instances inlinks
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¶
-
LINK_DICTS
= []¶
-
links
= {}¶
-
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 inLINK_DICTS
-
click_link
(link_name)[source]¶ 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 inself.links
-
hover_over_link
(link_name)[source]¶ 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 inself.links
-
click_expand_button
()[source]¶ Click the button to expand the nav menu
Note
For collapsible navs only. If
COLLAPSIBLE
isFalse
, 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
isFalse
, 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
isFalse
, a warning will be raised and the method will returnThis 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