Skip to content

Commit 97746e4

Browse files
Code Refactoring is implemented for JIRA Ticket - BCSS-20593 - Selenium to Playwright - Regression Tests - User
1 parent 7842110 commit 97746e4

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

pages/organisations/organisations_page.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from playwright.sync_api import Page
1+
from playwright.sync_api import Page, expect
22
from pages.base_page import BasePage
33

44

@@ -50,3 +50,45 @@ 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+
55+
class OrganisationSwitchPage(BasePage):
56+
"""
57+
Page Object Model for Organisation Switch functionality.
58+
"""
59+
60+
CONTINUE_BUTTON = "button:has-text('Continue')"
61+
SELECT_ORG_LINK_TEXT = "Select Org"
62+
RADIO_SELECTOR = "input[type='radio']"
63+
64+
def __init__(self, page: Page):
65+
self.page = page
66+
67+
def get_available_organisation_ids(self):
68+
"""
69+
Returns a list of all available organisation radio button IDs.
70+
"""
71+
radios = self.page.locator(self.RADIO_SELECTOR)
72+
org_ids = []
73+
for i in range(radios.count()):
74+
org_id = radios.nth(i).get_attribute("id")
75+
if org_id:
76+
org_ids.append(org_id)
77+
return org_ids
78+
79+
def select_organisation_by_id_and_navigate_home(self, org_id):
80+
"""
81+
Selects the organisation radio button by its id, clicks Continue,
82+
and it navigates to the BCSS Home page after which then clicks the 'Select Org' link & it returns back to the change of organisation ids page.
83+
"""
84+
self.page.locator(f'#{org_id}').check()
85+
self.page.get_by_role('button', name='Continue').click()
86+
self.page.get_by_role('link', name=self.SELECT_ORG_LINK_TEXT).click()
87+
88+
def switch_between_organisations(self):
89+
"""
90+
Switches between all available organisations by their ids.
91+
"""
92+
org_ids = self.get_available_organisation_ids()
93+
for org_id in org_ids:
94+
self.select_organisation_by_id_and_navigate_home(org_id)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
from utils.user_tools import UserTools
3+
from playwright.sync_api import Page, expect
4+
from pages.organisations.organisations_page import OrganisationSwitchPage
5+
6+
@pytest.mark.wip
7+
@pytest.mark.regression
8+
@pytest.mark.organisation_switch
9+
def test_user_can_switch_between_organisations(page: Page):
10+
"""
11+
Feature: Change Organisation
12+
13+
Scenario: Check an English user, that has multiple organisations is able to switch between them
14+
Given I log in to BCSS "England" as user role "MultiOrgUser"
15+
When I change organisation
16+
Then I will be logged in as the alternative organisation.
17+
"""
18+
19+
# Log in as MultiOrgUser
20+
UserTools.user_login(page, "Specialist Screening Practitioner at BCS009")
21+
22+
org_switch_page = OrganisationSwitchPage(page)
23+
24+
# Switch between all available organisations by their ids (no hardcoded values)
25+
org_switch_page.switch_between_organisations()
26+
27+
28+

users.json

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

0 commit comments

Comments
 (0)