Skip to content

Commit

Permalink
Merge pull request #98 from saritasa-nest/feature/update-item-class-a…
Browse files Browse the repository at this point in the history
…ttribute

Improve getting `item class` in `ListComponent`
  • Loading branch information
M1troll authored Nov 25, 2024
2 parents cfdb0d7 + c79ba41 commit 409ee09
Show file tree
Hide file tree
Showing 23 changed files with 236 additions and 65 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ Below is the code that opens ``PyPI.org``, searches for packages by name and pri

class PackageList(ListComponent[Package, PyPIPage]):

item_class = Package
relative_item_locator = locators.ClassLocator("snippet__name")

@property
Expand Down
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ words:
- STDLIB
- pydocstyle
- redef
- prefs

# RST blocks
- autodoc
Expand Down
Empty file added demo/__init__.py
Empty file.
11 changes: 9 additions & 2 deletions demo/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from pages import HelpPage, IndexPage, SearchPage
from selenium import webdriver as selenium_webdriver
from selenium.webdriver.remote.webdriver import WebDriver

import pytest

from demo.pages import HelpPage, IndexPage, SearchPage


# You can implement your own logic to initialize a webdriver.
# An example of Chrome initialization is described below.
@pytest.fixture(scope="session")
def webdriver() -> WebDriver:
"""Initialize `Chrome` webdriver."""
webdriver = selenium_webdriver.Chrome()
options = selenium_webdriver.ChromeOptions()

# Set browser's language to English
prefs = {"intl.accept_languages": "en,en_U"}
options.add_experimental_option("prefs", prefs)

webdriver = selenium_webdriver.Chrome(options)
webdriver.set_window_size(1920, 1080)
return webdriver

Expand Down
8 changes: 4 additions & 4 deletions demo/pages/base/base_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pomcorn import Page, locators

if TYPE_CHECKING:
from pages import IndexPage
from pages.common import Navbar
from demo.pages import IndexPage
from demo.pages.common import Navbar


