|
| 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