|
1 | 1 | from playwright.sync_api import Page |
2 | | -from playwright.sync_api import sync_playwright |
3 | 2 | from pages.base_page import BasePage |
4 | | -from typing import List |
| 3 | + |
5 | 4 |
|
6 | 5 | class OrganisationsPage(BasePage): |
7 | 6 | """Organisations Page locators, and methods for interacting with the page.""" |
@@ -52,65 +51,34 @@ def go_to_bureau_page(self) -> None: |
52 | 51 | """Clicks the 'Bureau' link.""" |
53 | 52 | self.click(self.bureau_page) |
54 | 53 |
|
55 | | -class NoOrganisationAvailableError(Exception): |
56 | | - pass |
57 | | - |
58 | | -class OrganisationNotSelectedError(Exception): |
59 | | - pass |
60 | | - |
61 | | -class ContinueButtonNotFoundError(Exception): |
62 | | - pass |
63 | | - |
64 | 54 |
|
65 | 55 | class OrganisationSwitchPage: |
66 | 56 | def __init__(self, page: Page): |
67 | 57 | self.page = page |
68 | 58 | self.radio_selector = "input[name='organisation']" |
69 | 59 | self.select_org_link = "a:has-text('Select Organisation')" |
70 | 60 |
|
71 | | - def get_available_organisation_ids(self) -> List[str]: |
72 | | - self.page.wait_for_selector(self.radio_selector, timeout=10000) |
73 | | - radios = self.page.locator(self.radio_selector) |
74 | | - org_ids = [ |
75 | | - org_id for i in range(radios.count()) |
76 | | - if (org_id := radios.nth(i).get_attribute("id")) is not None |
77 | | - ] |
78 | | - if len(org_ids) < 2: |
79 | | - raise NoOrganisationAvailableError("Fewer than two organisations available.") |
| 61 | + RADIO_SELECTOR = "input[type='radio']" |
| 62 | + SELECT_ORG_LINK_TEXT = "Select Org" |
| 63 | + LOGIN_INFO_SELECTOR = "td.loginInfo" |
| 64 | + |
| 65 | + def get_available_organisation_ids(self) -> list[str]: |
| 66 | + radios = self.page.locator(self.RADIO_SELECTOR) |
| 67 | + org_ids = [] |
| 68 | + for i in range(radios.count()): |
| 69 | + org_id = radios.nth(i).get_attribute("id") |
| 70 | + if org_id: |
| 71 | + org_ids.append(org_id) |
80 | 72 | return org_ids |
81 | 73 |
|
82 | 74 | def select_organisation_by_id(self, org_id: str) -> None: |
83 | | - radio = self.page.locator(f"{self.radio_selector}#{org_id}") |
84 | | - radio.wait_for(state="visible", timeout=5000) |
85 | | - radio.check(force=True) |
86 | | - |
87 | | - def select_first_available_organisation(self) -> None: |
88 | | - for selector in ['#BCS009', '#BCS001']: |
89 | | - radio = self.page.locator(selector) |
90 | | - if radio.is_enabled(): |
91 | | - radio.check() |
92 | | - return |
93 | | - raise OrganisationNotSelectedError("No available organisation radio buttons to select.") |
94 | | - |
95 | | - def get_selected_organisation_id(self) -> str: |
96 | | - selected = self.page.locator(f"{self.radio_selector}:checked") |
97 | | - try: |
98 | | - selected.wait_for(state="attached", timeout=5000) |
99 | | - except Exception: |
100 | | - raise OrganisationNotSelectedError("No organisation is currently selected.") |
101 | | - org_id = selected.get_attribute("id") |
102 | | - if not org_id: |
103 | | - raise OrganisationNotSelectedError("No organisation is currently selected.") |
104 | | - return org_id |
105 | | - |
106 | | - def click_continue_button(self) -> None: |
107 | | - try: |
108 | | - self.page.get_by_role("button", name="Continue").click() |
109 | | - self.page.wait_for_load_state("networkidle") |
110 | | - except Exception: |
111 | | - raise ContinueButtonNotFoundError("Could not find or click the 'Continue' button.") |
112 | | - |
113 | | - def return_to_change_org_page(self) -> None: |
114 | | - self.page.get_by_role("link", name="Select Org").click() |
115 | | - self.page.wait_for_url("**/changeorg**", timeout=10000) |
116 | | - self.page.wait_for_selector(self.radio_selector, timeout=10000) |
| 75 | + self.page.locator(f"#{org_id}").check() |
| 76 | + |
| 77 | + def click_continue(self) -> None: |
| 78 | + self.page.get_by_role("button", name="Continue").click() |
| 79 | + |
| 80 | + def click_select_org_link(self) -> None: |
| 81 | + self.page.get_by_role("link", name=self.SELECT_ORG_LINK_TEXT).click() |
| 82 | + |
| 83 | + def get_logged_in_text(self) -> str: |
| 84 | + return self.page.locator(self.LOGIN_INFO_SELECTOR).inner_text() |
0 commit comments