1
+ import os
2
+ import time
3
+ import platform
4
+ import pytest
5
+ from selenium .webdriver import Firefox
6
+ from selenium .webdriver .common .by import By
7
+ from pynput .keyboard import Controller , Key
8
+
9
+ from modules .browser_object_navigation import Navigation
10
+ from modules .page_object import GenericPdf
11
+
12
+ @pytest .fixture ()
13
+ def add_prefs ():
14
+ return []
15
+
16
+ def test_pdf_download (driver : Firefox , fillable_pdf_url : str ):
17
+ """
18
+ C3932: PDF files can be successfully downloaded via pdf.js
19
+ """
20
+ GenericPdf (driver , pdf_url = fillable_pdf_url ).open ()
21
+ nav = Navigation (driver )
22
+ keyboard = Controller ()
23
+
24
+ # Click the download button
25
+ download_button = driver .find_element (By .ID , "download" )
26
+ download_button .click ()
27
+
28
+ # Allow time for the download dialog m to appear and pressing enter to download
29
+ time .sleep (2 )
30
+ keyboard .press (Key .enter )
31
+ keyboard .release (Key .enter )
32
+
33
+ # Allow time for the download to complete
34
+ time .sleep (2 )
35
+
36
+ # Determine the platform and set the expected download path
37
+ this_platform = platform .system ()
38
+ saved_pdf_location = ""
39
+ file_name = "i-9.pdf"
40
+
41
+ if this_platform == "Windows" :
42
+ user = os .environ .get ("USERNAME" )
43
+ saved_pdf_location = f"C:\\ Users\\ { user } \\ Downloads\\ { file_name } "
44
+ elif this_platform == "Darwin" : # MacOS
45
+ user = os .environ .get ("USER" )
46
+ saved_pdf_location = f"/Users/{ user } /Downloads/{ file_name } "
47
+ elif this_platform == "Linux" :
48
+ user = os .environ .get ("USER" )
49
+ saved_pdf_location = f"/home/{ user } /Downloads/{ file_name } "
50
+
51
+ # Verify if the file exists
52
+ assert os .path .exists (saved_pdf_location ), f"The file was not downloaded to { saved_pdf_location } ."
53
+
54
+ print (f"Test passed: The file { file_name } has been downloaded and is present at { saved_pdf_location } ." )
0 commit comments