Skip to content

Commit 5bf1791

Browse files
Finished section 4 of the smoke screen tests
Added two packages to requirements.txt Started database connection
1 parent f3e0b24 commit 5bf1791

File tree

3 files changed

+61
-70
lines changed

3 files changed

+61
-70
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pytest-playwright>=0.5.1
22
pytest-html>=4.1.1
33
pytest-json-report>=1.5.0
4+
pypdf>=5.3.0
5+
oracledb>=2.5.1
Lines changed: 46 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import re
22
import pytest
3+
from pypdf import PdfReader
34
from playwright.sync_api import Page, expect
4-
5+
import oracledb
56

67
@pytest.mark.wip
78
def test_example(page: Page) -> None:
@@ -61,100 +62,75 @@ def test_example(page: Page) -> None:
6162
# Final check: ensure that the table now contains "Completed"
6263
expect(page.locator("#displayRS")).to_contain_text("Completed")
6364

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:
6469
# Print the batch of Pre-Invitation Letters
6570
page.get_by_role("link", name="Main Menu").click()
6671
page.get_by_role("link", name="Communications Production").click()
6772
page.get_by_role("link", name="Active Batch List").click()
6873
page.locator("#eventCodeFilter").click()
69-
page.locator("#eventCodeFilter").fill("S1")
74+
page.locator("#eventCodeFilter").fill(batch_type)
7075
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}']")
7277

7378
for i in range(pre_invitation_cells.count()):
7479
row = pre_invitation_cells.nth(i).locator("..") # Get the parent row
7580

7681
# 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:
7883
# Find the first link in that row and click it
7984
link = row.locator("a").first
8085
link_text = link.inner_text() # Get the link text dynamically
8186
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()
9587

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
106119

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
141120
page.on("dialog", lambda dialog: dialog.accept())
142121
page.get_by_role("button", name="Confirm Printed").click()
143122
expect(page.get_by_text("Batch Successfully Archived")).to_be_visible()
144123
page.get_by_role("link", name="Back").click()
145124
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+
152130
page.get_by_role("link", name="Main Menu").click()
153131
page.get_by_role("link", name="Screening Subject Search").click()
154132
page.get_by_role("textbox", name="NHS Number").click()
155133
page.get_by_role("textbox", name="NHS Number").fill(nhs_no)
134+
page.get_by_role("textbox", name="NHS Number").press("Enter")
156135
page.get_by_role("button", name="Search").click()
157136
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()

utils/oracle.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import getpass
2+
import oracledb
3+
4+
def database_connection():
5+
un = 'scott'
6+
cs = 'localhost/orclpdb'
7+
pw = getpass.getpass(f'Enter password for {un}@{cs}: ')
8+
9+
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
10+
with connection.cursor() as cursor:
11+
sql = """select sysdate from dual"""
12+
for r in cursor.execute(sql):
13+
print(r)

0 commit comments

Comments
 (0)