Skip to content

Commit 34f0e62

Browse files
Removed hard coded values from tests, added properties files for tests and smokescreen tests.
Changed properties keys from camel case to snake case, to be consistent with Python's naming conventions. Some general refactoring.
1 parent c9bc82b commit 34f0e62

13 files changed

+327
-66
lines changed

pages/create_a_plan_page.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from playwright.sync_api import Page
22
from utils.click_helper import click
33

4+
45
class CreateAPlan:
56
def __init__(self, page: Page):
67
self.page = page
@@ -17,7 +18,7 @@ def __init__(self, page: Page):
1718
def click_set_all_button(self):
1819
click(self.page, self.set_all_button)
1920

20-
def fill_daily_invitation_rate_field(self,value):
21+
def fill_daily_invitation_rate_field(self,value: str):
2122
self.daily_invitation_rate_field.fill(value)
2223

2324
def fill_weekly_invitation_rate_field(self,value):
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
from playwright.sync_api import Page
22
from utils.click_helper import click
33

4+
45
class InvitationsMonitoring:
56
def __init__(self, page: Page):
67
self.page = page
7-
# Call and Recall - page links
8-
self.bcss009_invitations_plan = self.page.get_by_role("link", name="BCS009")
9-
self.bcss001_invitations_plan = self.page.get_by_role("link", name="BCS001")
10-
11-
def go_to_bcss009_invitations_plan_page(self):
12-
click(self.page, self.bcss009_invitations_plan)
13-
14-
def go_to_bcss001_invitations_plan_page(self):
15-
click(self.page, self.bcss001_invitations_plan)
16-
17-
188

9+
def go_to_invitation_plan_page(self, sc_id):
10+
self.page.get_by_role("link", name=sc_id).click()

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
pytest-playwright>=0.5.1
22
pytest-html>=4.1.1
33
pytest-json-report>=1.5.0
4-
oracledb>=2.5.1
5-
pandas>=2.2.3
4+
oracledb~=3.0.0
5+
pandas~=2.2.3
66
python-dotenv~=1.0.1
77
Flask~=3.0.3
88
sqlalchemy>=2.0.38
9+
jproperties~=2.1.2

tests/Smokescreen/test_compartment_1.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import pytest
2-
from playwright.sync_api import Page
2+
from jproperties import Properties
3+
34
from my_pages import *
45
from utils.batch_processing import batch_processing
56

7+
8+
@pytest.fixture
9+
def smokescreen_properties() -> dict:
10+
"""
11+
Reads the 'bcss_smokescreen_tests.properties' file and populates a 'Properties' object.
12+
Returns a dictionary of properties for use in tests.
13+
14+
Returns:
15+
dict: A dictionary containing the values loaded from the 'bcss_smokescreen_tests.properties' file.
16+
"""
17+
configs = Properties()
18+
with open('bcss_smokescreen_tests.properties', 'rb') as read_prop:
19+
configs.load(read_prop)
20+
return configs.properties
21+
22+
623
@pytest.mark.smoke
724
@pytest.mark.compartment1
825
def test_create_invitations_plan(page: Page) -> None:
@@ -14,11 +31,11 @@ def test_create_invitations_plan(page: Page) -> None:
1431
# Create plan - England
1532
MainMenu(page).go_to_call_and_recall_page()
1633
CallAndRecall(page).go_to_planning_and_monitoring_page()
17-
InvitationsMonitoring(page).go_to_bcss001_invitations_plan_page()
34+
InvitationsMonitoring(page).go_to_invitation_plan_page(smokescreen_properties["c1_screening_centre_code"])
1835
InvitationsPlans(page).go_to_create_a_plan_page()
1936
logging.info("Setting daily invitation rate")
2037
CreateAPlan(page).click_set_all_button()
21-
CreateAPlan(page).fill_daily_invitation_rate_field("10")
38+
CreateAPlan(page).fill_daily_invitation_rate_field(smokescreen_properties["c1_daily_invitation_rate"])
2239
CreateAPlan(page).click_update_button()
2340
CreateAPlan(page).click_confirm_button()
2441
CreateAPlan(page).click_save_button()

tests/Smokescreen/test_compartment_2.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from utils.fit_kit_generation import create_fit_id_df
88
import logging
99

