Skip to content

Commit e975af2

Browse files
committed
Improved handling of HTTPS redirection verification
1 parent 598af7c commit e975af2

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/security_and_privacy/test_https_enabled_private_browsing.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
2+
from selenium.common import TimeoutException
23
from selenium.webdriver import Firefox
4+
from selenium.webdriver.support import expected_conditions as EC
35
from selenium.webdriver.support.wait import WebDriverWait
46

57
HTTP_URL = "http://example.com"
@@ -21,8 +23,15 @@ def test_https_first_mode_in_private_browsing(driver: Firefox):
2123
# Navigate to the HTTP URL
2224
driver.get(HTTP_URL)
2325

24-
# Wait for the URL to be redirected to HTTPS
25-
WebDriverWait(driver, 10).until(
26-
lambda d: d.current_url.startswith("https://"),
27-
message=f"Final URL should use HTTPS, but was: {driver.current_url}",
28-
)
26+
try:
27+
# Wait for the URL to be redirected to HTTPS
28+
WebDriverWait(driver, 10).until(EC.url_contains("https://example.com/"))
29+
except TimeoutException:
30+
pytest.fail(
31+
f"Timed out waiting for URL to switch to HTTPS: {driver.current_url}"
32+
)
33+
34+
# Assertion to ensure URL starts with HTTPS
35+
assert driver.current_url.startswith(
36+
"https://"
37+
), f"Final URL should be 'https://example.com/', but was: {driver.current_url}"

0 commit comments

Comments
 (0)