Skip to content

Commit d29325e

Browse files
Feature/bcss 20593 regression tests user (#98)
<!-- Markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Selenium to Playwright - Regression Tests - User ## Context <!-- Why is this change required? What problem does it solve? --> Feature: Change Organisation Scenario: Check an English user, that has multiple organisations is able to switch between them Given I log in to BCSS "England" as user role "MultiOrgUser" When I change organisation Then I will be logged in as the alternative organisation. Below are the 3 Files where Code Refactoring is Implemented. 1) Tests File - test_change_organisation_regression_user.py 2) POM - organisations_page.py 3) users.json ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [X] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [X] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [X] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [X] I have followed the code style of the project - [X] I have added tests to cover my changes (where appropriate) - [ ] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [X] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes. --------- Co-authored-by: AndyG <[email protected]>
1 parent 6dcdfef commit d29325e

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed

pages/organisations/organisations_page.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from playwright.sync_api import Page
22
from pages.base_page import BasePage
3-
3+
from typing import List
44

55
class OrganisationsPage(BasePage):
66
"""Organisations Page locators, and methods for interacting with the page."""
@@ -50,3 +50,76 @@ def go_to_upload_nacs_data_bureau_page(self) -> None:
5050
def go_to_bureau_page(self) -> None:
5151
"""Clicks the 'Bureau' link."""
5252
self.click(self.bureau_page)
53+
54+
class OrganisationSwitchPage:
55+
"""Page Object Model for interacting with the Organisation Switch page."""
56+
57+
def __init__(self, page: Page):
58+
"""
59+
Initializes the OrganisationSwitchPage with locators for key elements.
60+
61+
Args:
62+
page (Page): The Playwright Page object representing the browser page.
63+
"""
64+
self.page = page
65+
self.radio_buttons = self.page.locator("input[type='radio']")
66+
self.selected_radio = self.page.locator("input[name='organisation']:checked")
67+
self.continue_button = self.page.get_by_role("button", name="Continue")
68+
self.select_org_link = self.page.get_by_role("link", name="Select Org")
69+
self.login_info = self.page.locator("td.loginInfo")
70+
71+
def click(self, locator) -> None:
72+
"""
73+
Clicks the given locator element.
74+
75+
Args:
76+
locator: A Playwright Locator object to be clicked.
77+
"""
78+
locator.click()
79+
80+
def get_available_organisation_ids(self) -> List[str]:
81+
"""
82+
Retrieves the list of available organisation IDs from the radio button on the page.
83+
84+
Returns:
85+
List[str]: A list of organisation ID strings.
86+
"""
87+
org_ids = []
88+
count = self.radio_buttons.count()
89+
for element in range(count):
90+
org_id = self.radio_buttons.nth(element).get_attribute("id")
91+
if org_id:
92+
org_ids.append(org_id)
93+
return org_ids
94+
95+
def select_organisation_by_id(self, org_id: str) -> None:
96+
"""
97+
Selects an organisation radio button by its ID.
98+
99+
Args:
100+
org_id (str): The ID of the organisation to select.
101+
"""
102+
self.click(self.page.locator(f"#{org_id}"))
103+
104+
def click_continue(self) -> None:
105+
"""
106+
Clicks the 'Continue' button on the page.
107+
"""
108+
self.click(self.continue_button)
109+
110+
def click_select_org_link(self) -> None:
111+
"""
112+
Clicks the 'Select Org' link to return to the organisation selection page.
113+
"""
114+
self.click(self.select_org_link)
115+
116+
def get_logged_in_text(self) -> str:
117+
"""
118+
Retrieves the logged-in user information from the login info section.
119+
120+
Returns:
121+
str: The text indicating the logged-in user's role or name.
122+
"""
123+
return self.login_info.inner_text()
124+
125+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
import logging
3+
from utils.user_tools import UserTools
4+
from playwright.sync_api import Page
5+
from pages.organisations.organisations_page import OrganisationSwitchPage
6+
7+
8+
@pytest.mark.regression
9+
def test_user_can_switch_between_organisations(page: Page) -> None:
10+
"""
11+
Feature: Change Organisation
12+
Scenario: Check that an English user with multiple organisations is able to switch between them
13+
Given I log in to BCSS "England" as user role "MultiOrgUser"
14+
When I change organisation
15+
Then I will be logged in as the alternative organisation.
16+
"""
17+
18+
# Log in as a user with multiple organisations
19+
UserTools.user_login(page, "Specialist Screening Practitioner at BCS009 & BCS001")
20+
org_switch_page = OrganisationSwitchPage(page)
21+
22+
# Get the list of available organisation IDs
23+
org_ids = org_switch_page.get_available_organisation_ids()
24+
25+
# Select available organisations in turn and verify the switch
26+
for org_id in org_ids:
27+
# Select the organisation
28+
org_switch_page.select_organisation_by_id(org_id)
29+
30+
# Click continue
31+
org_switch_page.click_continue()
32+
33+
# Assert logged-in org matches expected
34+
login_text = org_switch_page.get_logged_in_text()
35+
logging.info(f"The user's current organisation is: {login_text}")
36+
assert (
37+
org_id in login_text
38+
), f"Expected to be logged in as '{org_id}', but got: {login_text}"
39+
40+
# Return to selection screen
41+
org_switch_page.click_select_org_link()

tests/regression/subject_search_criteria/test_screening_subject_search_criteria_page_regression.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
)
1010

1111
@pytest.mark.regression
12-
@pytest.mark.subject_search
1312
def test_user_can_search_for_subject_and_results_are_returned(page: Page):
1413
"""
1514
Verify that User can log in to BCSS "England" as user role "Hub Manager - State Registered"

users.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,12 @@
3030
"roles": [
3131
"Hub Manager, Southern Bowel Cancer Screening Programme Hub"
3232
]
33+
},
34+
"Specialist Screening Practitioner at BCS009 & BCS001": {
35+
"username": "BCSS120",
36+
"roles": [
37+
"Coventry and Warwickshire Bowel Cancer Screening Centre, MultiOrgUser",
38+
"Wolverhampton Bowel Cancer Screening Centre, MultiOrgUser"
39+
]
3340
}
3441
}

0 commit comments

Comments
 (0)