Skip to content

Commit a321bdf

Browse files
authored
Merge pull request #85 from mozilla/as/not-found-error-page
As/server not found error page
2 parents d4a8fcf + e4aad4b commit a321bdf

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"error-title": {
3+
"selectorData": ".title-text[data-l10n-id='dnsNotFound-title']",
4+
"strategy": "css",
5+
"groups": []
6+
},
7+
8+
"error-short-description": {
9+
"selectorData": "errorShortDesc",
10+
"strategy": "id",
11+
"groups": []
12+
},
13+
14+
"error-suggestion-link": {
15+
"selectorData": "#errorShortDesc a[data-l10n-name='website']",
16+
"strategy": "css",
17+
"groups": []
18+
},
19+
20+
"error-long-description-items": {
21+
"selectorData": "#errorLongDesc li",
22+
"strategy": "css",
23+
"groups": []
24+
},
25+
26+
"try-again-button": {
27+
"selectorData": "#netErrorButtonContainer #neterrorTryAgainButton",
28+
"strategy": "css",
29+
"groups": []
30+
}
31+
32+
}

modules/page_object_error_page.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from selenium.webdriver.remote.webelement import WebElement
2+
3+
from modules.page_base import BasePage
4+
5+
6+
class ErrorPage(BasePage):
7+
"""
8+
Page Object Model for the 'Server Not Found' error page.
9+
"""
10+
11+
def get_error_title(self) -> str:
12+
return self.get_element("error-title").get_attribute("innerText")
13+
14+
def get_error_short_description(self) -> str:
15+
return self.get_element("error-short-description").get_attribute("innerText")
16+
17+
def get_error_long_description_items(self) -> list[WebElement]:
18+
return self.get_elements("error-long-description-items")
19+
20+
def get_try_again_button(self) -> WebElement:
21+
return self.get_element("try-again-button")
22+
23+
def get_error_suggestion_link(self) -> WebElement:
24+
return self.get_element("error-suggestion-link")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
from selenium.webdriver.support import expected_conditions as EC
4+
from selenium.webdriver.support.wait import WebDriverWait
5+
6+
from modules.browser_object import Navigation
7+
from modules.browser_object_tabbar import TabBar
8+
from modules.page_object_error_page import ErrorPage
9+
10+
11+
@pytest.fixture()
12+
def add_prefs():
13+
return [
14+
("browser.search.region", "US"),
15+
]
16+
17+
18+
def test_server_not_found_error(driver: Firefox):
19+
"""
20+
C1901393: - This tests that when a user navigates to a non-existent site, a "Server Not Found" error is
21+
displayed. The error page contains the correct elements, and the suggested link redirects to the appropriate page.
22+
"""
23+
24+
# Create objects
25+
nav = Navigation(driver).open()
26+
tabs = TabBar(driver)
27+
error_page = ErrorPage(driver)
28+
29+
nav.search("http://cnn")
30+
31+
# Verify the tab title
32+
WebDriverWait(driver, 30).until(
33+
lambda d: tabs.get_tab_title(tabs.get_tab(1)) == "Server Not Found"
34+
)
35+
36+
# Verify elements on the error page
37+
error_title = error_page.get_error_title()
38+
assert (
39+
error_title == "Hmm. We’re having trouble finding that site."
40+
), f"Expected error title text not found. Actual: {error_title}"
41+
42+
error_short_description = error_page.get_error_short_description()
43+
assert (
44+
error_short_description
45+
== "We can’t connect to the server at cnn. Did you mean to go to www.cnn.com?"
46+
), (
47+
f"Expected error short description text not found."
48+
f"Actual: {error_short_description}"
49+
)
50+
51+
error_long_description_items = error_page.get_error_long_description_items()
52+
expected_texts = [
53+
"Try again later",
54+
"Check your network connection",
55+
"Check that Firefox has permission to access the web (you might be connected but behind a firewall)",
56+
]
57+
58+
for i, item in enumerate(error_long_description_items):
59+
assert (
60+
item.text == expected_texts[i]
61+
), f"Expected error long description item text not found. Actual: {item.text}"
62+
63+
try_again_button = error_page.get_try_again_button()
64+
assert try_again_button.is_displayed(), "The 'Try Again' button is not displayed"
65+
66+
# Verify that the suggested link redirects to the correct page
67+
error_page.get_error_suggestion_link().click()
68+
nav.expect_in_content(EC.url_contains("https://www.cnn.com/"))

0 commit comments

Comments
 (0)