Skip to content

Commit f0d3c7d

Browse files
Added logging to C1 and added pytest parks to pytest.ini
1 parent 2f85b4e commit f0d3c7d

File tree

8 files changed

+138
-129
lines changed

8 files changed

+138
-129
lines changed

pages/generate_invitations_page.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from playwright.sync_api import Page, expect
22
import pytest
3-
3+
import logging
44

55
class GenerateInvitations:
66
def __init__(self, page: Page):
@@ -32,6 +32,7 @@ def wait_for_invitation_generation_complete(self):
3232
elapsed = 0
3333

3434
# Loop until the table no longer contains "Queued"
35+
logging.info(f"Waiting for successful generation")
3536
while elapsed < timeout: # there may be a stored procedure to speed this process up
3637
table_text = self.displayRS.text_content()
3738
if "Queued" in table_text or "In Progress" in table_text:
@@ -45,8 +46,13 @@ def wait_for_invitation_generation_complete(self):
4546
break
4647

4748
# Final check: ensure that the table now contains "Completed"
48-
expect(self.displayRS).to_contain_text("Completed")
49+
try:
50+
expect(self.displayRS).to_contain_text("Completed")
51+
logging.info("Invitations successfully generated")
52+
logging.info(f"Invitations took {elapsed/1000} seconds to generate")
53+
except Exception as e:
54+
pytest.fail("Invitations not generated successfully")
4955

5056
value = self.planned_invitations_total.text_content().strip() # Get text and remove extra spaces
51-
if int(value) <= 5:
57+
if int(value) < 5:
5258
pytest.fail("There are less than 5 invitations generated")

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ markers =
2727
utils: test setup and support methods
2828
smoke: tests designed to run as part of the smokescreen regression test suite
2929
wip: tests that are currently in progress
30+
smokescreen: all compartments to be run as part of the smokescreen
31+
compartment1: only for compartment 1
32+
compartment2: only for compartment 2
33+
compartment3: only for compartment 3

tests/Smokescreen/test_compartment_1.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
@pytest.mark.smoke
88
@pytest.mark.smokescreen
9+
@pytest.mark.compartment1
910
def test_compartment_1(page: Page) -> None:
10-
11-
page.goto("/")
12-
BcssLoginPage(page).login_as_user("BCSS401")
11+
UserTools.user_login(page, "Hub Manager State Registered")
1312

1413
# Create plan - England
1514
MainMenu(page).go_to_call_and_recall_page()
1615
CallAndRecall(page).go_to_planning_and_monitoring_page()
1716
InvitationsMonitoring(page).go_to_bcss001_invitations_plan_page()
1817
InvitationsPlans(page).go_to_create_a_plan_page()
18+
logging.info("Setting daily invitation rate")
1919
CreateAPlan(page).click_set_all_button()
2020
CreateAPlan(page).fill_daily_invitation_rate_field("10")
2121
CreateAPlan(page).click_update_button()
@@ -29,24 +29,24 @@ def test_compartment_1(page: Page) -> None:
2929
NavigationBar(page).click_main_menu_link()
3030
MainMenu(page).go_to_call_and_recall_page()
3131
CallAndRecall(page).go_to_generate_invitations_page()
32+
logging.info("Generating Invitations")
3233
GenerateInvitations(page).click_generate_invitations_button()
3334
GenerateInvitations(page).wait_for_invitation_generation_complete()
3435

