Skip to content

Commit 5d937c6

Browse files
authored
Merge pull request #658 from mozilla/tracy/fix-download-mixed-content
tracy/Swap in new test site
2 parents 23ef258 + ea84650 commit 5d937c6

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tests/downloads/test_mixed_content_download_via_https.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import re
2+
from time import sleep
23

34
import pytest
5+
from selenium.common.exceptions import StaleElementReferenceException
46
from selenium.webdriver import Firefox
57
from selenium.webdriver.common.by import By
68
from selenium.webdriver.support import expected_conditions as EC
@@ -19,7 +21,8 @@ def delete_files_regex_string():
1921
return r"\bdownload\b"
2022

2123

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
2326

2427

2528
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):
2932

3033
web_page = GenericPage(driver, url=MIXED_CONTENT_DOWNLOAD_URL)
3134

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
3336
web_page.open()
3437
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"))
4039

4140
with driver.context(driver.CONTEXT_CHROME):
4241
download_name = WebDriverWait(driver, 10).until(
@@ -49,12 +48,23 @@ def test_mixed_content_download_via_https(driver: Firefox, delete_files):
4948

5049
# Verify that the desired download target element is present directly, no extra steps needed.
5150
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), (
5352
f"The download name is incorrect: {download_value}"
5453
)
5554

5655
# 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

Comments
 (0)