10+
1011
@pytest.mark.smoke
1112
@pytest.mark.smokescreen
1213
@pytest.mark.compartment2
@@ -22,7 +23,7 @@ def test_compartment_2(page: Page) -> None:
2223
logging.info(f"Logging FIT Device ID: {fit_device_id}")
2324
LogDevices(page).fill_fit_device_id_field(fit_device_id)
2425
sample_date = datetime.now().strftime("%#d %b %Y")
25-
logging.info("Setting sample date to todays date")
26+
logging.info("Setting sample date to today's date")
2627
LogDevices(page).fill_sample_date_field(sample_date)
2728
try:
2829
LogDevices(page).verify_successfully_logged_device_text()
@@ -33,7 +34,8 @@ def test_compartment_2(page: Page) -> None:
3334
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
3435
try:
3536
verify_subject_event_status_by_nhs_no(page, nhs_no, "S43 - Kit Returned and Logged (Initial Test)")
36-
logging.info(f"Successfully verified NHS number {nhs_no} with status S43 - Kit Returned and Logged (Initial Test)")
37+
logging.info(
38+
f"Successfully verified NHS number {nhs_no} with status S43 - Kit Returned and Logged (Initial Test)")
3739
except Exception as e:
3840
pytest.fail(f"Verification failed for NHS number {nhs_no}: {str(e)}")
3941

@@ -50,8 +52,7 @@ def test_compartment_2(page: Page) -> None:
5052
LogDevices(page).verify_successfully_logged_device_text()
5153
logging.info(f"{spoilt_fit_device_id} Successfully logged")
5254
except:
53-
pytest.fail(f"{spoilt_fit_device_id} unsuccessfully logged")
54-
55+
pytest.fail(f"{spoilt_fit_device_id} Unsuccessfully logged")
5556

5657
batch_processing(page, "S3", "Retest (Spoilt) (FIT)", "S11 - Retest Kit Sent (Spoilt)")
5758

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import logging
2+
from datetime import datetime
3+
4+
from my_pages import *
5+
from utils import fit_kit_logged
6+
from utils.batch_processing import batch_processing
7+
from utils.fit_kit_generation import create_fit_id_df
8+
from utils.fit_kit_logged import process_kit_data, update_kit_service_management_entity
9+
from utils.oracle import OracleDB
10+
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
11+
12+
13+
@pytest.mark.smokescreen
14+
@pytest.mark.compartment3
15+
def test_compartment_3(page: Page) -> None:
16+
UserTools.user_login(page, "Hub Manager State Registered")
17+
18+
# (STEP 1 ,2 & 3) find data , separate it into normal and abnormal, Add results to the test records in the KIT_QUEUE table (i.e. mimic receiving results from the middleware)
19+
# and get device IDs and their flags
20+
device_ids = process_kit_data()
21+
# Retrieve NHS numbers for each device_id and determine normal/abnormal status
22+
nhs_numbers = []
23+
normal_flags = []
24+
25+
for device_id, is_normal in device_ids:
26+
nhs_number = update_kit_service_management_entity(device_id, is_normal)
27+
nhs_numbers.append(nhs_number)
28+
normal_flags.append(is_normal) # Store the flag (True for normal, False for abnormal)
29+
30+
# (STEP - 4) Run two stored procedures to process any kit queue records at status BCSS_READY
31+
try:
32+
fit_kit_logged.execute_stored_procedures()
33+
logging.info("Stored procedures executed successfully.")
34+
except Exception as e:
35+
logging.error(f"Error executing stored procedures: {str(e)}")
36+
raise
37+
38+
# (STEP - 5) Check the results of the processed FIT kits have correctly updated the status of the associated subjects
39+
# Verify subject event status based on normal or abnormal classification
40+
for nhs_number, is_normal in zip(nhs_numbers, normal_flags):
41+
expected_status = "S2 - Normal" if is_normal else "A8 - Abnormal" # S2 for normal, A8 for abnormal
42+
logging.info(f"Verifying NHS number: {nhs_number} with expected status: {expected_status}")
43+
44+
try:
45+
verify_subject_event_status_by_nhs_no(page, nhs_number, expected_status)
46+
logging.info(f"Successfully verified NHS number {nhs_number} with status {expected_status}")
47+
except Exception as e:
48+
logging.error(f"Verification failed for NHS number {nhs_number} with status {expected_status}: {str(e)}")
49+
raise
50+
51+
# (Step 12) - Process S2 batch
52+
# Run batch processing function on S2 batch
53+
nhs_number_df = batch_processing(page, "S2", "Subject Result (Normal)", "S158 - Subject Discharge Sent (Normal)")
54+
OracleDB().exec_bcss_timed_events(nhs_number_df)
55+
56+
# (Step 13) - Process S158 batch
57+
# Run batch processing function on S158 batch
58+
nhs_number_df = batch_processing(page, "S158", "GP Result (Normal)", "S159 - GP Discharge Sent (Normal)")
59+
OracleDB().exec_bcss_timed_events(nhs_number_df)
60+
61+
# Log out
62+
Logout(page).log_out()