class PyPIPage(Page):
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(
@property
def navbar(self) -> Navbar:
"""Get a component for working with the page navigation panel."""
from pages.common import Navbar
from demo.pages.common import Navbar

return Navbar(self)

Expand All @@ -82,7 +82,7 @@ def check_page_is_loaded(self) -> bool:

def click_on_logo(self) -> IndexPage:
"""Click on the logo and redirect to `IndexPage`."""
from pages import IndexPage
from demo.pages import IndexPage

self.logo.click()
return IndexPage(self.webdriver)
7 changes: 3 additions & 4 deletions demo/pages/common/navigation_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from typing import TYPE_CHECKING

from pages import PyPIComponent

from demo.pages import PyPIComponent
from pomcorn import Element, locators

if TYPE_CHECKING:
from pages.help_page import HelpPage
from demo.pages.help_page import HelpPage


# `Component` implements methods of waiting until the component becomes
Expand All @@ -30,7 +29,7 @@ class Navbar(PyPIComponent):

def open_help(self) -> HelpPage:
"""Click on `Help` button and redirect to HelpPage."""
from pages.help_page import HelpPage
from demo.pages.help_page import HelpPage

self.help_button.click()
return HelpPage(self.webdriver)
6 changes: 3 additions & 3 deletions demo/pages/common/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from typing import TYPE_CHECKING

from pages import PyPIComponent
from selenium.webdriver.common.keys import Keys

from demo.pages import PyPIComponent
from pomcorn import locators

if TYPE_CHECKING:
from pages.search_page import SearchPage
from demo.pages.search_page import SearchPage


class Search(PyPIComponent):
Expand All @@ -24,7 +24,7 @@ def find(self, text: str) -> SearchPage:
Redirect to `SearchPage` and return its instance.
"""
from pages.search_page import SearchPage
from demo.pages.search_page import SearchPage

self.body.fill(text)
self.body.send_keys(Keys.ENTER)
Expand Down
4 changes: 2 additions & 2 deletions demo/pages/help_page.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

from pages.base import PyPIPage
from selenium.webdriver.remote.webdriver import WebDriver

from demo.pages.base import PyPIPage
from pomcorn import Element, locators


Expand All @@ -20,7 +20,7 @@ def open(
app_root: str | None = None,
) -> HelpPage:
"""Open the help page via the index page."""
from pages.index_page import IndexPage
from demo.pages.index_page import IndexPage

# Reusing already implemented methods of opening a page instead of
# overriding `app_root` allows us to be independent from URK changes:
Expand Down
5 changes: 3 additions & 2 deletions demo/pages/index_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pages.base import PyPIPage
from pages.common import Search
from selenium.webdriver.remote.webdriver import WebDriver

from demo.pages.base import PyPIPage
from demo.pages.common import Search


class IndexPage(PyPIPage):
"""Represent the index page."""
Expand Down
4 changes: 2 additions & 2 deletions demo/pages/package_details_page.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

from pages.base import PyPIPage
from selenium.webdriver.remote.webdriver import WebDriver

from demo.pages.base import PyPIPage
from pomcorn import locators


Expand All @@ -25,7 +25,7 @@ def open(
app_root: str | None = None,
) -> PackageDetailsPage:
"""Search and open the package details page by its name."""
from pages import IndexPage
from demo.pages import IndexPage

search_page = IndexPage.open(
webdriver,
Expand Down
7 changes: 3 additions & 4 deletions demo/pages/search_page/components/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from typing import TYPE_CHECKING

from pages import PyPIComponent

from demo.pages import PyPIComponent
from pomcorn import locators

if TYPE_CHECKING:
from pages import PackageDetailsPage
from demo.pages import PackageDetailsPage


class Package(PyPIComponent):
Expand All @@ -22,7 +21,7 @@ def name(self) -> str:

def open(self) -> PackageDetailsPage:
"""Click on the package and open its details page."""
from pages import PackageDetailsPage
from demo.pages import PackageDetailsPage

# The property `body` is available because the package is descendant of
# `Component`. It allows us to interact with the body of the component
Expand Down
9 changes: 4 additions & 5 deletions demo/pages/search_page/components/package_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pages import PyPIPage

from demo.pages import PyPIPage
from pomcorn import ListComponent, locators

from .package import Package
Expand All @@ -8,9 +7,9 @@
class PackageList(ListComponent[Package, PyPIPage]):
"""Represent the list of search results on `SearchPage`."""

# The ``ListComponent`` item should always be ``Component``, because all
# its methods depend on `base_locator`. Also this attribute is required.
item_class = Package
# By default `ListComponent` have `item_class` attribute with stored first
# Generic variable (Package in current case). This attribute is responsible
# for the class that will be used for list items.

base_locator = locators.PropertyLocator(
prop="aria-label",
Expand Down
3 changes: 2 additions & 1 deletion demo/pages/search_page/search_page.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from pages import IndexPage, PyPIPage
from selenium.webdriver.remote.webdriver import WebDriver

from demo.pages import IndexPage, PyPIPage

from .components import PackageList


Expand Down
2 changes: 1 addition & 1 deletion demo/tests/test_logo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pages import HelpPage
from demo.pages import HelpPage


def test_logo(help_page: HelpPage):
Expand Down
2 changes: 1 addition & 1 deletion demo/tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pages import IndexPage
from demo.pages import IndexPage


def test_search(index_page: IndexPage):
Expand Down
12 changes: 8 additions & 4 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Version history

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

0.8.1 (25.11.24)
*******************************************************************************
- Improve getting ``item class`` from first ``ListComponent`` generic variable.
There were several cases where this didn't work correctly (for multiple generic variables
and inheritance). Examples of such cases are presented in `this PR <https://github.com/saritasa-nest/pomcorn/pull/98#issuecomment-2485811259>`_.\

**Warning**: The ``item_class`` class attribute was removed.

0.8.0 (05.07.24)
*******************************************************************************
- Add ability to not specify ``item_class`` in ``ListComponent``. Instead, it
Expand All @@ -21,19 +29,16 @@ deprecated and will be removed soon.
- Improve ``Page.click_on_page()`` method to click the page coordinates instead
of offset relative to current mouse position


0.7.3
*******************************************************************************
- Add ability to not specify ``app_root`` in ``Page.open_from_url()`` as in ``Page.open()``


0.7.2
*******************************************************************************
- Improve ``Page.click_on_page()`` method to click on <html> tag
- Improve ``Page.open_from_url()`` to support kwargs
- Fix ``\`` related problems in ``Page._get_full_relative_url()``


0.7.1
*******************************************************************************

Expand All @@ -42,7 +47,6 @@ deprecated and will be removed soon.
- Fix some possible xpath errors depending on empty locators queries and
brackets.


0.7.0
*******************************************************************************

Expand Down
1 change: 0 additions & 1 deletion docs/developer_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Components
.. automodule:: pomcorn.component
:members:


PomcornElement
*******************************************************************************

Expand Down
Loading

0 comments on commit 409ee09

Please sign in to comment.