Skip to content

Commit c65ad44

Browse files
committed
Refactor and stabilization on download pdf test
1 parent 09cb07e commit c65ad44

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

tests/downloads/test_download_pdf.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)

tests/preferences/test_clear_cookie_data.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
def test_case():
1111
return "143627"
1212

13+
1314
WEBSITE_ADDRESS = "https://www.wikipedia.com"
14-
#WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win")
15+
# WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win")
1516

1617

1718
def _dialog_options_present(about_prefs: AboutPrefs) -> bool:
@@ -23,7 +24,9 @@ def _dialog_options_present(about_prefs: AboutPrefs) -> bool:
2324
return False
2425

2526

26-
def open_clear_cookies_data_dialog(about_prefs: AboutPrefs, ba: BrowserActions, wait: WebDriverWait):
27+
def open_clear_cookies_data_dialog(
28+
about_prefs: AboutPrefs, ba: BrowserActions, wait: WebDriverWait
29+
):
2730
"""
2831
Open about:preferences#privacy, show 'Clear Data' dialog, switch into its iframe,
2932
wait for its options container to be present, read the value, then switch back.

tests/tabs/test_active_tab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from modules.browser_object import TabBar
55

6-
76
NUM_TABS = 5
87

98

tests/tabs/test_navigation_multiple_tabs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
2+
23
import pytest
34
from selenium.webdriver import Firefox
5+
46
from modules.browser_object import TabBar
57

68
NUM_TABS = 20

tests/tabs/test_open_bookmark_in_new_tab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def test_case():
1818

1919

2020
def test_open_bookmark_in_new_tab(driver: Firefox):
21-
2221
"""
2322
C134460: Verify that New Tabs can be opened by right clicking and selecting new tab from the bookmarks.
2423
"""

tests/tabs/test_open_new_tab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from modules.browser_object import TabBar
66

7-
87
URL = "about:robots"
98
EXPECTED_TEXT = "Firefox"
109

tests/tabs/test_open_new_tab_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
22
from selenium.webdriver import Firefox
33
from selenium.webdriver.support import expected_conditions as EC
4-
from modules.browser_object import TabBar
54

5+
from modules.browser_object import TabBar
66

77
URL = "about:robots"
88
EXPECTED_TEXT = "Firefox"

0 commit comments

Comments
 (0)