tests/bcss_tests.properties

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ----------------------------------
2+
# SCREENING CENTRES, CCGs, HUBS & GPs
3+
# ----------------------------------
4+
screening_centre_code=BCS001
5+
eng_screening_centre_id=23162
6+
eng_hub_id=23159
7+
gp_practice_code=C81001
8+
ccg_code=Z1Z1Z
9+
10+
# ----------------------------------
11+
# SUBJECT / PATIENT SEARCH TEST DATA
12+
# ----------------------------------
13+
nhs_number=966 529 9271
14+
forename=Pentagram
15+
surname=Absurd
16+
subject_dob=11/01/1934
17+
episode_closed_date=22/09/2020
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# ----------------------------------
2+
# compartment 1
3+
# ----------------------------------
4+
c1_daily_invitation_rate=10
5+
c1_screening_centre_code=BCS001
6+
7+
# ----------------------------------
8+
# compartment 2
9+
# ----------------------------------
10+
# c2_fit_kit_logging_test_org_id=23159
11+
# c2_eng_gfobt_kit_logging_test_org_id=23159
12+
13+
# ----------------------------------
14+
# compartment 3
15+
# ----------------------------------
16+
# c3_fit_kit_results_test_org_id=23159
17+
# c3_fit_kit_normal_result=75
18+
# c3_fit_kit_abnormal_result=150
19+
# c3_fit_kit_authorised_user=AUTO1
20+
# c3_fit_kit_analyser_code=HMJackalt1
21+
22+
# ----------------------------------
23+
# compartment 4
24+
# ----------------------------------
25+
# c4_eng_org_id=23159
26+
# c4_eng_centre_name=Wolverhampton
27+
# c4_eng_site_name=Royal Hospital
28+
# c4_eng_practitioner_id=243
29+
# c4_eng_practitioner_name=Arvind, Vanaja
30+
# c4_eng_practitioner_name=Macarena, Gave #use this for anonymised
31+
# c4_eng_practitioner_id_for_rebooking=870
32+
# c4_eng_practitioner_name_for_rebookings=Burns, Harriet
33+
34+
# ----------------------------------
35+
# compartment 6
36+
# ----------------------------------
37+
# c6_eng_org_id=23159
38+
# c6_eng_site_id=35317
39+
# c6_eng_practitioner_id=243
40+
# c6_eng_testing_clinician_id=805
41+
# c6_eng_aspirant_endoscopist_id=1731
42+
43+
# ----------------------------------
44+
# NUMBER OF KITS / SUBJECTS TO PROCESS IN EACH COMPARTMENT
45+
# ----------------------------------
46+
# NOTE: England gFOBT has been turned off (all values set to 0), properties have been left just in case for now
47+
48+
# ----------------------------------
49+
# compartment 1
50+
# ----------------------------------
51+
# c1_eng_number_of_batches_to_create=1
52+
53+
# ----------------------------------
54+
# compartment 2
55+
# ----------------------------------
56+
# c2_eng_number_of_fit_kits_to_log=8
57+
# c2_eng_number_of_gfobt_kits_to_log=0
58+
# ## Spare subjects (subjects required for subject creation check = fit kits to log + gfobt kits to log + spare subject count)
59+
# ## NOTE: Should be at least 1 due to poke the beast requiring a subject to log a fit kit for on National
60+
# c2_spare_subject_count=5
61+
62+
# ----------------------------------
63+
# compartment 3
64+
# ----------------------------------
65+
# c3_eng_number_of_abnormal_gfobt_kits_to_log=0
66+
# c3_eng_number_of_normal_gfobt_kits_to_log=0
67+
# c3_eng_number_of_weak_positive_gfobt_kits_to_log=0
68+
# c3_eng_number_of_abnormal_fit_kits=7
69+
# c3_eng_number_of_normal_fit_kits=1
70+
71+
# ----------------------------------
72+
# compartment 4
73+
# ----------------------------------
74+
# # note there is a max of 16 slots available each day
75+
# c4_eng_number_of_appointments_to_book=6
76+
77+
# ----------------------------------
78+
# compartment 5
79+
# ----------------------------------
80+
# c5_eng_number_of_screening_appts_to_attend=6
81+
82+
# ----------------------------------
83+
# compartment 6
84+
# ----------------------------------
85+
# c6_eng_number_of_normal_results_to_record=2
86+
# c6_eng_number_of_lnpcp_results_to_record=1
87+
# c6_eng_number_of_high_risk_findings_results_to_record=1
88+
# c6_eng_number_of_lnpcp_results_over_74_to_record=1
89+
# c6_eng_number_of_high_risk_findings_results_over_74_to_record=1

