|
| 1 | +from time import sleep |
| 2 | + |
| 3 | +import pytest |
| 4 | +from selenium.webdriver import Firefox |
| 5 | +from selenium.webdriver.common.by import By |
| 6 | +from selenium.webdriver.common.keys import Keys |
| 7 | +from selenium.webdriver.support import expected_conditions as EC |
| 8 | +from selenium.webdriver.support.wait import WebDriverWait |
| 9 | + |
| 10 | +from modules.browser_object import Navigation |
| 11 | +from modules.browser_object_context_menu import ContextMenu |
| 12 | +from modules.page_object import AboutConfig, AboutPrefs |
| 13 | + |
| 14 | + |
| 15 | +@pytest.fixture() |
| 16 | +def add_prefs(): |
| 17 | + return [ |
| 18 | + ("browser.search.region", "US"), |
| 19 | + ] |
| 20 | + |
| 21 | + |
| 22 | +def test_default_search_provider_change(driver: Firefox): |
| 23 | + """ |
| 24 | + C1365245 - This test makes sure that the default search |
| 25 | + provider can be changed and settings are applied |
| 26 | + """ |
| 27 | + |
| 28 | + # Create objects |
| 29 | + nav = Navigation(driver).open() |
| 30 | + about_config = AboutConfig(driver) |
| 31 | + search_term = "what is life?" |
| 32 | + |
| 33 | + # enable search bar via about:config |
| 34 | + pref = "browser.search.widget.inNavBar" |
| 35 | + about_config.toggle_true_false_config(pref) |
| 36 | + nav.clear_awesome_bar() |
| 37 | + nav.set_content_context() |
| 38 | + sleep(1) |
| 39 | + |
| 40 | + # type some word->select 'Change search settings' when the search drop-down panel is opened. |
| 41 | + |
| 42 | + nav.type_in_search_bar(search_term) |
| 43 | + nav.click_on_change_search_settings_button() |
| 44 | + |
| 45 | + # switch to the second tab |
| 46 | + driver.switch_to.window(driver.window_handles[1]) |
| 47 | + sleep(1) |
| 48 | + |
| 49 | + # check that the current URL is about:preferences#search |
| 50 | + assert driver.current_url == "about:preferences#search" |
| 51 | + |
| 52 | + # open a site, open search settings again and check if it's opened in a different tab |
| 53 | + driver.get("https://9gag.com/") |
| 54 | + nav.type_in_search_bar(search_term) |
| 55 | + nav.click_on_change_search_settings_button() |
| 56 | + assert driver.current_url == "https://9gag.com/" |
| 57 | + |
| 58 | + driver.switch_to.window(driver.window_handles[2]) |
| 59 | + assert driver.current_url == "about:preferences#search" |
| 60 | + |
| 61 | + # Set a different provider as a default search engine |
| 62 | + about_prefs = AboutPrefs(driver, category="search").open() |
| 63 | + about_prefs.search_engine_dropdown().select_option("DuckDuckGo") |
| 64 | + |
| 65 | + # Open the search bar and type in a keyword and check if it's with the right provider |
| 66 | + nav.type_in_search_bar(search_term) |
| 67 | + with driver.context(driver.CONTEXT_CHROME): |
| 68 | + search_engine_name_element = driver.find_element( |
| 69 | + By.CSS_SELECTOR, ".searchbar-engine-name" |
| 70 | + ) |
| 71 | + |
| 72 | + assert search_engine_name_element.get_attribute("value") == "DuckDuckGo Search" |
0 commit comments