|
| 1 | +import logging |
| 2 | +import pytest |
| 3 | +from playwright.sync_api import Page, expect |
| 4 | +from pages.base_page import BasePage |
| 5 | + |
| 6 | + |
| 7 | +class SubjectEpisodeEventsAndNotesPage(BasePage): |
| 8 | + """Episode Events and Notes Page locators, and methods for interacting with the page.""" |
| 9 | + |
| 10 | + def __init__(self, page: Page): |
| 11 | + super().__init__(page) |
| 12 | + self.page = page |
| 13 | + # List of episode events and notes - page locators |
| 14 | + self.latest_event_status_cell = self.page.locator("table >> td.epihdr_data").nth(0) # if it's the first one |
| 15 | + self.latest_event_cell = self.page.get_by_role("cell", name="Record Diagnosis Date", exact=True) |
| 16 | + self.latest_diagnosis_cell = self.page.locator("td[align='center']:has-text('Diag Date :')") |
| 17 | + |
| 18 | + # Episode details (Replace with actual selectors only for scenario 17) |
| 19 | + self.latest_episode_status = self.page.locator("#latestEpisodeStatus") |
| 20 | + self.latest_episode_has_diagnosis_date = self.page.locator("#latestEpisodeHasDiagnosisDate") |
| 21 | + self.latest_episode_diagnosis_reason = self.page.locator("#latestEpisodeDiagnosisDateReason") |
| 22 | + self.process_sspi_update_button = self.page.get_by_text("Process SSPI Update") |
| 23 | + self.deduction_reason_dropdown = self.page.locator("#deductionReason") |
| 24 | + self.confirm_sspi_update_button = self.page.get_by_text("Confirm") |
| 25 | + |
| 26 | + def expected_episode_event_is_displayed(self, event_description: str) -> None: |
| 27 | + """Check if the expected episode event is displayed on the page.""" |
| 28 | + expect( |
| 29 | + self.page.get_by_role("cell", name=event_description, exact=True) |
| 30 | + ).to_be_visible() |
| 31 | + |
| 32 | + def get_latest_event_details(self) -> dict: |
| 33 | + """Retrieves key details for the latest episode entry.""" |
| 34 | + try: |
| 35 | + status_text = self.latest_event_status_cell.inner_text() |
| 36 | + event_text = self.latest_event_cell.inner_text() |
| 37 | + diagnosis_text = self.latest_diagnosis_cell.first.inner_text() |
| 38 | + logging.debug(f"DEBUG: {event_text}, {status_text}, {diagnosis_text}") |
| 39 | + except Exception as e: |
| 40 | + logging.error(f"Could not retrieve latest event details: {e}") |
| 41 | + pytest.fail("Failed to read latest episode event details from UI.") |
| 42 | + |
| 43 | + return { |
| 44 | + "latest_event_status": status_text, |
| 45 | + "event": event_text, |
| 46 | + "item": diagnosis_text, |
| 47 | + } |
| 48 | + |
| 49 | + def validate_event_status_is_not_A50(self, event_details: dict) -> None: |
| 50 | + """Validates that latest_event_status does not contain 'A50'.""" |
| 51 | + latest_status = event_details.get("latest_event_status") |
| 52 | + |
| 53 | + logging.info(f"Validating Latest Event Status: {latest_status}") |
| 54 | + |
| 55 | + if latest_status is None: |
| 56 | + pytest.fail("Missing 'latest_event_status' in event_details.") |
| 57 | + |
| 58 | + if "A50" in latest_status: |
| 59 | + pytest.fail(f"Invalid status detected: 'A50' is not allowed. Received: '{latest_status}'") |
| 60 | + |
| 61 | + logging.info(f"Status '{latest_status}' is allowed.") |
| 62 | + |
| 63 | + def is_record_diagnosis_date_option_available(self) -> bool: |
| 64 | + """ |
| 65 | + Check if the 'Record Diagnosis Date' option is available on the page. |
| 66 | +
|
| 67 | + Returns: |
| 68 | + bool: True if the option is available, False otherwise. |
| 69 | + """ |
| 70 | + try: |
| 71 | + return self.page.get_by_role("button", name="Record Diagnosis Date").is_visible() |
| 72 | + except Exception as e: |
| 73 | + logging.error(f"Error checking for 'Record Diagnosis Date' option: {e}") |
| 74 | + return False |
| 75 | + |
| 76 | + def is_amend_diagnosis_date_option_available(self) -> bool: |
| 77 | + """ |
| 78 | + Check if the 'Amend Diagnosis Date' option is available on the page. |
| 79 | +
|
| 80 | + Returns: |
| 81 | + bool: True if the option is available, False otherwise. |
| 82 | + """ |
| 83 | + try: |
| 84 | + return self.page.get_by_role("button", name="Amend Diagnosis Date").is_visible() |
| 85 | + except Exception as e: |
| 86 | + logging.error(f"Error checking for 'Amend Diagnosis Date' option: {e}") |
| 87 | + return False |
| 88 | + |
| 89 | + def process_sspi_update_for_death(self, deduction_reason: str): |
| 90 | + self.process_sspi_update_button.click() |
| 91 | + self.deduction_reason_dropdown.select_option(label=deduction_reason) |
| 92 | + self.confirm_sspi_update_button.click() |
| 93 | + |
| 94 | + def get_latest_episode_details(self): |
| 95 | + return { |
| 96 | + "latest_episode_status": self.latest_episode_status.inner_text(), |
| 97 | + "latest_episode_has_diagnosis_date": self.latest_episode_has_diagnosis_date.inner_text(), |
| 98 | + "latest_episode_diagnosis_date_reason": self.latest_episode_diagnosis_reason.inner_text(), |
| 99 | + } |
0 commit comments