Skip to content

Commit 77fd28b

Browse files
Merge pull request #162 from mozilla/vs/testPDFdownload
Vs/test pdf download
2 parents d1b24c6 + 7f74664 commit 77fd28b

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ def sys_platform():
167167
return platform.system()
168168

169169

170+
@pytest.fixture()
171+
def downloads_folder(sys_platform):
172+
"""Return the downloads folder location for this OS"""
173+
if sys_platform == "Windows":
174+
user = os.environ.get("USERNAME")
175+
return f"C:\\Users\\{user}\\Downloads"
176+
elif sys_platform == "Darwin": # MacOS
177+
user = os.environ.get("USER")
178+
return f"/Users/{user}/Downloads"
179+
elif sys_platform == "Linux":
180+
user = os.environ.get("USER")
181+
return f"/home/{user}/Downloads"
182+
183+
170184
@pytest.fixture()
171185
def fx_executable(request, sys_platform):
172186
"""Get the Fx executable path based on platform and edition request."""

modules/data/generic_pdf.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@
3131
"selectorData": "zoomIn",
3232
"strategy": "id",
3333
"groups": []
34+
},
35+
36+
"download-button": {
37+
"selectorData": "download",
38+
"strategy": "id",
39+
"groups": []
3440
}
3541
}

tests/pdf_viewer/test_pdf_download.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
import time
3+
4+
import pytest
5+
6+
from selenium.webdriver import Firefox
7+
from modules.page_object import GenericPdf
8+
9+
10+
@pytest.fixture()
11+
def add_prefs():
12+
return []
13+
14+
15+
@pytest.mark.headed
16+
def test_pdf_download(driver: Firefox, fillable_pdf_url: str, downloads_folder: str, sys_platform):
17+
"""
18+
C3932: PDF files can be successfully downloaded via pdf.js
19+
"""
20+
from pynput.keyboard import Controller, Key
21+
22+
pdf = GenericPdf(driver, pdf_url=fillable_pdf_url).open()
23+
keyboard = Controller()
24+
25+
# Click the download button
26+
download_button = pdf.get_element("download-button")
27+
download_button.click()
28+
29+
# Allow time for the download dialog m to appear and pressing enter to download
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+
49+
keyboard.press(Key.enter)
50+
keyboard.release(Key.enter)
51+
52+
# Allow time for the download to complete
53+
time.sleep(2)
54+
55+
# Set the expected download path and the expected PDF name
56+
file_name = "i-9.pdf"
57+
saved_pdf_location = os.path.join(downloads_folder, file_name)
58+
59+
# Verify if the file exists
60+
assert os.path.exists(saved_pdf_location), f"The file was not downloaded to {saved_pdf_location}."
61+
62+
print(f"Test passed: The file {file_name} has been downloaded and is present at {saved_pdf_location}.")

0 commit comments

Comments
 (0)