File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,15 @@ def delete_files_regex_string():
1818 return r".*i-9.pdf"
1919
2020
21+ def wait_for_file_download (file_path , timeout = 10 , interval = 0.5 ):
22+ start = time .time ()
23+ while time .time () - start < timeout :
24+ if os .path .exists (file_path ):
25+ return True
26+ time .sleep (interval )
27+ return False
28+
29+
2130@pytest .mark .headed
2231def test_download_pdf (
2332 driver : Firefox ,
@@ -54,14 +63,6 @@ def test_download_pdf(
5463 saved_pdf_location = os .path .join (downloads_folder , file_name )
5564
5665 # Wait up to 10 seconds for the file to appear and finish downloading
57- timeout = 10
58- start = time .time ()
59- while time .time () - start < timeout :
60- if os .path .exists (saved_pdf_location ):
61- break
62- time .sleep (0.5 )
63-
64- # Verify that the file was downloaded
65- assert os .path .exists (saved_pdf_location ), (
66- f"The file was not downloaded to { saved_pdf_location } after { timeout } seconds."
66+ assert wait_for_file_download (saved_pdf_location , timeout = 10 ), (
67+ f"File not found: { saved_pdf_location } "
6768 )
You can’t perform that action at this time.
0 commit comments