|
1 | 1 | import re |
2 | 2 | import pytest |
| 3 | +from pypdf import PdfReader |
3 | 4 | from playwright.sync_api import Page, expect |
4 | | - |
| 5 | +import oracledb |
5 | 6 |
|
6 | 7 | @pytest.mark.wip |
7 | 8 | def test_example(page: Page) -> None: |
@@ -61,100 +62,75 @@ def test_example(page: Page) -> None: |
61 | 62 | # Final check: ensure that the table now contains "Completed" |
62 | 63 | expect(page.locator("#displayRS")).to_contain_text("Completed") |
63 | 64 |
|
| 65 | + active_batch_processing(page, "S1", "Pre-invitation (FIT)") |
| 66 | + active_batch_processing(page, "S1", "Pre-invitation (FIT) (digital leaflet)") |
| 67 | + |
| 68 | +def active_batch_processing(page: Page, batch_type: str, batch_description: str) -> None: |
64 | 69 | # Print the batch of Pre-Invitation Letters |
65 | 70 | page.get_by_role("link", name="Main Menu").click() |
66 | 71 | page.get_by_role("link", name="Communications Production").click() |
67 | 72 | page.get_by_role("link", name="Active Batch List").click() |
68 | 73 | page.locator("#eventCodeFilter").click() |
69 | | - page.locator("#eventCodeFilter").fill("S1") |
| 74 | + page.locator("#eventCodeFilter").fill(batch_type) |
70 | 75 | page.locator("#eventCodeFilter").press("Enter") |
71 | | - pre_invitation_cells = page.locator("//td[text()='Pre-invitation (FIT)']") |
| 76 | + pre_invitation_cells = page.locator(f"//td[text()='{batch_description}']") |
72 | 77 |
|
73 | 78 | for i in range(pre_invitation_cells.count()): |
74 | 79 | row = pre_invitation_cells.nth(i).locator("..") # Get the parent row |
75 | 80 |
|
76 | 81 | # 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: |
| 82 | + 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: |
78 | 83 | # Find the first link in that row and click it |
79 | 84 | link = row.locator("a").first |
80 | 85 | link_text = link.inner_text() # Get the link text dynamically |
81 | 86 | link.click() |
82 | | - page.get_by_text("Open In-Queue Processing Prepared Type : Original Priority : High Deadline : 17").click() |
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 | 87 |
|
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 |
| 88 | + # Checks to see if batch is already prepared |
| 89 | + page.wait_for_timeout(3000) # Without this timeout prepare_button is always set to false |
| 90 | + prepare_button = page.get_by_role("button", name="Prepare Batch").is_visible() |
| 91 | + |
| 92 | + #If not prepared it will click on the prepare button and wait 5 seconds (ideally would be a loop) |
| 93 | + if prepare_button: |
| 94 | + page.get_by_role("button", name="Prepare Batch").click() |
| 95 | + page.wait_for_timeout(5000) |
| 96 | + |
| 97 | + # Start waiting for the download |
| 98 | + with page.expect_download() as download_info: |
| 99 | + # Perform the action that initiates download |
| 100 | + page.get_by_role("button", name="Retrieve").click() |
| 101 | + download = download_info.value |
| 102 | + |
| 103 | + # Wait for the download process to complete and save the downloaded file in a temp folder |
| 104 | + download.save_as(f"/temp/{download.suggested_filename}") |
| 105 | + |
| 106 | + reader = PdfReader(f"/temp/{download.suggested_filename}") |
| 107 | + |
| 108 | + # For loop looping through all pages of the file to find the NHS Number |
| 109 | + for pages in reader.pages: |
| 110 | + text = pages.extract_text() |
| 111 | + if "NHS No" in text: |
| 112 | + # If NHS number is found split the text by every new line into a list |
| 113 | + text = text.splitlines(True) |
| 114 | + for split_text in text: |
| 115 | + if "NHS No" in split_text: |
| 116 | + # If a string is found containing "NHS No" all characters but digits are stored into nhs_no |
| 117 | + nhs_no = res = "".join([ele for ele in split_text if ele.isdigit()]) |
| 118 | + break |
106 | 119 |
|
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 | 120 | page.on("dialog", lambda dialog: dialog.accept()) |
142 | 121 | page.get_by_role("button", name="Confirm Printed").click() |
143 | 122 | expect(page.get_by_text("Batch Successfully Archived")).to_be_visible() |
144 | 123 | page.get_by_role("link", name="Back").click() |
145 | 124 | 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() |
| 125 | + page.locator("#batchIdFilter").click() |
| 126 | + page.locator("#batchIdFilter").fill(link_text) |
| 127 | + page.locator("#batchIdFilter").press("Enter") |
| 128 | + expect(page.locator("td").filter(has_text=link_text)).to_be_visible() |
| 129 | + |
152 | 130 | page.get_by_role("link", name="Main Menu").click() |
153 | 131 | page.get_by_role("link", name="Screening Subject Search").click() |
154 | 132 | page.get_by_role("textbox", name="NHS Number").click() |
155 | 133 | page.get_by_role("textbox", name="NHS Number").fill(nhs_no) |
| 134 | + page.get_by_role("textbox", name="NHS Number").press("Enter") |
156 | 135 | page.get_by_role("button", name="Search").click() |
157 | 136 | 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