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

20250205 #73

Merged
merged 2 commits into from
Feb 5, 2025
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
211 changes: 121 additions & 90 deletions libs/playwright_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,111 +134,142 @@ def act(self, locator, action, value=None, **kwargs) -> None:
self.capture_screenshot(identifier=locator, action=f"before-{action}")
match action.lower():
case actions.CLICK_LINK:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator, exact=exact).nth(index)
else:
elem = self.ce.page.get_by_role(aria_roles.LINK, name=locator, exact=exact).nth(index)
elem.click()
self._click_link(locator=locator, exact=exact, index=index)
case actions.CLICK_BUTTON:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_role(aria_roles.BUTTON, name=locator).nth(index)
elem.click()
self._click_button(locator=locator, exact=exact, index=index)
case actions.CLICK_LABEL:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.click()
self._click_label(locator=locator, exact=exact, index=index)
case actions.CLICK_TEXT:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_text(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_text(locator, exact=exact).nth(index)
elem.click()
self._click_text(locator=locator, exact=exact, index=index)
case actions.FILL | actions.TYPE:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.click()
if value != data_values.EMPTY:
elem.fill(value)
self.capture_screenshot(identifier=locator, action=f"after-{action}")
self._fill(locator=locator, value=value, exact=exact, index=index)
case actions.RADIO_BUTTON_SELECT:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.click()
self.capture_screenshot(identifier=locator, action=f"after-{action}")
self._radio_button_select(locator=locator, exact=exact, index=index)
case actions.SELECT_FILE:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.set_input_files(value)
self._select_file(locator=locator, value=value, exact=exact, index=index)
case actions.SELECT_FROM_LIST:
self.act(locator=locator, action=actions.FILL, value=value)
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_role(aria_roles.OPTION, name=value)
elem.click()
self._select_from_list(locator=locator, value=value, index=index)
case actions.CHECKBOX_CHECK:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator).nth(index)
elem.check()
self._checkbox_check(locator=locator, index=index)
case actions.CHECKBOX_UNCHECK:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator).nth(0)
elem.uncheck()
self._checkbox_uncheck(locator=locator, index=index)
case actions.CLICK_LINK_INDEX_FOR_ROW:
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = (
self.ce.page.get_by_role(
aria_roles.ROW,
name=locator,
)
.get_by_role(aria_roles.LINK)
.nth(value)
)
elem.click()
self._click_index_for_row(locator=locator, value=value, index=index)
case actions.CLICK_WILDCARD:
elem = self.ce.page.click(f"text={locator}")
self.ce.page.click(f"text={locator}")
case actions.CHAIN_LOCATOR_ACTION:
eval(f"{self.PAGE_ELEMENT_PATH}{locator}")
self.capture_screenshot(identifier=locator, action=f"after-{action}")

def _click_link(self, locator: str, exact: bool, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator, exact=exact).nth(index)
else:
elem = self.ce.page.get_by_role(aria_roles.LINK, name=locator, exact=exact).nth(index)
elem.click()

def _click_button(self, locator: str, exact: bool, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_role(aria_roles.BUTTON, name=locator, exact=exact).nth(index)
elem.click()

def _click_label(self, locator: str, exact: bool, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.click()

def _click_text(self, locator: str, exact: bool, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_text(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_text(locator, exact=exact).nth(index)
elem.click()

def _fill(self, locator: str, value: str, exact: bool, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.click()
if value != data_values.EMPTY:
elem.fill(value)

def _radio_button_select(self, locator: str, exact: bool, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.click()

def _select_file(self, locator: str, value: str, exact: bool, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator, exact=exact).nth(index)
elem.set_input_files(value)

def _select_from_list(self, locator: str, value: str, index: int):
self._fill(locator=locator, value=value, exact=False, index=index)
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_role(aria_roles.OPTION, name=value)
elem.click()

def _checkbox_check(self, locator: str, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator).nth(index)
elem.check()

def _checkbox_uncheck(self, locator: str, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = self.ce.page.get_by_label(locator).nth(0)
elem.uncheck()

def _click_index_for_row(self, locator: str, value: str, index: int):
if escape_characters.SEPARATOR_CHAR in locator:
_location = locator.split(escape_characters.SEPARATOR_CHAR)[0]
_locator = locator.split(escape_characters.SEPARATOR_CHAR)[1]
elem = self.ce.page.get_by_role(_location, name=_locator).nth(index)
else:
elem = (
self.ce.page.get_by_role(
aria_roles.ROW,
name=locator,
)
.get_by_role(aria_roles.LINK)
.nth(value)
)
elem.click()

def go_to_url(self, url: str) -> None:
_full_url = f"{self.ce.service_url.replace('/start','')}{url}" if url.startswith("/") else url
self.ce.page.goto(_full_url)
Expand Down
5 changes: 2 additions & 3 deletions pages/pg_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,14 +665,13 @@ def bug_mavis_1818(self):
self.po.verify(
locator=self.LBL_MAIN,
property=element_properties.TEXT,
expected_value="Ready for nurse",
expected_value="Conflicting consent",
)
self.po.verify(
locator=self.LBL_MAIN,
property=element_properties.TEXT,
expected_value=f"Nurse Joy decided that {self.LNK_CHILD_CONFLICTING_CONSENT} is ready for the nurse.",
expected_value=f"You can only vaccinate if all respondents give consent.",
)
self.po.verify(locator=self.LBL_MAIN, property=element_properties.TEXT, expected_value="Consent given")
self.click_activity_log()
self.po.verify(
locator=self.LBL_MAIN,
Expand Down
Loading