Skip to content

Commit 0b92324

Browse files
Removing the majority of hard coded timeouts
1 parent b166293 commit 0b92324

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

pages/manage_active_batch_page.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def __init__(self, page: Page):
1111
self.prepare_button_text = self.page.locator('text="Prepare Batch"')
1212
self.retrieve_button_text = self.page.locator('text="Retrieve"')
1313
self.confirm_button_text = self.page.locator('text="Confirm Printed"')
14+
self.reprepare_batch_text = self.page.locator('text="Re-Prepare Batch"')
1415

1516
def click_prepare_button(self):
1617
self.prepare_button.click()

pages/navigation_bar_links.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ def __init__(self, page: Page):
1010
self.help_link = self.page.get_by_role("link", name="Help")
1111
self.log_out_link = self.page.get_by_role("link", name="Log-out")
1212

13-
def click_main_menu_link(self): # change to check if URL is correct
14-
for _ in range(3): # Try up to 3 times
15-
self.page.wait_for_timeout(2000) # Wait for 2 seconds before trying (as sometimes this button is clicked as a redirect happens)
16-
if self.main_menu_link.is_visible():
17-
self.main_menu_link.click()
18-
return # Exit if successful
13+
def click_main_menu_link(self):
14+
self.main_menu_link.click()
1915

2016
def click_back_link(self):
2117
self.back_link.click()

tests/Smokescreen/test_compartment_1.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def test_example(page: Page) -> None:
3131
CreateAPlan(page).click_save_button()
3232
CreateAPlan(page).fill_note_field("test data")
3333
CreateAPlan(page).click_saveNote_button()
34+
expect(page).to_have_url("https://bcss-bcss-18680-ddc-bcss.k8s-nonprod.texasplatform.uk/invitation/plan/23159/23162/")
3435

3536
# Generate Invitations
3637
NavigationBar(page).click_main_menu_link()
@@ -45,7 +46,7 @@ def test_example(page: Page) -> None:
4546

4647
# Set timeout parameters
4748
timeout = 120000 # Total timeout of 120 seconds (in milliseconds)
48-
wait_interval = 10000 # Wait 10 seconds between refreshes (in milliseconds)
49+
wait_interval = 5000 # Wait 5 seconds between refreshes (in milliseconds)
4950
elapsed = 0
5051

5152
# Loop until the table no longer contains "Queued"
@@ -106,19 +107,13 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
106107
else:
107108
pytest.fail(f"No open/prepared '{batch_type} - {batch_description}' batch found")
108109

109-
# Checks to see if batch is already prepared
110-
page.wait_for_timeout(3000) # Without this timeout prepare_button is always set to false
111-
prepare_button = ManageActiveBatch(page).prepare_button_text.is_visible()
112-
113-
#If not prepared it will click on the prepare button
114-
if prepare_button:
115-
ManageActiveBatch(page).click_prepare_button()
116-
117-
ManageActiveBatch(page).retrieve_button_text.nth(0).wait_for()
118-
page.wait_for_timeout(5000) # This 5 second wait is to allow other Retrieve buttons to show as they do not show up at the same time
110+
ManageActiveBatch(page).click_prepare_button()
119111

112+
ManageActiveBatch(page).reprepare_batch_text.wait_for()
113+
retrieve_button_count = 0
120114
# This loops through each Retrieve button and clicks each one
121115
for retrieve_button in range (ManageActiveBatch(page).retrieve_button.count()):
116+
retrieve_button_count += 1
122117
# Start waiting for the pdf download
123118
with page.expect_download() as download_info:
124119
# Perform the action that initiates download
@@ -127,24 +122,19 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
127122
file = download_file.suggested_filename
128123
# Wait for the download process to complete and save the downloaded file in a temp folder
129124
download_file.save_as(file)
130-
page.wait_for_timeout(1000)
131125
if file.endswith(".pdf"):
132126
nhs_no = pdf_Reader(file)
133127
os.remove(file) # Deletes the file after extracting the necessary data
134128
elif file.endswith(".csv"):
135129
csv_df = csv_Reader(file) # Currently no use in compartment 1, will be necessary for future compartments
136130
os.remove(file) # Deletes the file after extracting the necessary data
137131

138-
ManageActiveBatch(page).confirm_button_text.nth(0).wait_for()
139-
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
140-
141132
# This loops through each Confirm printed button and clicks each one
142-
for _ in range (ManageActiveBatch(page).confirm_button.count()):
133+
for _ in range (retrieve_button_count):
143134
page.on("dialog", lambda dialog: dialog.accept())
144135
ManageActiveBatch(page).confirm_button.nth(0).click()
145-
page.wait_for_timeout(1000)
146136

147-
# Add wait for batch successfully archived
137+
page.locator('text="Batch Successfully Archived and Printed"').wait_for()
148138

149139
NavigationBar(page).click_main_menu_link()
150140
MainMenu(page).go_to_communications_production_page()

utils/oracle.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def database_connection_exec(procedure: str): # To use when "exec xxxx" (stored
1414
with connection.cursor() as cursor:
1515
for r in cursor.callproc(procedure):
1616
print(r)
17-
connection.close()
1817

1918
def database_connection_query(sql: str): # To use when "select a from b"
2019
load_dotenv()
@@ -26,5 +25,4 @@ def database_connection_query(sql: str): # To use when "select a from b"
2625
with connection.cursor() as cursor:
2726
for r in cursor.execute(sql):
2827
print(r)
29-
connection.close()
3028
return r

0 commit comments

Comments
 (0)