|
1 | 1 | import pytest |
2 | | -from pypdf import PdfReader |
3 | | -from playwright.sync_api import Page, expect |
4 | | -import pandas as pd |
5 | | -import os |
| 2 | +from playwright.sync_api import Page |
6 | 3 | from my_pages import * |
| 4 | +from utils.batch_processing import batch_processing |
| 5 | +from utils.oracle import exec_bcss_timed_events |
7 | 6 |
|
8 | 7 | # To Do: |
9 | | -# Create more POMs |
10 | | -# Add more fail states |
11 | | -# Add more logging to understand what is going on |
12 | | -# Convert import pages * into 1 line |
13 | | -# Move functions to utils |
14 | | -# Remove as many hard coded timeouts as possible |
15 | 8 | # Create a generic click() function -> this aims to solve an issue where sometimes it thinks it has clicked the element but the page does not change |
16 | 9 |
|
17 | 10 | @pytest.mark.wip |
@@ -41,113 +34,17 @@ def test_example(page: Page) -> None: |
41 | 34 | GenerateInvitations(page).wait_for_invitation_generation_complete() |
42 | 35 |
|
43 | 36 | # Print the batch of Pre-Invitation Letters |
44 | | - batch_processing(page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent") |
| 37 | + s1_nhs_no = batch_processing(page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent") |
| 38 | + exec_bcss_timed_events(s1_nhs_no) |
45 | 39 | batch_processing(page, "S1", "Pre-invitation (FIT) (digital leaflet)", "S9 - Pre-invitation Sent") |
46 | 40 |
|
47 | | - database_connection_exec("bcss_timed_events") |
48 | | - |
49 | 41 | # Print the batch of Invitation & Test Kit Letters |
50 | | - batch_processing(page, "S9", "Invitation & Test Kit (FIT)", "S10 - Invitation & Test Kit Sent") |
| 42 | + s9_nhs_no = batch_processing(page, "S9", "Invitation & Test Kit (FIT)", "S10 - Invitation & Test Kit Sent") |
| 43 | + exec_bcss_timed_events(s9_nhs_no) |
51 | 44 |
|
52 | 45 | # Print a set of reminder letters |
53 | 46 | batch_processing(page, "S10", "Test Kit Reminder", "S19 - Reminder of Initial Test Sent") |
54 | 47 |
|
55 | 48 | # Log out |
56 | 49 | NavigationBar(page).click_log_out_link() |
57 | 50 | Logout(page).verify_log_out_page() |
58 | | - |
59 | | -def batch_processing(page: Page, batch_type: str, batch_description: str, latest_event_status: str): |
60 | | - NavigationBar(page).click_main_menu_link() |
61 | | - MainMenu(page).go_to_communications_production_page() |
62 | | - CommunicationsProduction(page).go_to_active_batch_list_page() |
63 | | - ActiveBatchList(page).enter_event_code_filter(batch_type) |
64 | | - |
65 | | - batch_description_cells = page.locator(f"//td[text()='{batch_description}']") |
66 | | - |
67 | | - if batch_description_cells.count() == 0 and batch_description == "Pre-invitation (FIT) (digital leaflet)": |
68 | | - print(f"No S1 Pre-invitation (FIT) (digital leaflet) batch found. Skipping to next step") |
69 | | - return |
70 | | - elif batch_description_cells.count() == 0 and page.locator("td", has_text="No matching records found"): |
71 | | - pytest.fail(f"No {batch_type} {batch_description} batch found") |
72 | | - |
73 | | - for i in range(batch_description_cells.count()): |
74 | | - row = batch_description_cells.nth(i).locator("..") # Get the parent row |
75 | | - |
76 | | - # Check if the row contains "Prepared" or "Open" |
77 | | - if row.locator("td", has_text="Prepared").count() > 0 or row.locator("td", has_text="Open").count() > 0: |
78 | | - # Find the first link in that row and click it |
79 | | - link = row.locator("a").first |
80 | | - link_text = link.inner_text() # Get the batch id dynamically |
81 | | - link.click() |
82 | | - break |
83 | | - else: |
84 | | - pytest.fail(f"No open/prepared '{batch_type} - {batch_description}' batch found") |
85 | | - |
86 | | - ManageActiveBatch(page).click_prepare_button() |
87 | | - |
88 | | - ManageActiveBatch(page).reprepare_batch_text.wait_for() |
89 | | - |
90 | | - # This loops through each Retrieve button and clicks each one |
91 | | - retrieve_button_count = 0 |
92 | | - for retrieve_button in range (ManageActiveBatch(page).retrieve_button.count()): |
93 | | - retrieve_button_count += 1 |
94 | | - # Start waiting for the pdf download |
95 | | - with page.expect_download() as download_info: |
96 | | - # Perform the action that initiates download |
97 | | - ManageActiveBatch(page).retrieve_button.nth(retrieve_button-1).click() |
98 | | - download_file = download_info.value |
99 | | - file = download_file.suggested_filename |
100 | | - # Wait for the download process to complete and save the downloaded file in a temp folder |
101 | | - download_file.save_as(file) |
102 | | - if file.endswith(".pdf"): |
103 | | - nhs_no = pdf_Reader(file) |
104 | | - os.remove(file) # Deletes the file after extracting the necessary data |
105 | | - elif file.endswith(".csv"): |
106 | | - # csv_df = csv_Reader(file) # Currently no use in compartment 1, will be necessary for future compartments |
107 | | - os.remove(file) # Deletes the file after extracting the necessary data |
108 | | - |
109 | | - # This loops through each Confirm printed button and clicks each one |
110 | | - for _ in range (retrieve_button_count): |
111 | | - page.on("dialog", lambda dialog: dialog.accept()) |
112 | | - ManageActiveBatch(page).confirm_button.nth(0).click() |
113 | | - |
114 | | - ActiveBatchList(page).batch_successfully_archived_msg.wait_for() |
115 | | - |
116 | | - NavigationBar(page).click_main_menu_link() |
117 | | - MainMenu(page).go_to_communications_production_page() |
118 | | - CommunicationsProduction(page).go_to_archived_batch_list_page() |
119 | | - ArchivedBatchList(page).enter_id_filter(link_text) |
120 | | - ArchivedBatchList(page).verify_table_data(link_text) |
121 | | - |
122 | | - subject_search_by_nhs_no(page, nhs_no, latest_event_status) |
123 | | - |
124 | | -def pdf_Reader(file: str): |
125 | | - reader = PdfReader(file) |
126 | | - |
127 | | - # For loop looping through all pages of the file to find the NHS Number |
128 | | - for pages in reader.pages: |
129 | | - text = pages.extract_text() |
130 | | - if "NHS No" in text: |
131 | | - # If NHS number is found split the text by every new line into a list |
132 | | - text = text.splitlines(True) |
133 | | - for split_text in text: |
134 | | - if "NHS No" in split_text: |
135 | | - # If a string is found containing "NHS No" only digits are stored into nhs_no |
136 | | - nhs_no = "".join([ele for ele in split_text if ele.isdigit()]) |
137 | | - break |
138 | | - return nhs_no |
139 | | - |
140 | | -def csv_Reader(file: str): |
141 | | - csv_df = pd.read_csv(file) |
142 | | - return csv_df |
143 | | - |
144 | | -def subject_search_by_nhs_no(page: Page, nhs_no: str, latest_event_status: str): |
145 | | - NavigationBar(page).click_main_menu_link() |
146 | | - MainMenu(page).go_to_screening_subject_search_page() |
147 | | - SubjectScreeningPage(page).click_nhs_number_filter() |
148 | | - SubjectScreeningPage(page).nhs_number_filter.fill(nhs_no) |
149 | | - SubjectScreeningPage(page).nhs_number_filter.press("Enter") |
150 | | - SubjectScreeningPage(page).click_search_button() |
151 | | - SubjectScreeningSummary(page).verify_subject_screening_summary() |
152 | | - SubjectScreeningSummary(page).verify_latest_event_status_header() |
153 | | - SubjectScreeningSummary(page).verify_latest_event_status_value(latest_event_status) |
0 commit comments