Skip to content

Commit

Permalink
[#505] REFACTOR: make pom sub-descriptors naming similar to selene.En…
Browse files Browse the repository at this point in the history
…tities...

this way the API of descriptors will be easier to learn (because of similarity, and consistency), and less different from future version when we make descriptors built into selene.Entities... But... might confuse if we fail to make them built in:D Let's see...
  • Loading branch information
yashaka committed Jul 21, 2024
1 parent 8a5ebd5 commit ddfa124
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions selene/support/_pom.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def within_browser(self):
)
)

def Element(self, selector: str | Tuple[str, str]) -> Element:
def element(self, selector: str | Tuple[str, str]) -> Element:
# return Element(selector, _context=self)
return Element(
selector,
Expand All @@ -112,7 +112,7 @@ def Element(self, selector: str | Tuple[str, str]) -> Element:
)[1],
)

def All(self, selector: str | Tuple[str, str]) -> All:
def all(self, selector: str | Tuple[str, str]) -> All:
return All(
selector,
_context=lambda instance: (
Expand All @@ -137,7 +137,7 @@ def __get__(self, instance, owner):
actual_context.element(self.__selector)
if isinstance(actual_context, (selene.Browser, selene.Element))
# self.__context is of type self.__class__ ;)
else actual_context._element(self.__selector)
else actual_context._selene_element(self.__selector)
),
)

Expand All @@ -147,10 +147,10 @@ def __get__(self, instance, owner):

# currently protected from direct access on purpose to not missclick on it
# when actually the .Element or .All is needed
def _element(self, selector: str | Tuple[str, str]):
def _selene_element(self, selector: str | Tuple[str, str]):
return self.__as_context.element(selector)

def _all(self, selector: str | Tuple[str, str]) -> selene.Collection:
def _selene_all(self, selector: str | Tuple[str, str]) -> selene.Collection:
return self.__as_context.all(selector)


Expand Down Expand Up @@ -220,7 +220,7 @@ def __get__(self, instance, owner):
actual_context.all(self.__selector)
if isinstance(actual_context, (selene.Browser, selene.Element))
# self.__context is of type self.__class__ ;)
else actual_context._all(self.__selector)
else actual_context._selene_all(self.__selector)
),
)

Expand Down
22 changes: 11 additions & 11 deletions tests/examples/pom/test_material_ui__react_x_data_grid__mit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@

class DataGridMIT:
grid = Element('[role=grid]')
headers = grid.All('[role=columnheader]')
header = grid.Element('.MuiDataGrid-columnHeaders')
toggle_all_checkbox = header.Element('.PrivateSwitchBase-input')
headers = grid.all('[role=columnheader]')
header = grid.element('.MuiDataGrid-columnHeaders')
toggle_all_checkbox = header.element('.PrivateSwitchBase-input')
'''
# todo: support also the following:
toggle_all = headers.ElementBy(have.attribute('data-field').value('__check__'))
toggle_all_checkbox = toggle_all.Element('[type=checkbox]')
'''
content = grid.Element('[role=rowgroup]')
rows = content.All('[role=row]')
content = grid.element('[role=rowgroup]')
rows = content.all('[role=row]')
_cells_selector = '[role=gridcell]'
cells = content.All(_cells_selector)
cells = content.all(_cells_selector)

def cells_of_row(self, number):
return self.rows[number - 1].all(self._cells_selector)

footer = Element('.MuiDataGrid-footerContainer')
selected_rows_count = footer.Element('.MuiDataGrid-selectedRowCount')
pagination = footer.Element('.MuiTablePagination-root')
pagination_rows_displayed = pagination.Element('.MuiTablePagination-displayedRows')
page_to_right = pagination.Element('[data-testid=KeyboardArrowRightIcon]')
page_to_left = pagination.Element('[data-testid=KeyboardArrowLeftIcon]')
selected_rows_count = footer.element('.MuiDataGrid-selectedRowCount')
pagination = footer.element('.MuiTablePagination-root')
pagination_rows_displayed = pagination.element('.MuiTablePagination-displayedRows')
page_to_right = pagination.element('[data-testid=KeyboardArrowRightIcon]')
page_to_left = pagination.element('[data-testid=KeyboardArrowLeftIcon]')

def __init__(self, context):
self.context = context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def open(self):
# Example of the POM-like PageObject pattern
class ReactContinuousSlider:
thumb = Element('.MuiSlider-thumb')
thumb_input = thumb.Element('input')
thumb_input = thumb.element('input')
volume_up = Element('[data-testid=VolumeUpIcon]')
volume_down = Element('[data-testid=VolumeDownIcon]')
rail = Element('.MuiSlider-rail')
Expand Down

0 comments on commit ddfa124

Please sign in to comment.