Skip to content

Commit 7f004f6

Browse files
authored
Anca/Add server not found pb + some POM changes (#847)
* Add 3029186 and improve POMs * docstring and small changes * Correct tc ids * Add a comment
1 parent 8ecec12 commit 7f004f6

File tree

6 files changed

+131
-43
lines changed

6 files changed

+131
-43
lines changed

modules/browser_object_tabbar.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ def get_tab_title(self, tab_element: WebElement) -> str:
136136
tab_label = tab_element.find_element(*self.get_selector("tab-title"))
137137
return tab_label.text
138138

139+
@BasePage.context_chrome
140+
def wait_for_tab_title(
141+
self, expected_title: str, tab_index: int = 1, timeout: int = 30
142+
) -> None:
143+
"""
144+
Wait until the tab title matches the expected value.
145+
Arguments:
146+
expected_title: The tab title to wait for.
147+
tab_index: The tab index to check (default is 1).
148+
timeout: Time limit (in seconds) before raising TimeoutException.
149+
"""
150+
self.custom_wait(timeout=timeout).until(
151+
lambda d: self.get_tab_title(self.get_tab(tab_index)) == expected_title
152+
)
153+
139154
@BasePage.context_chrome
140155
def expect_tab_sound_status(
141156
self, identifier: Union[str, int], status: MediaStatus

modules/page_object_error_page.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,57 @@ class ErrorPage(BasePage):
99
"""
1010

1111
def get_error_title(self) -> str:
12+
"""Get the main title text of the error page."""
1213
return self.get_element("error-title").get_attribute("innerText")
1314

1415
def get_error_short_description(self) -> str:
16+
"""Get the short description text of the error page."""
1517
return self.get_element("error-short-description").get_attribute("innerText")
1618

1719
def get_error_long_description_items(self) -> list[WebElement]:
20+
"""Get the list of bullet items under the long description section."""
1821
return self.get_elements("error-long-description-items")
1922

2023
def get_try_again_button(self) -> WebElement:
24+
"""Get the 'Try Again' button element."""
2125
return self.get_element("try-again-button")
2226

2327
def get_error_suggestion_link(self) -> WebElement:
28+
"""Get the suggestion link element."""
2429
return self.get_element("error-suggestion-link")
30+
31+
def verify_error_header(self, expected_titles: list[str], short_site: str) -> None:
32+
"""Verify the main title and short description on the error page.
33+
Arguments:
34+
expected_titles: The list of valid titles accepted for the error page.
35+
short_site: The short version of the site URL (eg. "example" from "http://example")."""
36+
assert self.get_error_title() in expected_titles
37+
assert (
38+
f"We can’t connect to the server at {short_site}"
39+
in self.get_error_short_description()
40+
)
41+
42+
def verify_error_bullets(
43+
self,
44+
expected_texts: list[str],
45+
possible_permission_messages: list[str],
46+
) -> None:
47+
"""Verify bullet items under the long description section.
48+
Arguments:
49+
expected_texts: The list of exact text strings expected for the first two bullet items.
50+
possible_permission_messages: The list of valid permission-related messages accepted for the third bullet item."""
51+
items = self.get_error_long_description_items()
52+
assert len(items) >= 3
53+
54+
for i in range(2):
55+
assert items[i].text == expected_texts[i]
56+
# Third must match one of the permission messages based on the chanel
57+
assert items[2].text in possible_permission_messages
58+
59+
def click_suggestion_and_verify_redirect(self, redirect_url: str) -> "BasePage":
60+
"""Click the suggestion link and verify it redirects correctly.
61+
Arguments:
62+
redirect_url: The expected URL after clicking the suggestion link."""
63+
self.get_error_suggestion_link().click()
64+
self.url_contains(redirect_url)
65+
return self

modules/page_object_prefs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ def press_button_get_popup_dialog_iframe(self, button_label: str) -> WebElement:
430430
Returns the iframe object for the dialog panel in the popup after pressing some button that triggers a popup
431431
"""
432432
# hack to know if the current iframe is the default browser one or not
433-
if self.get_iframe().location['x'] > 0:
434-
self.click_on('close-dialog')
433+
if self.get_iframe().location["x"] > 0:
434+
self.click_on("close-dialog")
435435
self.click_on("prefs-button", labels=[button_label])
436436
iframe = self.get_element("browser-popup")
437437
return iframe
Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
from selenium.webdriver.support import expected_conditions as EC
4-
from selenium.webdriver.support.wait import WebDriverWait
53

64
from modules.browser_object import Navigation
75
from modules.browser_object_tabbar import TabBar
@@ -15,16 +13,27 @@ def test_case():
1513

1614
CHECK_SITE = "http://example"
1715
SHORT_SITE = CHECK_SITE.split("/")[-1]
16+
REDIRECT_URL = "https://www.example.com/"
1817
ERROR_TITLES = ["Hmm. We’re having trouble finding that site."]
18+
POSSIBLE_PERMISSION_MESSAGES = [
19+
"Check that Firefox has permission to access the web (you might be connected but behind a firewall)",
20+
"Check that Firefox Developer Edition has permission to access the web (you might be connected but behind a "
21+
"firewall)",
22+
"Check that Nightly has permission to access the web (you might be connected but behind a firewall)",
23+
]
24+
EXPECTED_TEXTS = [
25+
"Try again later",
26+
"Check your network connection",
27+
]
1928

2029

2130
def test_server_not_found_error(driver: Firefox, version: str):
2231
"""
23-
C1901393: - This tests that when a user navigates to a non-existent site, a "Server Not Found" error is
32+
C3029186 - This tests that when a user navigates to a non-existent site, a "Server Not Found" error is
2433
displayed. The error page contains the correct elements, and the suggested link redirects to the appropriate page.
2534
"""
2635

27-
# Create objects
36+
# Instantiate objects
2837
nav = Navigation(driver)
2938
tabs = TabBar(driver)
3039
error_page = ErrorPage(driver)
@@ -33,40 +42,11 @@ def test_server_not_found_error(driver: Firefox, version: str):
3342
nav.search(CHECK_SITE)
3443

3544
# Wait until the tab title updates to "Server Not Found"
36-
WebDriverWait(driver, 30).until(
37-
lambda d: tabs.get_tab_title(tabs.get_tab(1)) == "Server Not Found"
38-
)
45+
tabs.wait_for_tab_title("Server Not Found")
3946

4047
# Verify elements on the error page
41-
assert error_page.get_error_title() in ERROR_TITLES
42-
assert (
43-
f"We can’t connect to the server at {SHORT_SITE}"
44-
in error_page.get_error_short_description()
45-
)
48+
error_page.verify_error_header(ERROR_TITLES, SHORT_SITE)
49+
error_page.verify_error_bullets(EXPECTED_TEXTS, POSSIBLE_PERMISSION_MESSAGES)
4650

47-
# Define all possible valid permission messages (exact matches) for different Firefox channels
48-
possible_permission_messages = [
49-
"Check that Firefox has permission to access the web (you might be connected but behind a firewall)",
50-
"Check that Firefox Developer Edition has permission to access the web (you might be connected but behind a "
51-
"firewall)",
52-
"Check that Nightly has permission to access the web (you might be connected but behind a firewall)",
53-
]
54-
55-
expected_texts = [
56-
"Try again later",
57-
"Check your network connection",
58-
]
59-
60-
items = error_page.get_error_long_description_items()
61-
assert len(items) >= 3
62-
63-
# Verify that the first two bullet items exactly match the expected texts
64-
for i in range(2):
65-
assert items[i].text == expected_texts[i]
66-
67-
# Verify that the third bullet item exactly matches one of the valid permission messages
68-
assert items[2].text in possible_permission_messages
69-
70-
# Verify that the suggested link redirects to the correct page
71-
error_page.get_error_suggestion_link().click()
72-
nav.expect_in_content(EC.url_contains("https://www.example.com/"))
51+
# Verify the suggestion link redirects correctly
52+
error_page.click_suggestion_and_verify_redirect(REDIRECT_URL)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object import Navigation
5+
from modules.browser_object_panel_ui import PanelUi
6+
from modules.browser_object_tabbar import TabBar
7+
from modules.page_object_error_page import ErrorPage
8+
9+
10+
@pytest.fixture()
11+
def test_case():
12+
return "3029188"
13+
14+
15+
CHECK_SITE = "http://example"
16+
SHORT_SITE = CHECK_SITE.split("/")[-1]
17+
REDIRECT_URL = "https://www.example.com/"
18+
ERROR_TITLES = ["Hmm. We’re having trouble finding that site."]
19+
POSSIBLE_PERMISSION_MESSAGES = [
20+
"Check that Firefox has permission to access the web (you might be connected but behind a firewall)",
21+
"Check that Firefox Developer Edition has permission to access the web (you might be connected but behind a "
22+
"firewall)",
23+
"Check that Nightly has permission to access the web (you might be connected but behind a firewall)",
24+
]
25+
EXPECTED_TEXTS = ["Try again later", "Check your network connection"]
26+
27+
28+
def test_server_not_found_error_on_private_window(driver: Firefox, version: str):
29+
"""
30+
C3029188 - This tests that when a user navigates to a non-existent site in private window, a "Server Not Found"
31+
error is displayed. The error page contains the correct elements, and the suggested link redirects to the
32+
appropriate page.
33+
"""
34+
35+
# Instantiate objects
36+
nav = Navigation(driver)
37+
tabs = TabBar(driver)
38+
error_page = ErrorPage(driver)
39+
panel = PanelUi(driver)
40+
41+
# Open a new private window and navigate to the desired site
42+
panel.open_and_switch_to_new_window("private")
43+
nav.search(CHECK_SITE)
44+
45+
# Wait until the tab title updates to "Server Not Found"
46+
tabs.wait_for_tab_title("Server Not Found")
47+
48+
# Verify elements on the error page
49+
error_page.verify_error_header(ERROR_TITLES, SHORT_SITE)
50+
error_page.verify_error_bullets(EXPECTED_TEXTS, POSSIBLE_PERMISSION_MESSAGES)
51+
52+
# Verify the suggestion link redirects correctly
53+
error_page.click_suggestion_and_verify_redirect(REDIRECT_URL)

tests/preferences/test_clear_cookie_data.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ def test_case():
1414
WEBSITE_ADDRESS = "https://www.wikipedia.com"
1515
# WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win")
1616

17-
def _open_clear_cookies_data_dialog(
18-
about_prefs: AboutPrefs, ba: BrowserActions
19-
):
17+
18+
def _open_clear_cookies_data_dialog(about_prefs: AboutPrefs, ba: BrowserActions):
2019
"""
2120
Open about:preferences#privacy, show the 'Clear Data' dialog, switch into its iframe,
2221
wait for its option container to be present, read the value, then switch back.

0 commit comments

Comments
 (0)