Skip to content

Commit 5ec37d5

Browse files
committed
Seperated some of the OrganisationSwitchPage class methods to allow assertions to be made on the test script after each iteration.
Added assertions to the test script. # Conflicts: # pages/organisations/organisations_page.py # tests/regression/organisation_regression_tests_user/test_change_organisation_regression_user.py
1 parent c7be853 commit 5ec37d5

File tree

2 files changed

+44
-87
lines changed

2 files changed

+44
-87
lines changed
Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from playwright.sync_api import Page
2-
from playwright.sync_api import sync_playwright
32
from pages.base_page import BasePage
4-
from typing import List
3+
54

65
class OrganisationsPage(BasePage):
76
"""Organisations Page locators, and methods for interacting with the page."""
@@ -52,65 +51,34 @@ def go_to_bureau_page(self) -> None:
5251
"""Clicks the 'Bureau' link."""
5352
self.click(self.bureau_page)
5453

55-
class NoOrganisationAvailableError(Exception):
56-
pass
57-
58-
class OrganisationNotSelectedError(Exception):
59-
pass
60-
61-
class ContinueButtonNotFoundError(Exception):
62-
pass
63-
6454

6555
class OrganisationSwitchPage:
6656
def __init__(self, page: Page):
6757
self.page = page
6858
self.radio_selector = "input[name='organisation']"
6959
self.select_org_link = "a:has-text('Select Organisation')"
7060

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)
8072
return org_ids
8173

8274
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()
Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,38 @@
11
import pytest
2-
from playwright.sync_api import Page
2+
import logging
33
from utils.user_tools import UserTools
4-
from pages.organisations.organisations_page import (
5-
OrganisationSwitchPage,
6-
NoOrganisationAvailableError,
7-
OrganisationNotSelectedError,
8-
ContinueButtonNotFoundError,
9-
)
4+
from playwright.sync_api import Page
5+
from pages.organisations.organisations_page import OrganisationSwitchPage
106

117
@pytest.mark.regression
128
@pytest.mark.organisation_switch
13-
def test_user_can_switch_between_two_organisations_using_continue_button(page: Page):
9+
def test_user_can_switch_between_organisations(page: Page) -> None:
1410
"""
1511
Scenario:
1612
User switches from Org 1 → Continue → Home → 'Select Organisation' → Org 2 → Continue → Home → Return.
1713
Verifies switch success using aria role-based 'Continue' button logic.
1814
"""
15+
# Log in as a user with multiple organisations
1916
UserTools.user_login(page, "Specialist Screening Practitioner at BCS009")
20-
org_page = OrganisationSwitchPage(page)
17+
org_switch_page = OrganisationSwitchPage(page)
2118

22-
try:
23-
org_ids = org_page.get_available_organisation_ids()
24-
org1, org2 = org_ids[:2]
19+
# Get the list of available organisation IDs
20+
org_ids = org_switch_page.get_available_organisation_ids()
2521

26-
# Select Org 1 → Continue → Home
27-
org_page.select_organisation_by_id(org1)
28-
org_page.click_continue_button()
29-
selected_1 = org_page.get_selected_organisation_id()
30-
assert selected_1 == org1, f"Expected org '{org1}', got '{selected_1}'"
22+
# Select available organisations in turn and verify the switch
23+
for org_id in org_ids:
24+
# Select the organisation
25+
org_switch_page.select_organisation_by_id(org_id)
3126

32-
# Return to Change Org screen
33-
org_page.return_to_change_org_page()
27+
# Click continue
28+
org_switch_page.click_continue()
3429

35-
# Select Org 2 → Continue → Home
36-
org_page.select_organisation_by_id(org2)
37-
org_page.click_continue_button()
38-
selected_2 = org_page.get_selected_organisation_id()
39-
assert selected_2 == org2, f"Expected org '{org2}', got '{selected_2}'"
40-
assert selected_1 != selected_2, "Organisation switch did not occur."
30+
# Assert logged-in org matches expected
31+
login_text = org_switch_page.get_logged_in_text()
32+
logging.info(f"The user's current organisation is: {login_text}")
33+
assert (
34+
org_id in login_text
35+
), f"Expected to be logged in as '{org_id}', but got: {login_text}"
4136

42-
except NoOrganisationAvailableError:
43-
pytest.skip("Skipping test — fewer than two organisations available.")
44-
except (ContinueButtonNotFoundError, OrganisationNotSelectedError) as e:
45-
page.screenshot(path="org_switch_failure.png")
46-
pytest.fail(f"Test failed: {e}")
47-
except Exception as e:
48-
page.screenshot(path="unexpected_error.png")
49-
pytest.fail(f"Unexpected error: {e}")
37+
# Return to selection screen
38+
org_switch_page.click_select_org_link()

0 commit comments

Comments
 (0)