Skip to content

Commit a66d451

Browse files
authored
Merge pull request #106 from mozilla/as/warning-pages
As/phishing and malware warnings
2 parents 8878d5f + f779b4f commit a66d451

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
from selenium.webdriver.common.by import By
4+
from selenium.webdriver.support import expected_conditions as EC
5+
from selenium.webdriver.support.wait import WebDriverWait
6+
7+
from modules.browser_object_tabbar import TabBar
8+
9+
PHISHING_URL = "http://www.itisatrap.org/firefox/its-a-trap.html"
10+
MALWARE_URL = "http://www.itisatrap.org/firefox/its-an-attack.html"
11+
12+
13+
@pytest.fixture()
14+
def add_prefs():
15+
return [
16+
("browser.safebrowsing.malware.enabled", True),
17+
("browser.safebrowsing.phishing.enabled", True),
18+
]
19+
20+
21+
def get_error_title(driver, url):
22+
"""
23+
Navigate to the given URL and return the error title text.
24+
"""
25+
driver.get(url)
26+
error_title_element = WebDriverWait(driver, 10).until(
27+
EC.presence_of_element_located((By.ID, "errorTitleText"))
28+
)
29+
return error_title_element.get_attribute("innerText")
30+
31+
32+
def test_phishing_and_malware_warning_errors(driver: Firefox):
33+
"""
34+
C1901393: - This tests that when a user accesses websites suspected of phishing or malware, a warning page is
35+
displayed.
36+
"""
37+
# Create the object
38+
tabs = TabBar(driver)
39+
40+
# Test phishing warning page
41+
phishing_error_title = get_error_title(driver, PHISHING_URL)
42+
assert phishing_error_title == "Deceptive site ahead", (
43+
f"Expected error title 'Deceptive site ahead' not found at {PHISHING_URL}. "
44+
f"Actual: {phishing_error_title}"
45+
)
46+
47+
# Open a new tab
48+
tabs.new_tab_by_button()
49+
tabs.wait_for_num_tabs(2)
50+
driver.switch_to.window(driver.window_handles[1])
51+
52+
# Test malware warning page
53+
malware_error_title = get_error_title(driver, MALWARE_URL)
54+
assert malware_error_title == "Visiting this website may harm your computer", (
55+
f"Expected error title 'Visiting this website may harm your computer' not found at {MALWARE_URL}. "
56+
f"Actual: {malware_error_title}"
57+
)

0 commit comments

Comments
 (0)