22from pypdf import PdfReader
33from playwright .sync_api import Page , expect
44import pandas as pd
5+ import os
56import sys
6- sys .path .append ("../utils " )
7+ sys .path .append ("../" )
78from utils .oracle import *
9+ from pages .bcss_home_page import *
10+ from pages .login_page import *
11+ from pages .communications_production_page import *
12+ from pages .call_and_recall_page import *
13+ from pages .active_batch_list_page import *
14+ from pages .archived_batch_list_page import *
15+ from pages .navigation_bar_links import *
16+ from pages .subject_screening_page import *
817
918@pytest .mark .wip
1019def test_example (page : Page ) -> None :
1120 page .goto ("/" )
12- page .get_by_role ("textbox" , name = "Username" ).click ()
13- page .get_by_role ("textbox" , name = "Username" ).fill ("BCSS401" )
14- page .get_by_role ("textbox" , name = "Username" ).press ("Tab" )
15- page .get_by_role ("textbox" , name = "Password" ).fill ("changeme" )
16- page .get_by_role ("button" , name = "submit" ).click ()
21+ BcssLoginPage (page ).login_as_user_bcss401 ()
1722
1823 # Create plan
19- page . get_by_role ( "link" , name = "Call and Recall" ). click ()
20- page . get_by_role ( "link" , name = "Planning and Monitoring" ). click ()
24+ MainMenu ( page ). go_to_call_and_recall_page ()
25+ CallAndRecall ( page ). go_to_planning_and_monitoring_page ()
2126 page .get_by_role ("link" , name = "BCS001" ).click ()
2227 page .get_by_role ("button" , name = "Create a Plan" ).click ()
2328 page .get_by_role ("link" , name = "Set all" ).click ()
@@ -31,9 +36,9 @@ def test_example(page: Page) -> None:
3136 page .locator ("#saveNote" ).get_by_role ("button" , name = "Save" ).click ()
3237
3338 # Generate Invitations
34- main_menu_available (page )
35- page . get_by_role ( "link" , name = "Call and Recall" ). click ()
36- page . get_by_role ( "link" , name = "Generate Invitations" ). click ()
39+ NavigationBar (page ). click_main_menu_link ( )
40+ MainMenu ( page ). go_to_call_and_recall_page ()
41+ CallAndRecall ( page ). go_to_generate_invitations_page ()
3742 page .get_by_role ("button" , name = "Generate Invitations" ).click ()
3843
3944 page .wait_for_selector ("#displayRS" , timeout = 5000 )
@@ -64,7 +69,7 @@ def test_example(page: Page) -> None:
6469
6570 # Print the batch of Pre-Invitation Letters
6671 batch_processing (page , "S1" , "Pre-invitation (FIT)" , "S9 - Pre-invitation Sent" )
67- batch_processing (page , "S1" , "Pre-invitation (FIT) (digital leaflet)" , "S9 - Pre-invitation Sent" ) # Sometimes it is "S10 - Invitation & Test Kit Sent"
72+ batch_processing (page , "S1" , "Pre-invitation (FIT) (digital leaflet)" , "S9 - Pre-invitation Sent" )
6873
6974 database_connection_exec ("bcss_timed_events" )
7075
@@ -75,16 +80,15 @@ def test_example(page: Page) -> None:
7580 batch_processing (page , "S10" , "Test Kit Reminder" , "S19 - Reminder of Initial Test Sent" )
7681
7782 # Log out
78- page . get_by_role ( "link" , name = "Log-out" ). click ()
83+ NavigationBar ( page ). click_log_out_link ()
7984 expect (page .get_by_role ("heading" , name = "You have logged out" )).to_be_visible ()
8085
8186def batch_processing (page : Page , batch_type : str , batch_description : str , latest_event_status : str ):
82- main_menu_available (page )
83- page .get_by_role ("link" , name = "Communications Production" ).click ()
84- page .get_by_role ("link" , name = "Active Batch List" ).click ()
85- page .locator ("#eventCodeFilter" ).click ()
86- page .locator ("#eventCodeFilter" ).fill (batch_type )
87- page .locator ("#eventCodeFilter" ).press ("Enter" )
87+ NavigationBar (page ).click_main_menu_link ()
88+ MainMenu (page ).go_to_communications_production_page ()
89+ CommunicationsProduction (page ).go_to_active_batch_list_page ()
90+ ActiveBatchList (page ).event_code_filter .click ()
91+ ActiveBatchList (page ).event_code_filter .fill (batch_type )
8892 pre_invitation_cells = page .locator (f"//td[text()='{ batch_description } ']" )
8993
9094 for i in range (pre_invitation_cells .count ()):
@@ -94,14 +98,14 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
9498 if row .locator ("td" , has_text = "Prepared" ).count () > 0 or row .locator ("td" , has_text = "Open" ).count () > 0 or row .locator ("td" , has_text = "Closed" ).count () > 0 :
9599 # Find the first link in that row and click it
96100 link = row .locator ("a" ).first
97- link_text = link .inner_text () # Get the link text dynamically
101+ link_text = link .inner_text () # Get the batch id dynamically
98102 link .click ()
99103 break
100104 else :
101- pytest .fail (f"No { batch_type } batch found" )
105+ pytest .fail (f"No open/prepared { batch_type } batch found" )
102106
103107 # Checks to see if batch is already prepared
104- page .wait_for_timeout (3000 ) # Without this timeout prepare_button is always set to false
108+ page .wait_for_timeout (1000 ) # Without this timeout prepare_button is always set to false
105109 prepare_button = page .get_by_role ("button" , name = "Prepare Batch" ).is_visible ()
106110
107111 #If not prepared it will click on the prepare button
@@ -124,24 +128,25 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
124128 page .wait_for_timeout (1000 )
125129 if file .endswith (".pdf" ):
126130 nhs_no = pdf_Reader (file )
131+ os .remove (file ) # Deletes the file after extracting the necessary data
127132 elif file .endswith (".csv" ):
128- csv_df = csv_Reader (file )
133+ csv_df = csv_Reader (file ) # Currently no use in compartment 1, will be necessary for future compartments
134+ os .remove (file ) # Deletes the file after extracting the necessary data
129135
130136 page .locator ('text="Confirm Printed"' ).nth (0 ).wait_for ()
131137 page .wait_for_timeout (1000 ) # This 1 second wait is to allow other Confirm printed buttons to show as they do not show up at the same time
132138
133139 # This loops through each Confirm printed button and clicks each one
134- for confirm_button in range (page .get_by_role ("button" , name = "Confirm Printed" ).count ()):
140+ for _ in range (page .get_by_role ("button" , name = "Confirm Printed" ).count ()):
135141 page .on ("dialog" , lambda dialog : dialog .accept ())
136142 page .get_by_role ("button" , name = "Confirm Printed" ).nth (0 ).click ()
137143 page .wait_for_timeout (1000 )
138144
139- main_menu_available (page )
140- page .get_by_role ("link" , name = "Communications Production" ).click ()
141- page .get_by_role ("link" , name = "Archived Batch List" ).click ()
142- page .locator ("#batchIdFilter" ).click ()
143- page .locator ("#batchIdFilter" ).fill (link_text )
144- page .locator ("#batchIdFilter" ).press ("Enter" )
145+ NavigationBar (page ).click_main_menu_link ()
146+ MainMenu (page ).go_to_communications_production_page ()
147+ CommunicationsProduction (page ).go_to_archived_batch_list_page ()
148+ ArchivedBatchList (page ).event_code_filter .click ()
149+ ArchivedBatchList (page ).event_code_filter .fill (link_text )
145150 expect (page .locator ("td" ).filter (has_text = link_text )).to_be_visible () # Checks to see if the batch is now archived
146151
147152 subject_search_by_nhs_no (page , nhs_no , latest_event_status )
@@ -167,18 +172,12 @@ def csv_Reader(file: str):
167172 return csv_df
168173
169174def subject_search_by_nhs_no (page : Page , nhs_no : str , latest_event_status : str ):
170- main_menu_available (page )
171- page . get_by_role ( "link" , name = "Screening Subject Search" ). click ()
172- page . get_by_role ( "textbox" , name = "NHS Number" ). click ()
173- page . get_by_role ( "textbox" , name = "NHS Number" ) .fill (nhs_no )
174- page . get_by_role ( "textbox" , name = "NHS Number" ) .press ("Enter" )
175- page . get_by_role ( "button" , name = "Search" ). click ()
175+ NavigationBar (page ). click_main_menu_link ( )
176+ MainMenu ( page ). go_to_screening_subject_search_page ()
177+ SubjectScreeningPage ( page ). click_nhs_number_filter ()
178+ SubjectScreeningPage ( page ). nhs_number_filter .fill (nhs_no )
179+ SubjectScreeningPage ( page ). nhs_number_filter .press ("Enter" )
180+ SubjectScreeningPage ( page ). click_search_button ()
176181 expect (page .get_by_role ("cell" , name = "Subject Screening Summary" , exact = True )).to_be_visible ()
177182 expect (page .get_by_role ("cell" , name = "Latest Event Status" , exact = True )).to_be_visible ()
178183 expect (page .get_by_role ("cell" , name = latest_event_status , exact = True )).to_be_visible ()
179-
180- def main_menu_available (page : str ):
181- is_main_menu_available = page .get_by_role ("link" , name = "Main Menu" ).is_visible ()
182-
183- if is_main_menu_available :
184- page .get_by_role ("link" , name = "Main Menu" ).click ()
0 commit comments