1
1
import re
2
+ from time import sleep
2
3
3
4
import pytest
5
+ from selenium .common .exceptions import StaleElementReferenceException
4
6
from selenium .webdriver import Firefox
5
7
from selenium .webdriver .common .by import By
6
8
from selenium .webdriver .support import expected_conditions as EC
@@ -19,7 +21,8 @@ def delete_files_regex_string():
19
21
return r"\bdownload\b"
20
22
21
23
22
- MIXED_CONTENT_DOWNLOAD_URL = "https://b-mcb-download.glitch.me/"
24
+ MIXED_CONTENT_DOWNLOAD_URL = "https://file-examples.com/wp-content/storage/2018/04/file_example_AVI_480_750kB.avi"
25
+ MAX_CHECKS = 30
23
26
24
27
25
28
def test_mixed_content_download_via_https (driver : Firefox , delete_files ):
@@ -29,14 +32,10 @@ def test_mixed_content_download_via_https(driver: Firefox, delete_files):
29
32
30
33
web_page = GenericPage (driver , url = MIXED_CONTENT_DOWNLOAD_URL )
31
34
32
- # Wait up to 30 seconds for test website to wake up and load the content
35
+ # Wait up to 30 seconds for test website to wake up and download the content
33
36
web_page .open ()
34
37
with driver .context (driver .CONTEXT_CHROME ):
35
- WebDriverWait (driver , 30 ).until (EC .title_contains ("Hello!" ))
36
-
37
- WebDriverWait (driver , 5 ).until (
38
- EC .presence_of_element_located ((By .XPATH , "//button[@onclick='runtestSec()']" ))
39
- ).click ()
38
+ WebDriverWait (driver , 30 ).until (EC .title_contains ("File Examples" ))
40
39
41
40
with driver .context (driver .CONTEXT_CHROME ):
42
41
download_name = WebDriverWait (driver , 10 ).until (
@@ -49,12 +48,23 @@ def test_mixed_content_download_via_https(driver: Firefox, delete_files):
49
48
50
49
# Verify that the desired download target element is present directly, no extra steps needed.
51
50
download_value = download_name .get_attribute ("value" )
52
- assert re .match (r"download (\(\d+\))? $" , download_value ), (
51
+ assert re .match (r"file_example_AVI_480_750kB (\(\d+\)).avi $" , download_value ), (
53
52
f"The download name is incorrect: { download_value } "
54
53
)
55
54
56
55
# Verify that the download progress has reached 100%, which indicates that the download is complete.
57
- download_status_value = download_status .get_attribute ("value" )
58
- assert download_status_value == "100" , (
59
- f"The download status is not '100': { download_status_value } "
60
- )
56
+ i = 1
57
+ while True :
58
+ try :
59
+ download_value = download_status .get_attribute ("value" )
60
+ if download_value == "100" :
61
+ break
62
+ except StaleElementReferenceException :
63
+ pass
64
+
65
+ if i > MAX_CHECKS :
66
+ raise TimeoutError (
67
+ "Download progress did not reach 100% within reasonable time."
68
+ )
69
+ sleep (1 )
70
+ i = + 1
0 commit comments