|
| 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 | + |
| 9 | + |
| 10 | +@pytest.fixture() |
| 11 | +def add_prefs(): |
| 12 | + return [ |
| 13 | + ("browser.search.region", "US"), |
| 14 | + ("browser.urlbar.autoFill.adaptiveHistory.enabled", True), |
| 15 | + ] |
| 16 | + |
| 17 | + |
| 18 | +def test_add_adaptive_history_autofill(driver: Firefox): |
| 19 | + """ |
| 20 | + C1814373 - Test to verify that typing the first three characters of a previously visited URL in the address bar |
| 21 | + triggers the adaptive history autofill. |
| 22 | + """ |
| 23 | + |
| 24 | + nav = Navigation(driver).open() |
| 25 | + tabs = TabBar(driver) |
| 26 | + |
| 27 | + nav.search("https://www.nationalgeographic.com/science/") |
| 28 | + WebDriverWait(driver, 10).until( |
| 29 | + lambda d: tabs.get_tab_title(tabs.get_tab(1)) == "Science" |
| 30 | + ) |
| 31 | + |
| 32 | + tabs.new_tab_by_button() |
| 33 | + tabs.wait_for_num_tabs(2) |
| 34 | + driver.switch_to.window(driver.window_handles[1]) |
| 35 | + |
| 36 | + with driver.context(driver.CONTEXT_CHROME): |
| 37 | + x_icon = tabs.get_element("tab-x-icon", multiple=True) |
| 38 | + x_icon[0].click() |
| 39 | + |
| 40 | + # Type the first 3 characters of the visited URL in the address bar and select the suggested URL |
| 41 | + nav.type_in_awesome_bar("nat") |
| 42 | + nav.get_element("firefox-suggest").click() |
| 43 | + nav.expect_in_content( |
| 44 | + EC.url_contains("https://www.nationalgeographic.com/science/") |
| 45 | + ) |
| 46 | + |
| 47 | + tabs.set_content_context() |
| 48 | + |
| 49 | + # Open a new tab, type the first 3 characters of the visited URL |
| 50 | + tabs.new_tab_by_button() |
| 51 | + tabs.wait_for_num_tabs(2) |
| 52 | + driver.switch_to.window(driver.window_handles[-1]) |
| 53 | + nav.type_in_awesome_bar("nat") |
| 54 | + |
| 55 | + autofill_adaptive_element = nav.get_element( |
| 56 | + "search-result-autofill-adaptive-element" |
| 57 | + ) |
| 58 | + |
| 59 | + # Assertion to verify that the 'autofill_adaptive' type is found |
| 60 | + assert ( |
| 61 | + autofill_adaptive_element.get_attribute("type") == "autofill_adaptive" |
| 62 | + ), f"Expected element type to be 'autofill_adaptive' but found '{autofill_adaptive_element.get_attribute('type')}'" |
| 63 | + |
| 64 | + # Assertion to check the autofilled URL is the expected one |
| 65 | + assert ( |
| 66 | + "nationalgeographic.com/science" in autofill_adaptive_element.text |
| 67 | + ), "URL 'https://www.nationalgeographic.com/science' not found in autofill suggestions." |
0 commit comments