Page Key Features¶
Note
Only a few methods are described here, due to their complexity. For a comprehensive list of all available methods, please refer to the Page Interface documentation.
The Page class is equipped with methods to manage and verify the state of web pages during automated testing.
Two complex methods, wait_page_loaded and is_page_opened, provide functionality to handle page loading and
validation effectively. Below are the details for each method.
Key Methods¶
1. Method wait_page_loaded¶
The wait_page_loaded method is designed to wait until the page and its elements are fully loaded.
This is crucial for ensuring that your interactions with the page occur only after all necessary elements are available.
Parameters¶
silent(bool): When set toTrue, the method suppresses logging messages. IfFalse, the method logs a message indicating that it is waiting for the page to load.timeout(Union[int, float]): Specifies the maximum time (in seconds) to wait for the page and its elements to load. This parameter can be set to a custom value or use the defaultWAIT_PAGEvalue.
Functionality¶
Anchor Element Wait:
The method waits for the
anchorelement (a key element indicating that the page has loaded) to be visible using the specified timeout.
Element Waits:
The method iterates through
self.page_elementsand waits for each element according to itswaitattribute:If
waitisFalse, it waits until the element is hidden.If
waitisTrue, it waits until the element is visible.
Example Usage¶
from mops.base.page import Page
from mops.base.element import Element
class LoginPage(Page):
def __init__(self):
super().__init__('.login.page', name='Login page')
loader = Element('.loader', name='loader', wait=False)
form = Element('.login.form', name='login form', wait=True)
# pytest usage
def test_wait_page_load(driver_wrapper):
LoginPage().wait_page_loaded()
Code Explanation
The page.wait_page_loaded() line will wait for:
anchorinternal Element visibility ofLoginPagewhich is “.login.page”loaderElement invisibility ofLoginPageformElement visibility ofLoginPage
2. Method is_page_opened¶
The is_page_opened method is designed to determine if the current page is opened and ready for interaction.
This method checks several conditions to confirm that the page is in the expected state.
Parameters¶
with_elements(bool): If set toTrue, the method will verify that the page elements defined inself.page_elementsare visible and displayed. This ensures that key elements on the page are present and accessible.with_url(bool): If set toTrue, the method will also check that the current URL of the page matches the expected URL (self.url). This helps ensure that the browser is on the correct page.
Functionality¶
Element Visibility Check:
The method iterates through
self.page_elementsto check if eachElement(..., wait=True)is visible on the page, if thewith_elementsparameter isTrue.
Anchor Visibility Check:
It checks if the
anchorinternalElement(presumably a key element indicating that the page has loaded) is displayed.
URL Check:
If
with_urlisTrue, it verifies that the current URL of the page matches the expected URL stored inself.url.
Example Usage¶
from mops.base.page import Page
from mops.base.element import Element
class LoginPage(Page):
def __init__(self):
super().__init__('.login.page', name='Login page')
loader = Element('.loader', name='loader', wait=False)
form = Element('.login.form', name='login form', wait=True)
# pytest usage
def test_wait_page_load(driver_wrapper):
assert LoginPage().is_page_opened(with_elements=True, with_url=False)
Code Explanation
The is_page_opened(...) method will return status of:
anchorinternal Element visibility ofLoginPagewhich is “.login.page”formElement visibility ofLoginPageurlequality will be skipped according towith_url=False