tests/test_call_and_recall_page.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22
from playwright.sync_api import Page, expect
33
from utils.click_helper import click
44
from pages.bcss_home_page import MainMenu
5-
from pages.login_page import BcssLoginPage
5+
from utils.user_tools import UserTools
6+
from jproperties import Properties
7+
8+
9+
@pytest.fixture
10+
def tests_properties() -> dict:
11+
"""
12+
Reads the 'bcss_tests.properties' file and populates a 'Properties' object.
13+
Returns a dictionary of properties for use in tests.
14+
15+
Returns:
16+
dict: A dictionary containing the values loaded from the 'bcss_tests.properties' file.
17+
"""
18+
configs = Properties()
19+
with open('bcss_tests.properties', 'rb') as read_prop:
20+
configs.load(read_prop)
21+
return configs.properties
622

723

824
@pytest.fixture(scope="function", autouse=True)
@@ -55,15 +71,15 @@ def test_call_and_recall_page_navigation(page: Page) -> None:
5571
expect(page.locator("#ntshPageTitle")).to_contain_text("Main Menu")
5672

5773

58-
def test_view_an_invitation_plan(page: Page) -> None:
74+
def test_view_an_invitation_plan(page: Page, tests_properties: dict) -> None:
5975
"""
6076
Confirms that an invitation plan can be viewed via a screening centre from the planning ad monitoring page
6177
"""
6278
# Go to planning and monitoring page
6379
click(page, page.get_by_role("link", name="Planning and Monitoring"))
6480

6581
# Select a screening centre
66-
click(page, page.get_by_role("link", name="BCS009"))
82+
page.get_by_role("link", name=tests_properties["screening_centre_code"]).click()
6783

6884
# Select an invitation plan
6985
click(page, page.get_by_role("row").nth(1).get_by_role("link"))

tests/test_gfobt_test_kits_page.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,24 @@ def test_create_a_qc_kit(page: Page) -> None:
5252
"""
5353
Confirms that a qc test kit can be created and that each of the dropdowns has an option set available for selection
5454
"""
55+
# 'Reading' dropdown locators
56+
reading1dropdown = page.locator("#A_C_Reading_999_0_0")
57+
reading2dropdown = page.locator("#A_C_Reading_999_0_1")
58+
reading3dropdown = page.locator("#A_C_Reading_999_1_0")
59+
reading4dropdown = page.locator("#A_C_Reading_999_1_1")
60+
reading5dropdown = page.locator("#A_C_Reading_999_2_0")
61+
reading6dropdown = page.locator("#A_C_Reading_999_2_1")
62+
5563
# Navigate to create QC kit page
5664
click(page, page.get_by_role("link", name="Create QC Kit"))
5765

5866
# Select QC kit drop down options
59-
page.locator("#A_C_Reading_999_0_0").select_option("NEGATIVE")
60-
page.locator("#A_C_Reading_999_0_1").select_option("POSITIVE")
61-
page.locator("#A_C_Reading_999_1_0").select_option("POSITIVE")
62-
page.locator("#A_C_Reading_999_1_1").select_option("UNUSED")
63-
page.locator("#A_C_Reading_999_2_0").select_option("NEGATIVE")
64-
page.locator("#A_C_Reading_999_2_1").select_option("POSITIVE")
67+
reading1dropdown.select_option("NEGATIVE")
68+
reading2dropdown.select_option("POSITIVE")
69+
reading3dropdown.select_option("POSITIVE")
70+
reading4dropdown.select_option("UNUSED")
71+
reading5dropdown.select_option("NEGATIVE")
72+
reading6dropdown.select_option("POSITIVE")
6573

6674
# Click save
6775
click(page, page.get_by_role("button", name="Save Kit"))

0 commit comments

Comments
 (0)