@@ -28,30 +28,41 @@ def test_download_pdf(
2828):
2929 """
3030 C1756769: Verify that the user can Download a PDF
31+
32+ Notes:
33+ - Firefox is launched with a new profile that has default download settings.
34+ - This means the OS-level "Save File" dialog will appear for every download.
35+ - Selenium cannot interact with this native dialog directly, so the test
36+ must rely on fixed waits to give the OS time to render the dialog and to
37+ finish writing the file.
3138 """
32- pdf = GenericPdf (driver , pdf_url = fillable_pdf_url ).open ()
39+
40+ # Initialize objects
41+ pdf = GenericPdf (driver , pdf_url = fillable_pdf_url )
3342 keyboard = Controller ()
3443
3544 # Click the download button
45+ pdf .open ()
3646 download_button = pdf .get_element ("download-button" )
3747 download_button .click ()
3848
3949 # Allow time for the download dialog to appear and pressing handle the prompt
4050 time .sleep (2 )
4151 pdf .handle_os_download_confirmation (keyboard , sys_platform )
4252
43- # Allow time for the download to complete
44- time .sleep (3 )
45-
4653 # Set the expected download path and the expected PDF name
4754 file_name = "i-9.pdf"
4855 saved_pdf_location = os .path .join (downloads_folder , file_name )
4956
50- # Verify if the file exists
51- assert os .path .exists (saved_pdf_location ), (
52- f"The file was not downloaded to { saved_pdf_location } ."
53- )
57+ # Wait up to 10 seconds for the file to appear and finish downloading
58+ timeout = 10
59+ start = time .time ()
60+ while time .time () - start < timeout :
61+ if os .path .exists (saved_pdf_location ):
62+ break
63+ time .sleep (0.5 )
5464
55- print (
56- f"Test passed: The file { file_name } has been downloaded and is present at { saved_pdf_location } ."
65+ # Verify that the file was downloaded
66+ assert os .path .exists (saved_pdf_location ), (
67+ f"The file was not downloaded to { saved_pdf_location } after { timeout } seconds."
5768 )
0 commit comments