Skip to content

Commit 88e4da7

Browse files
Merge pull request #551 from mozilla/vs/refactoring
vs/Part1-Refactoring
2 parents 2afda2c + f31db44 commit 88e4da7

6 files changed

+78
-103
lines changed

tests/address_bar_and_search/test_adaptive_history_autofill.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
from modules.browser_object import Navigation
77
from modules.browser_object_tabbar import TabBar
88

9+
WAIT_TIMEOUT = 10
10+
TEST_URL = "https://www.nationalgeographic.com/science/"
11+
EXPECTED_TITLE = "Science"
12+
913

1014
@pytest.fixture()
1115
def test_case():
@@ -14,58 +18,45 @@ def test_case():
1418

1519
@pytest.fixture()
1620
def add_to_prefs_list():
17-
return [
18-
("browser.urlbar.autoFill.adaptiveHistory.enabled", True),
19-
]
21+
return [("browser.urlbar.autoFill.adaptiveHistory.enabled", True)]
2022

2123

2224
def test_add_adaptive_history_autofill(driver: Firefox):
2325
"""
24-
C1814373 - Test to verify that typing the first three characters of a previously visited URL in the address bar
25-
triggers the adaptive history autofill.
26+
C1814373 - Verify adaptive history autofill triggers from address bar input.
2627
"""
27-
2828
nav = Navigation(driver)
2929
tabs = TabBar(driver)
3030

