Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace is_loaded property to check_page_is_loaded method #14

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 9 additions & 3 deletions demo/pages/base/base_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,21 @@ 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.

"""
# Be careful with the elements you use to check page load. If you only
# use them to check loading, it's better to initiate them directly in
# this method. Otherwise, it is better to define them as page
# properties or initiate them in the `__init__` method above the
# `super().__init__` call. This is necessary because the
# `wait_until_loaded` method will be called in `super().__init__`, and
# it depends on `check_page_is_loaded`.
return self.init_element(
locator=locators.TagNameLocator("main"),
).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
)
7 changes: 7 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ Version history

We follow `Semantic Versions <https://semver.org/>`_.

unreleased
*******************************************************************************

Backwards incompatible changes
-------------------------------------------------------------------------------
- Replace ``is_loaded`` property to ``check_page_is_loaded`` method

0.1.0
*******************************************************************************

Expand Down
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.

6 changes: 2 additions & 4 deletions pomcorn/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ def _prepare_locator(

Check that only one locator argument is passed, or none.
If only `relative_locator` was passed, `base_locator` will be added to
it.
If only `locator` was passed, it will return itself.
If both locators are empty, `base_locator` is returned.
it. If only `locator` was passed, it will return itself.

Raises:
ValueError: If both arguments were passed.
ValueError: If both arguments were passed or neither.

"""
if relative_locator and locator:
Expand Down
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
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ maintainers = [
]
homepage = "https://pypi.org/project/pomcorn/"
repository = "https://github.com/saritasa-nest/pomcorn/"
documentation = "http://pomcorn.rtfd.io/"
keywords = [
"python",
"selenium",
Expand Down Expand Up @@ -51,8 +52,6 @@ ipython = ">= 8.14.0"
# A framework for managing and maintaining multi-language pre-commit hooks.
# 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"
# Collection of invoke commands
# https://github.com/saritasa-nest/saritasa-python-invocations
saritasa-invocations = ">= 0.8"
Expand Down