3536
# Print the batch of Pre-Invitation Letters - England
3637
batch_processing(page, "S1", "Pre-invitation (FIT) (digital leaflet)", "S9 - Pre-invitation Sent")
3738
nhs_number_df = batch_processing(page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent")
38-
for index, row in nhs_number_df.iterrows():
39-
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
39+
OracleDB().exec_bcss_timed_events(nhs_number_df)
4040

4141
# Print the batch of Invitation & Test Kit Letters - England
4242
nhs_number_df = batch_processing(page, "S9", "Invitation & Test Kit (FIT)", "S10 - Invitation & Test Kit Sent")
43-
for index, row in nhs_number_df.iterrows():
44-
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
43+
OracleDB().exec_bcss_timed_events(nhs_number_df)
4544

4645
# Print a set of reminder letters
4746
batch_processing(page, "S10", "Test Kit Reminder", "S19 - Reminder of Initial Test Sent")
4847

4948
# Log out
49+
logging.info("Logging Out")
5050
NavigationBar(page).click_log_out_link()
5151
Logout(page).verify_log_out_page()
5252
page.close()

tests/Smokescreen/test_compartment_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99

1010
@pytest.mark.smokescreen
11+
@pytest.mark.compartment2
1112
def test_compartment_2(page: Page) -> None:
12-
page.goto("/")
13-
BcssLoginPage(page).login_as_user("BCSS401")
13+
UserTools.user_login(page, "Hub Manager State Registered")
1414

1515
MainMenu(page).go_to_fit_test_kits_page()
1616
FITTestKits(page).go_to_log_devices_page()

tests/Smokescreen/test_compartment_3.py

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from utils.oracle import OracleDB
1010
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
1111

12-
13-
@pytest.mark.wip2
12+
@pytest.mark.smokescreen
13+
@pytest.mark.compartment3
1414
def test_compartment_3(page: Page) -> None:
1515
UserTools.user_login(page, "Hub Manager State Registered")
1616

@@ -45,49 +45,17 @@ def test_compartment_3(page: Page) -> None:
4545
logging.error(f"Verification failed for NHS number {nhs_number} with status {expected_status}: {str(e)}")
4646
raise
4747

48-
49-
# Navigate to log devices page
50-
MainMenu(page).go_to_fit_test_kits_page()
51-
FITTestKits(page).go_to_log_devices_page()
52-
53-
# Get a fit device id
54-
subjectdf = create_fit_id_df()
55-
56-
# Log fit device
57-
for subject in range(4):
58-
fit_device_id = subjectdf["fit_device_id"].iloc[subject]
59-
LogDevices(page).fill_fit_device_id_field(fit_device_id)
60-
sample_date = datetime.now().strftime("%#d %b %Y")
61-
LogDevices(page).fill_sample_date_field(sample_date)
62-
LogDevices(page).verify_successfully_logged_device_text()
63-
64-
# Check statuses of 'normal' FIT kit subjects has moved to S2
65-
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
66-
verify_subject_event_status_by_nhs_no(page, nhs_no, "S2 - Normal")
67-
68-
# Check status of 'abnormal' FIT kit subjects has moved to A8
69-
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
70-
verify_subject_event_status_by_nhs_no(page, nhs_no, "A8 - Abnormal")
71-
7248
# (Step 12) - Process S2 batch
7349
# Run batch processing function on S2 batch
74-
batch_processing(page, "S2", "Normal", "S2 - Normal")
75-
nhs_number_df = batch_processing(page, "S2", "Normal", "S2 - Normal")
76-
for index, row in nhs_number_df.iterrows():
77-
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
78-
79-
# Verify Status of subject is updated to S158
80-
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
81-
verify_subject_event_status_by_nhs_no(page, nhs_no, "S158")
50+
nhs_number_df = batch_processing(page, "S2", "Subject Result (Normal)", "S158 - Subject Discharge Sent (Normal)")
51+
OracleDB().exec_bcss_timed_events(nhs_number_df)
8252

8353
# (Step 13) - Process S158 batch
8454
# Run batch processing function on S158 batch
85-
batch_processing(page, "S158", "Normal result letter sent to subject", "S158 - Normal result letter sent to subject")
86-
nhs_number_df = batch_processing(page, "S158", "Normal result letter sent to subject", "S158 - Normal result letter sent to subject")
87-
for index, row in nhs_number_df.iterrows():
88-
OracleDB().exec_bcss_timed_events(row["subject_nhs_number"])
89-
90-
# Verify Status of subject is updated to S159
91-
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
92-
verify_subject_event_status_by_nhs_no(page, nhs_no, "S159 - Normal result letter sent to GP")
55+
nhs_number_df = batch_processing(page, "S158", "GP Result (Normal)", "S159 - GP Discharge Sent (Normal)")
56+
OracleDB().exec_bcss_timed_events(nhs_number_df)
9357

58+
# Log out
59+
NavigationBar(page).click_log_out_link()
60+
Logout(page).verify_log_out_page()
61+
page.close()

utils/batch_processing.py

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
from pages.active_batch_list_page import ActiveBatchList
55
from pages.manage_active_batch_page import ManageActiveBatch
66
from pages.archived_batch_list_page import ArchivedBatchList
7-
from utils.pdf_reader import extract_nhs_no_from_pdf
87
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
98
from utils.get_nhs_no_from_batch_id import get_nhs_no_from_batch_id
109
import os
1110
import pytest
1211
from playwright.sync_api import Page
12+
import logging
1313

1414
def batch_processing(page: Page, batch_type: str, batch_description: str, latest_event_status: str):
15+
logging.info(f"Processing {batch_type} - {batch_description} batch")
1516
NavigationBar(page).click_main_menu_link()
1617
MainMenu(page).go_to_communications_production_page()
1718
CommunicationsProduction(page).go_to_active_batch_list_page()
@@ -20,59 +21,81 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
2021
batch_description_cells = page.locator(f"//td[text()='{batch_description}']")
2122

2223
if batch_description_cells.count() == 0 and batch_description == "Pre-invitation (FIT) (digital leaflet)":
23-
print(f"No S1 Pre-invitation (FIT) (digital leaflet) batch found. Skipping to next step")
24+
logging.warning("No S1 Pre-invitation (FIT) (digital leaflet) batch found. Skipping to next step")
2425
return
2526
elif batch_description_cells.count() == 0 and page.locator("td", has_text="No matching records found"):
2627
pytest.fail(f"No {batch_type} {batch_description} batch found")
2728

2829
for i in range(batch_description_cells.count()):
2930
row = batch_description_cells.nth(i).locator("..") # Get the parent row
3031

31-
# Check if the row contains "Prepared" or "Open"
32-
if row.locator("td", has_text="Prepared").count() > 0 or row.locator("td", has_text="Open").count() > 0:
32+
# Check if the row contains "Open"
33+
if row.locator("td", has_text="Open").count() > 0:
3334
# Find the first link in that row and click it
3435
link = row.locator("a").first
3536
link_text = link.inner_text() # Get the batch id dynamically
36-
nhs_no_df = get_nhs_no_from_batch_id(link_text)
37+
try:
38+
logging.info(f"Attempting to get NHS Numbers for batch: {link_text} from the DB")
39+
nhs_no_df = get_nhs_no_from_batch_id(link_text)
40+
logging.info(f"Successfully retrieved NHS Numbers from batch: {link_text}")
41+
except Exception as e:
42+
logging.error(f"Failed to retrieve NHS Numbers from batch: {link_text}")
3743
link.click()
3844
break
3945
else:
40-
pytest.fail(f"No open/prepared '{batch_type} - {batch_description}' batch found")
46+
pytest.fail(f"No open '{batch_type} - {batch_description}' batch found")
4147

4248
ManageActiveBatch(page).click_prepare_button()
4349
page.wait_for_timeout(1000) # This one second timeout does not affect the time to execute, as it is just used to ensure the reprepare batch button is clicked and does not instantly advance to the next step
4450
ManageActiveBatch(page).reprepare_batch_text.wait_for()
4551

4652
# This loops through each Retrieve button and clicks each one
4753
retrieve_button_count = 0
48-
for retrieve_button in range (ManageActiveBatch(page).retrieve_button.count()):
49-
retrieve_button_count += 1
50-
# Start waiting for the pdf download
51-
with page.expect_download() as download_info:
52-
# Perform the action that initiates download
53-
ManageActiveBatch(page).retrieve_button.nth(retrieve_button-1).click()
54-
download_file = download_info.value
55-
file = download_file.suggested_filename
56-
# Wait for the download process to complete and save the downloaded file in a temp folder
57-
download_file.save_as(file)
58-
if file.endswith(".pdf"):
59-
os.remove(file) # Deletes the file after extracting the necessary data
60-
elif file.endswith(".csv"):
54+
try:
55+
for retrieve_button in range (ManageActiveBatch(page).retrieve_button.count()):
56+
retrieve_button_count += 1
57+
logging.info(f"Clicking retrieve button {retrieve_button_count}")
58+
# Start waiting for the pdf download
59+
with page.expect_download() as download_info:
60+
# Perform the action that initiates download
61+
ManageActiveBatch(page).retrieve_button.nth(retrieve_button-1).click()
62+
download_file = download_info.value
63+
file = download_file.suggested_filename
64+
# Wait for the download process to complete and save the downloaded file in a temp folder
65+
download_file.save_as(file)
6166
os.remove(file) # Deletes the file after extracting the necessary data
67+
except Exception as e:
68+
logging.error(f"No retrieve button available to click: {str(e)}")
6269

6370
# This loops through each Confirm printed button and clicks each one
64-
for _ in range (retrieve_button_count):
65-
page.on("dialog", lambda dialog: dialog.accept())
66-
ManageActiveBatch(page).confirm_button.nth(0).click()
71+
try:
72+
for confirm_printed_button in range (retrieve_button_count):
73+
logging.info(f"Clicking confirm printed button {confirm_printed_button+1}")
74+
page.once("dialog", lambda dialog: dialog.accept())
75+
ManageActiveBatch(page).confirm_button.nth(0).click()
76+
except Exception as e:
77+
logging.error(f"No confirm printed button available to click: {str(e)}")
6778

68-
ActiveBatchList(page).batch_successfully_archived_msg.wait_for()
79+
try:
80+
ActiveBatchList(page).batch_successfully_archived_msg.wait_for()
81+
logging.info(f"Batch {link_text} successfully archived")
82+
except Exception as e:
83+
logging.error(f"Batch successfully archived message is not shown: {str(e)}")
6984

7085
NavigationBar(page).click_main_menu_link()
7186
MainMenu(page).go_to_communications_production_page()
7287
CommunicationsProduction(page).go_to_archived_batch_list_page()
7388
ArchivedBatchList(page).enter_id_filter(link_text)
74-
ArchivedBatchList(page).verify_table_data(link_text)
89+
try:
90+
ArchivedBatchList(page).verify_table_data(link_text)
91+
logging.info(f"Batch {link_text} visible in archived batch list")
92+
except Exception:
93+
logging.error(f"Batch {link_text} not visible in archived batch list")
7594

7695
first_nhs_no = nhs_no_df["subject_nhs_number"].iloc[0]
77-
verify_subject_event_status_by_nhs_no(page, first_nhs_no, latest_event_status)
96+
try:
97+
verify_subject_event_status_by_nhs_no(page, first_nhs_no, latest_event_status)
98+
logging.info(f"Successfully verified NHS number {first_nhs_no} with status {latest_event_status}")
99+
except Exception as e:
100+
logging.error(f"Verification failed for NHS number {first_nhs_no} with status {latest_event_status}: {str(e)}")
78101
return nhs_no_df

utils/fit_kit_logged.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pandas as pd
33
from datetime import datetime
44
import logging
5-
5+
import pytest
66

77

88
def process_kit_data():
@@ -21,7 +21,7 @@ def process_kit_data():
2121
logging.info(f"Processing normal kit with Device ID: {device_id}") # Logging normal device_id
2222
device_ids.append((device_id, True)) # Add to the list with normal flag
2323
else:
24-
logging.warning("No normal kits found for processing.") # Log warning
24+
pytest.fail("No normal kits found for processing.")
2525

2626
# Process abnormal kits (multiple, loop through)
2727
if not abnormal_fit_kit_df.empty:
@@ -30,7 +30,7 @@ def process_kit_data():
3030
logging.info(f"Processing abnormal kit with Device ID: {device_id}") # Logging abnormal device_id
3131
device_ids.append((device_id, False)) # Add to the list with abnormal flag
3232
else:
33-
logging.warning("No abnormal kits found for processing.") # Log warning
33+
pytest.fail("No abnormal kits found for processing.")
3434

3535
return device_ids
3636

0 commit comments

Comments
 (0)