31-
nav.search("https://www.nationalgeographic.com/science/")
32-
WebDriverWait(driver, 10).until(
33-
lambda d: tabs.get_tab_title(tabs.get_tab(1)) == "Science"
31+
nav.search(TEST_URL)
32+
WebDriverWait(driver, WAIT_TIMEOUT).until(
33+
lambda d: tabs.get_tab_title(tabs.get_tab(1)) == EXPECTED_TITLE
3434
)
3535

3636
tabs.new_tab_by_button()
3737
tabs.wait_for_num_tabs(2)
3838
driver.switch_to.window(driver.window_handles[1])
3939

4040
with driver.context(driver.CONTEXT_CHROME):
41-
x_icon = tabs.get_elements("tab-x-icon")
42-
x_icon[0].click()
41+
tabs.get_elements("tab-x-icon")[0].click()
4342

44-
# Type the first 3 characters of the visited URL in the address bar and select the suggested URL
4543
nav.type_in_awesome_bar("nat")
4644
with driver.context(driver.CONTEXT_CHROME):
4745
nav.get_element("firefox-suggest").click()
48-
nav.expect_in_content(
49-
EC.url_contains("https://www.nationalgeographic.com/science/")
50-
)
5146

52-
# Open a new tab, type the first 3 characters of the visited URL
47+
nav.expect_in_content(EC.url_contains(TEST_URL))
48+
5349
tabs.new_tab_by_button()
5450
tabs.wait_for_num_tabs(2)
5551
driver.switch_to.window(driver.window_handles[-1])
5652
nav.type_in_awesome_bar("nat")
5753

5854
tabs.set_chrome_context()
59-
autofill_adaptive_element = nav.get_element(
60-
"search-result-autofill-adaptive-element"
61-
)
55+
autofill_element = nav.get_element("search-result-autofill-adaptive-element")
6256

63-
# Assertion to verify that the 'autofill_adaptive' type is found
64-
assert autofill_adaptive_element.get_attribute("type") == "autofill_adaptive", (
65-
f"Expected element type to be 'autofill_adaptive' but found '{autofill_adaptive_element.get_attribute('type')}'"
57+
assert autofill_element.get_attribute("type") == "autofill_adaptive", (
58+
f"Expected type 'autofill_adaptive', got '{autofill_element.get_attribute('type')}'"
6659
)
67-
68-
# Assertion to check the autofilled URL is the expected one
69-
assert "nationalgeographic.com/science" in autofill_adaptive_element.text, (
70-
"URL 'https://www.nationalgeographic.com/science' not found in autofill suggestions."
60+
assert "nationalgeographic.com/science" in autofill_element.text, (
61+
f"Autofill text did not contain expected URL. Got: {autofill_element.text}"
7162
)
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
from selenium.webdriver.support import expected_conditions as EC
43

5-
from modules.browser_object import Navigation, TabBar
6-
from modules.browser_object_context_menu import ContextMenu
4+
from modules.browser_object import ContextMenu, Navigation, TabBar
75

86

97
@pytest.fixture()
@@ -18,27 +16,23 @@ def hard_quit():
1816

1917
def test_add_search_engine_from_address_bar(driver: Firefox):
2018
"""
21-
C1365478: Open Search Engines can be added using the address bar context click option.
19+
C1365478 - Verify that Open Search engines can be added via the address bar context menu.
2220
"""
2321
nav = Navigation(driver)
2422
menu = ContextMenu(driver)
2523
tabs = TabBar(driver)
2624

27-
# Visit the URL and wait until it is loaded
2825
driver.get("https://youtube.com")
29-
nav.custom_wait(timeout=20).until(EC.url_contains("www.youtube.com"))
26+
nav.custom_wait(timeout=20).until(lambda d: "youtube.com" in d.current_url)
3027

3128
with driver.context(driver.CONTEXT_CHROME):
32-
# Right-Click the address bar and select the "Add YouTube" option
3329
nav.context_click_in_awesome_bar()
3430
menu.click_context_item("context-menu-add-search-engine")
3531

36-
# Open a new tab and close the previous tab
3732
tabs.new_tab_by_button()
38-
previous_tab = tabs.get_tab_by_title("YouTube")
39-
tabs.close_tab(previous_tab)
33+
youtube_tab = tabs.get_tab_by_title("YouTube")
34+
tabs.close_tab(youtube_tab)
4035

41-
# Confirm that YouTube is an option in the search mode list
4236
nav.click_on("searchmode-switcher")
4337
nav.element_exists("search-mode-switcher-option", labels=["YouTube"])
4438
nav.click_on("searchmode-switcher")
Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
from time import sleep
2-
31
import pytest
2+
from selenium.common.exceptions import TimeoutException
43
from selenium.webdriver import Firefox
54
from selenium.webdriver.support import expected_conditions as EC
5+
from selenium.webdriver.support.ui import WebDriverWait
66

77
from modules.browser_object import Navigation
88

9+
ADDONS_BASE_URL = "https://addons.mozilla.org/en-US/firefox/addon/"
10+
911

1012
@pytest.fixture()
1113
def test_case():
1214
return "2234714"
1315

1416

17+
@pytest.fixture()
18+
def add_to_prefs_list():
19+
return [
20+
("browser.urlbar.suggest.addons", True),
21+
("browser.urlbar.addons.featureGate", True),
22+
]
23+
24+
1525
def test_addon_suggestion_based_on_search_input(driver: Firefox):
1626
"""
17-
C2234714: Test that add-on suggestions match the URL bar input.
18-
19-
To avoid lengthy waits caused by network traffic during browser startup,
20-
this test loops through the list of addons in a single browser session
21-
instead of using parameterization. This reduces the overall test duration
22-
by waiting for the network traffic only once.
27+
C2234714 - Verify that the address bar suggests relevant add-ons based on search input.
2328
"""
24-
25-
# Map input text to addon names
2629
input_to_addon_name = {
2730
"clips": "video-downloadhelper",
2831
"grammar": "languagetool",
@@ -35,14 +38,19 @@ def test_addon_suggestion_based_on_search_input(driver: Firefox):
3538

3639
nav = Navigation(driver)
3740
nav.set_awesome_bar()
38-
sleep(2)
3941

4042
for input_text, addon_name in input_to_addon_name.items():
4143
nav.type_in_awesome_bar(input_text)
42-
nav.element_visible("addon-suggestion")
44+
try:
45+
nav.element_visible("addon-suggestion")
46+
except TimeoutException:
47+
raise AssertionError(
48+
f"Addon suggestion not visible for input: '{input_text}'"
49+
)
50+
4351
nav.select_element_in_nav("addon-suggestion")
4452

45-
# Construct the expected URL
46-
expected_url = f"https://addons.mozilla.org/en-US/firefox/addon/{addon_name}/"
53+
expected_url = f"{ADDONS_BASE_URL}{addon_name}/"
4754
nav.expect_in_content(EC.url_contains(expected_url))
55+
4856
nav.clear_awesome_bar()

tests/address_bar_and_search/test_default_search_provider_change_awesome_bar.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from modules.browser_object import Navigation
55
from modules.page_object import AboutPrefs
66

7+
WAIT_TIMEOUT = 10
8+
SEARCH_ENGINE = "DuckDuckGo"
9+
EXPECTED_PLACEHOLDER = f"Search with {SEARCH_ENGINE} or enter address"
10+
711

812
@pytest.fixture()
913
def test_case():
@@ -13,25 +17,14 @@ def test_case():
1317
@pytest.mark.ci
1418
def test_default_search_provider_change_awesome_bar(driver: Firefox):
1519
"""
16-
C2860208 - This test makes sure that the default search provider can be changed and settings are applied
20+
C2860208 - Verify that changing the default search provider updates the address bar placeholder.
1721
"""
18-
# Create objects
1922
nav = Navigation(driver)
20-
about_prefs = AboutPrefs(driver)
23+
prefs = AboutPrefs(driver)
2124

22-
# Make sure we start at about:newtab
2325
driver.get("about:newtab")
24-
25-
# Click the USB and click the 'Search Settings' button.
2626
nav.open_searchmode_switcher_settings()
27+
prefs.search_engine_dropdown().select_option(SEARCH_ENGINE)
2728

28-
# Set a different provider as a default search engine
29-
about_prefs.search_engine_dropdown().select_option("DuckDuckGo")
30-
31-
# Open a new tab
3229
driver.get("about:newtab")
33-
34-
# Verify that the search provider has been changed to the selected search engine
35-
nav.element_attribute_contains(
36-
"awesome-bar", "placeholder", "Search with DuckDuckGo or enter address"
37-
)
30+
nav.element_attribute_contains("awesome-bar", "placeholder", EXPECTED_PLACEHOLDER)

tests/address_bar_and_search/test_default_search_provider_change_legacy_search_bar.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
from modules.browser_object import Navigation, PanelUi, TabBar
66
from modules.page_object import AboutPrefs, CustomizeFirefox
77

8+
SEARCH_TERM = "what is life?"
9+
SEARCH_ENGINE = "DuckDuckGo"
10+
EXPECTED_ENGINE_DISPLAY = "DuckDuckGo Search"
11+
SEARCH_SETTINGS_URL = "about:preferences#search"
12+
813

914
@pytest.fixture()
1015
def test_case():
@@ -13,51 +18,35 @@ def test_case():
1318

1419
def test_default_search_provider_change_legacy_search_bar(driver: Firefox):
1520
"""
16-
C1365245 - This test makes sure that the default search
17-
provider can be changed and settings are applied
21+
C1365245 - Verify that changing the default search provider is reflected in the legacy search bar.
1822
"""
19-
20-
search_term = "what is life?"
21-
22-
# Create objects
2323
panel_ui = PanelUi(driver)
24-
customize_firefox = CustomizeFirefox(driver)
24+
customize = CustomizeFirefox(driver)
2525
nav = Navigation(driver)
2626
tabs = TabBar(driver)
27-
about_prefs = AboutPrefs(driver, category="search")
27+
prefs = AboutPrefs(driver, category="search")
2828

29-
# Open the customize page and add the search bar to the toolbar
3029
panel_ui.open_panel_menu()
3130
panel_ui.navigate_to_customize_toolbar()
32-
customize_firefox.add_widget_to_toolbar("search-bar")
31+
customize.add_widget_to_toolbar("search-bar")
3332

34-
# Type the search term, click 'Change search settings'
3533
tabs.new_tab_by_button()
36-
nav.type_in_search_bar(search_term)
34+
nav.type_in_search_bar(SEARCH_TERM)
3735
nav.click_on_change_search_settings_button()
38-
39-
# Check the current URL is the search settings page
4036
driver.switch_to.window(driver.window_handles[2])
41-
assert driver.current_url == "about:preferences#search"
37+
assert driver.current_url == SEARCH_SETTINGS_URL
4238

43-
# Open a site, open search settings again and check if it's opened in a different tab
4439
driver.get("https://9gag.com/")
45-
nav.type_in_search_bar(search_term)
40+
nav.type_in_search_bar(SEARCH_TERM)
4641
nav.click_on_change_search_settings_button()
4742
assert driver.current_url == "https://9gag.com/"
48-
4943
driver.switch_to.window(driver.window_handles[3])
50-
assert driver.current_url == "about:preferences#search"
44+
assert driver.current_url == SEARCH_SETTINGS_URL
5145

52-
# Set a different provider as a default search engine
53-
about_prefs.open()
54-
about_prefs.search_engine_dropdown().select_option("DuckDuckGo")
46+
prefs.open()
47+
prefs.search_engine_dropdown().select_option(SEARCH_ENGINE)
48+
nav.type_in_search_bar(SEARCH_TERM)
5549

56-
# Open the search bar, type the search term and check if the search engine is the one set
57-
nav.type_in_search_bar(search_term)
5850
with driver.context(driver.CONTEXT_CHROME):
59-
search_engine_name_element = driver.find_element(
60-
By.CSS_SELECTOR, ".searchbar-engine-name"
61-
)
62-
63-
assert search_engine_name_element.get_attribute("value") == "DuckDuckGo Search"
51+
engine_name = driver.find_element(By.CSS_SELECTOR, ".searchbar-engine-name")
52+
assert engine_name.get_attribute("value") == EXPECTED_ENGINE_DISPLAY

tests/address_bar_and_search/test_refresh_firefox_dialog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
from modules.browser_object import Navigation
55

6+
SEARCH_QUERY = "refresh firefox"
7+
REFRESH_BUTTON_ID = "refresh-button-awesome-bar"
8+
DIALOG_ID = "refresh-firefox-dialog"
9+
610

711
@pytest.fixture()
812
def test_case():
@@ -11,15 +15,11 @@ def test_case():
1115

1216
def test_refresh_firefox_dialog(driver: Firefox):
1317
"""
14-
C2914620: Refresh Firefox dialog
18+
C2914620 - Verify that the 'Refresh Firefox' dialog appears from the address bar.
1519
"""
16-
# instantiate objects and type in search bar
1720
nav = Navigation(driver)
1821
nav.set_awesome_bar()
19-
nav.type_in_awesome_bar("refresh firefox")
20-
21-
# Click on the "Refresh Firefox" button
22-
nav.click_on("refresh-button-awesome-bar")
22+
nav.type_in_awesome_bar(SEARCH_QUERY)
2323

24-
# Refresh Firefox dialog is correctly displayed
25-
nav.element_visible("refresh-firefox-dialog")
24+
nav.click_on(REFRESH_BUTTON_ID)
25+
nav.element_visible(DIALOG_ID)

0 commit comments

Comments
 (0)