Skip to content

Commit

Permalink
Replace is_loaded to check_page_is_loaded
Browse files Browse the repository at this point in the history
`is_loaded` property was replaced by
`check_page_is_loaded` method, because there
were cases when a developer forgot to set
`@property`, and because of that
`wait_until_loaded` did not work correctly. It
was decided to explicitly call this check as a
method to minimize such mistakes.
  • Loading branch information
M1troll committed Nov 30, 2023
1 parent 5584f6b commit d8ac7d8
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 57 deletions.
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ packages to the terminal. The script contains all base classes contained in ``po
APP_ROOT = "https://pypi.org"
@property
def is_loaded(self) -> bool:
def check_page_is_loaded(self) -> bool:
return self.init_element(locator=locators.TagNameLocator("main")).is_displayed
@property
Expand Down
10 changes: 6 additions & 4 deletions demo/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ Base Page
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

.. note::
The ``is_loaded`` property and the ``APP_ROOT`` attribute require special attention here.
The ``check_page_is_loaded`` method and the ``APP_ROOT`` attribute require special attention
here.

.. literalinclude:: ../demo/pages/base/base_page.py
:language: python
Expand Down Expand Up @@ -182,7 +183,8 @@ Help Page
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This class represents the PyPI `help page <https://pypi.org/help/>`_. The ``title`` property is
implemented here to show how you can use page properties to implement the ``is_loaded`` property.
implemented here to show how you can use page properties to implement the ``check_page_is_loaded``
method.

.. image:: ../docs/_static/images/pypi_help_title.png
:alt: Help page title
Expand Down Expand Up @@ -215,8 +217,8 @@ This class represents the PyPI
:language: python

.. note::
You don't have to implement the ``is_loaded`` page property if this property is set on the base
page and is appropriate for the current page.
You don't have to implement the ``check_page_is_loaded`` page method if this property is set on
the base page and is appropriate for the current page.

Tests
-------------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions demo/pages/base/base_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ def navbar(self) -> Navbar:
return Navbar(self)

# Some pages can be slow to load and cause problems checking for unloaded
# items. To be sure the page is loaded, this property should return the
# items. To be sure the page is loaded, this method should return the
# result of checking for the slowest parts of the page.
@property
def is_loaded(self) -> bool:
def check_page_is_loaded(self) -> bool:
"""Return the result of checking that the page is loaded.
Check that `main` tag is displayed.
Expand Down
6 changes: 4 additions & 2 deletions demo/pages/help_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ def title_element(self) -> XPathElement:
"""Get the title element."""
return self.init_element(locators.ClassLocator("page-title"))

def is_loaded(self) -> bool:
def check_page_is_loaded(self) -> bool:
"""Return the check result that the page is loaded.
Return whether `main` tag and help page title element are displayed
or not.
"""
return super().is_loaded and self.title_element.is_displayed
return (
super().check_page_is_loaded() and self.title_element.is_displayed
)
85 changes: 43 additions & 42 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pomcorn/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def __init__(
)
self.wait_until_loaded()

@property
def is_loaded(self) -> bool:
def check_page_is_loaded(self) -> bool:
"""Return result of check that the page is loaded.
Some pages can be slow to load and cause problems checking for unloaded
Expand Down Expand Up @@ -117,7 +116,7 @@ def refresh(self) -> None:

def wait_until_loaded(self) -> None:
"""Wait until page is loaded."""
self.wait.until(lambda _: self.is_loaded)
self.wait.until(lambda _: self.check_page_is_loaded())

def navigate(self, url: str) -> None:
"""Navigate absolute URL.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ipython = ">= 8.14.0"
# https://pre-commit.com/
pre-commit = ">= 3.3.3"
# Fixed version until fix of https://github.com/jorisroovers/gitlint/issues/535
virtualenv = "20.24.5"
# virtualenv = "20.24.5"
# Collection of invoke commands
# https://github.com/saritasa-nest/saritasa-python-invocations
saritasa-invocations = ">= 0.8"
Expand Down

0 comments on commit d8ac7d8

Please sign in to comment.