|
| 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 | +@pytest.mark.parametrize( |
| 19 | + "url, site_name, suggestion_url", |
| 20 | + [ |
| 21 | + ("http://cnn", "cnn", "https://www.cnn.com/"), |
| 22 | + ("http://example", "example", "https://www.example.com/"), |
| 23 | + ], |
| 24 | +) |
| 25 | +def test_server_not_found_error(driver: Firefox, url, site_name, suggestion_url): |
| 26 | + """ |
| 27 | + C1901393: - This tests that when a user navigates to a non-existent site, a "Server Not Found" error is |
| 28 | + displayed. The error page contains the correct elements, and the suggested link redirects to the appropriate page. |
| 29 | +
|
| 30 | + """ |
| 31 | + |
| 32 | + # Create objects |
| 33 | + nav = Navigation(driver).open() |
| 34 | + tabs = TabBar(driver) |
| 35 | + error_page = ErrorPage(driver) |
| 36 | + |
| 37 | + nav.search(url) |
| 38 | + |
| 39 | + # Verify the tab title |
| 40 | + |
| 41 | + WebDriverWait(driver, 30).until( |
| 42 | + lambda d: tabs.get_tab_title(tabs.get_tab(1)) == "Server Not Found" |
| 43 | + ) |
| 44 | + |
| 45 | + # Verify elements on the error page |
| 46 | + |
| 47 | + error_title = error_page.get_error_title() |
| 48 | + assert ( |
| 49 | + error_title == "Hmm. We’re having trouble finding that site." |
| 50 | + ), f"Expected error title text not found. Actual: {error_title}" |
| 51 | + |
| 52 | + error_short_description = error_page.get_error_short_description() |
| 53 | + assert ( |
| 54 | + error_short_description |
| 55 | + == f"We can’t connect to the server at {site_name}. Did you mean to go to www.{site_name}.com?" |
| 56 | + ), ( |
| 57 | + f"Expected error short description text not found." |
| 58 | + f"Actual: {error_short_description}" |
| 59 | + ) |
| 60 | + |
| 61 | + error_long_description_items = error_page.get_error_long_description_items() |
| 62 | + expected_texts = [ |
| 63 | + "Try again later", |
| 64 | + "Check your network connection", |
| 65 | + "Check that Firefox has permission to access the web (you might be connected but behind a firewall)", |
| 66 | + ] |
| 67 | + |
| 68 | + for i, item in enumerate(error_long_description_items): |
| 69 | + assert ( |
| 70 | + item.text == expected_texts[i] |
| 71 | + ), f"Expected error long description item text not found. Actual: {item.text}" |
| 72 | + |
| 73 | + try_again_button = error_page.get_try_again_button() |
| 74 | + assert try_again_button.is_displayed(), "The 'Try Again' button is not displayed" |
| 75 | + |
| 76 | + # Verify that the suggested link redirects to the correct page |
| 77 | + |
| 78 | + error_page.get_error_suggestion_link().click() |
| 79 | + nav.expect_in_content(EC.url_contains(suggestion_url)) |
0 commit comments