Skip to content

Commit 7f74664

Browse files
committed
vs/ test pdf download
1 parent 4ba987f commit 7f74664

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ def downloads_folder(sys_platform):
172172
"""Return the downloads folder location for this OS"""
173173
if sys_platform == "Windows":
174174
user = os.environ.get("USERNAME")
175-
return f"C:\\Users\\{user}\\Downloads\\{file_name}"
175+
return f"C:\\Users\\{user}\\Downloads"
176176
elif sys_platform == "Darwin": # MacOS
177177
user = os.environ.get("USER")
178-
return f"/Users/{user}/Downloads/{file_name}"
178+
return f"/Users/{user}/Downloads"
179179
elif sys_platform == "Linux":
180180
user = os.environ.get("USER")
181-
return f"/home/{user}/Downloads/{file_name}"
181+
return f"/home/{user}/Downloads"
182182

183183

184184
@pytest.fixture()

modules/data/generic_pdf.components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"groups": []
3434
},
3535

36-
"download": {
36+
"download-button": {
3737
"selectorData": "download",
3838
"strategy": "id",
3939
"groups": []

tests/pdf_viewer/test_pdf_download.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import os
2-
import platform
32
import time
43

54
import pytest
6-
from pynput.keyboard import Controller, Key
7-
from selenium.webdriver import Firefox
8-
from selenium.webdriver.common.by import By
95

10-
from modules.browser_object_navigation import Navigation
6+
from selenium.webdriver import Firefox
117
from modules.page_object import GenericPdf
128

139

@@ -16,45 +12,51 @@ def add_prefs():
1612
return []
1713

1814

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):
2017
"""
2118
C3932: PDF files can be successfully downloaded via pdf.js
2219
"""
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()
2423
keyboard = Controller()
2524

2625
# Click the download button
27-
download_button = driver.find_element(By.ID, "download")
26+
download_button = pdf.get_element("download-button")
2827
download_button.click()
2928

3029
# Allow time for the download dialog m to appear and pressing enter to download
3130
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+
3249
keyboard.press(Key.enter)
3350
keyboard.release(Key.enter)
3451

3552
# Allow time for the download to complete
3653
time.sleep(2)
3754

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
4156
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)
5258

5359
# 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}."
5761

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

Comments
 (0)