@@ -80,4 +80,81 @@ def test_example(page: Page) -> None:
8080 link_text = link .inner_text () # Get the link text dynamically
8181 link .click ()
8282 page .get_by_text ("Open In-Queue Processing Prepared Type : Original Priority : High Deadline : 17" ).click ()
83-
83+
84+
85+ from pypdf import PdfReader
86+
87+ @pytest .mark .wip2
88+ def test_example (page : Page ) -> None :
89+ page .goto ("/" )
90+ page .get_by_role ("textbox" , name = "Username" ).click ()
91+ page .get_by_role ("textbox" , name = "Username" ).fill ("BCSS401" )
92+ page .get_by_role ("textbox" , name = "Username" ).press ("Tab" )
93+ page .get_by_role ("textbox" , name = "Password" ).fill ("changeme" )
94+ page .get_by_role ("button" , name = "submit" ).click ()
95+
96+ # Print the batch of Pre-Invitation Letters
97+ page .get_by_role ("link" , name = "Communications Production" ).click ()
98+ page .get_by_role ("link" , name = "Active Batch List" ).click ()
99+ page .locator ("#eventCodeFilter" ).click ()
100+ page .locator ("#eventCodeFilter" ).fill ("S1" )
101+ page .locator ("#eventCodeFilter" ).press ("Enter" )
102+ pre_invitation_cells = page .locator ("//td[text()='Pre-invitation (FIT)']" )
103+
104+ for i in range (pre_invitation_cells .count ()):
105+ row = pre_invitation_cells .nth (i ).locator (".." ) # Get the parent row
106+
107+ # Check if the row contains "Prepared" or "Open"
108+ if row .locator ("td" , has_text = "Prepared" ).count () > 0 or row .locator ("td" , has_text = "Open" ).count () > 0 :
109+ break
110+ # # Find the first link in that row and click it
111+ # link = row.locator("a").first
112+ # link_text = link.inner_text() # Get the link text dynamically
113+ # link.click()
114+ else :
115+ page .get_by_role ("button" , name = "Prepare Batch" ).click ()
116+ page .wait_for_timeout (10000 )
117+
118+ # Start waiting for the download
119+ with page .expect_download () as download_info :
120+ # Perform the action that initiates download
121+ page .get_by_role ("button" , name = "Retrieve" ).click ()
122+ download = download_info .value
123+
124+ # Wait for the download process to complete and save the downloaded file somewhere
125+ download .save_as (f"/temp/{ download .suggested_filename } " )
126+
127+
128+ reader = PdfReader (f"/temp/{ download .suggested_filename } " )
129+ #For loop looping through all pages of the file to find the NHS Number
130+ for pages in reader .pages :
131+ text = pages .extract_text ()
132+ if "NHS No" in text :
133+ #If NHS number is found split the text by every new line into a list
134+ text = text .splitlines (True )
135+ for split_text in text :
136+ if "NHS No" in split_text :
137+ #If a string is found containing "NHS No" all characters but digits are stored into nhs_no
138+ nhs_no = res = "" .join ([ele for ele in split_text if ele .isdigit ()])
139+ break
140+ # print(nhs_no) 9849028742
141+ page .on ("dialog" , lambda dialog : dialog .accept ())
142+ page .get_by_role ("button" , name = "Confirm Printed" ).click ()
143+ expect (page .get_by_text ("Batch Successfully Archived" )).to_be_visible ()
144+ page .get_by_role ("link" , name = "Back" ).click ()
145+ page .get_by_role ("link" , name = "Archived Batch List" ).click ()
146+ page .get_by_role ("cell" , name = "Date Archived : Activate to" ).locator ("span" ).nth (1 ).click ()
147+ page .get_by_role ("cell" , name = "Date Archived : Activate to" ).click ()
148+ # Change below to check if first row is the same as the batch we just archived
149+ # expect(page.get_by_role("cell", name="S1").first).to_be_visible()
150+ # expect(page.get_by_role("cell", name="Pre-invitation (FIT)").first).to_be_visible()
151+ # expect(page.get_by_role("link", name="8848")).to_be_visible()
152+ page .get_by_role ("link" , name = "Main Menu" ).click ()
153+ page .get_by_role ("link" , name = "Screening Subject Search" ).click ()
154+ page .get_by_role ("textbox" , name = "NHS Number" ).click ()
155+ page .get_by_role ("textbox" , name = "NHS Number" ).fill (nhs_no )
156+ page .get_by_role ("button" , name = "Search" ).click ()
157+ expect (page .get_by_role ("cell" , name = "Subject Screening Summary" , exact = True )).to_be_visible ()
158+ page .get_by_role ("link" , name = "Main Menu" ).click ()
159+ page .get_by_role ("link" , name = "Communications Production" ).click ()
160+ page .get_by_role ("link" , name = "Active Batch List" ).click ()
0 commit comments