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