1- import re
2- from time import sleep
3-
41import pytest
5- from selenium .common .exceptions import StaleElementReferenceException
62from selenium .webdriver import Firefox
7- from selenium .webdriver .common .by import By
8- from selenium .webdriver .support import expected_conditions as EC
9- from selenium .webdriver .support .wait import WebDriverWait
103
4+ from modules .browser_object import Navigation
115from modules .page_object import GenericPage
126
137
@@ -31,42 +25,16 @@ def test_mixed_content_download_via_https(driver: Firefox, delete_files):
3125 """
3226 C1756722: Verify that the user can download mixed content via HTTPS
3327 """
34-
28+ # Initialize objects
3529 web_page = GenericPage (driver , url = MIXED_CONTENT_DOWNLOAD_URL )
30+ nav = Navigation (driver )
3631
37- # Wait up to 30 seconds for test website to wake up and download the content
32+ # Wait for the test website to wake up and download the content
3833 web_page .open ()
39- with driver .context (driver .CONTEXT_CHROME ):
40- WebDriverWait (driver , 30 ).until (EC .title_contains ("File Examples" ))
41-
42- with driver .context (driver .CONTEXT_CHROME ):
43- download_name = WebDriverWait (driver , 10 ).until (
44- EC .presence_of_element_located ((By .CLASS_NAME , "downloadTarget" ))
45- )
46-
47- download_status = WebDriverWait (driver , 10 ).until (
48- EC .presence_of_element_located ((By .CLASS_NAME , "downloadProgress" ))
49- )
50-
51- # Verify that the desired download target element is present directly, no extra steps needed.
52- download_value = download_name .get_attribute ("value" )
53- assert re .match (r"file-sample_100kB(\(\d+\)).odt$" , download_value ), (
54- f"The download name is incorrect: { download_value } "
55- )
34+ web_page .wait .until (lambda _ : web_page .title_contains ("File Examples" ))
5635
57- # Verify that the download progress has reached 100%, which indicates that the download is complete.
58- i = 1
59- while True :
60- try :
61- download_value = download_status .get_attribute ("value" )
62- if download_value == "100" :
63- break
64- except StaleElementReferenceException :
65- pass
36+ # Verify download name matches expected pattern
37+ nav .verify_download_name (r"file-sample_100kB(\(\d+\))?.odt$" )
6638
67- if i > MAX_CHECKS :
68- raise TimeoutError (
69- "Download progress did not reach 100% within reasonable time."
70- )
71- sleep (1 )
72- i = + 1
39+ # Wait for download completion
40+ nav .wait_for_download_completion ()
0 commit comments