Skip to content

Commit 0daef0b

Browse files
authored
Merge pull request #98 from mozilla/tw/persist-search-term
Create test for persistence of search terms
2 parents 944254f + 97f8d86 commit 0daef0b

File tree

6 files changed

+132
-26
lines changed

6 files changed

+132
-26
lines changed

modules/browser_object_navigation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def get_awesome_bar(self) -> WebElement:
3737
self.set_awesome_bar()
3838
return self.awesome_bar
3939

40+
def get_awesome_bar_text(self):
41+
"""
42+
Get the text directly from the awesome bar.
43+
This is different from 'driver.current_url' which pulls from href
44+
"""
45+
self.set_chrome_context()
46+
awesome_bar = self.get_element("awesome-bar").get_attribute("value")
47+
return awesome_bar
48+
4049
def clear_awesome_bar(self) -> BasePage:
4150
"""Clear the Awesome Bar. Prefer this over get_element("awesome-bar").clear()"""
4251
self.set_awesome_bar()

modules/browser_object_tabbar.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ def expect_tab_sound_status(
106106
)
107107
return self
108108

109+
def expect_title_contains(self, text: str) -> BasePage:
110+
"""
111+
Check if the page title contains given text
112+
"""
113+
self.expect(EC.title_contains(text))
114+
return self
115+
109116
def open_all_tabs_list(self) -> BasePage:
110117
"""Click the Tab Visibility / List All Tabs button"""
111118
with self.driver.context(self.driver.CONTEXT_CHROME):
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import pytest
22
from selenium.webdriver import Firefox
33
from selenium.webdriver.common.by import By
4-
from selenium.webdriver.support import expected_conditions as EC
54

6-
from modules.browser_object import Navigation
5+
from modules.browser_object import Navigation, TabBar
76
from modules.page_object import AboutConfig
87

98

@@ -14,6 +13,11 @@ def add_prefs():
1413
]
1514

1615

16+
# Set constants
17+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
18+
SEARCH_TERM = "saxophone"
19+
20+
1721
def test_search_bar_results(driver: Firefox):
1822
"""
1923
C1365213 - The Search Bar provides valid results for specific search terms
@@ -22,21 +26,19 @@ def test_search_bar_results(driver: Firefox):
2226
# Create objects
2327
nav = Navigation(driver).open()
2428
ac = AboutConfig(driver)
25-
26-
search_term = "saxophone"
29+
tab = TabBar(driver)
2730

2831
# Check Google results from a Search bar search
2932
# First enable search bar via about:config
30-
pref = "browser.search.widget.inNavBar"
31-
ac.toggle_true_false_config(pref)
33+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
3234
nav.clear_awesome_bar()
3335

3436
# Then run search and check the results
35-
nav.search_bar_search(search_term)
37+
nav.search_bar_search(SEARCH_TERM)
3638
nav.set_content_context()
37-
nav.expect_in_content(EC.title_contains("Google Search"))
39+
tab.expect_title_contains("Google Search")
3840
search_url = driver.current_url
39-
assert search_term in search_url
41+
assert SEARCH_TERM in search_url
4042
content_searchbar = nav.find_element(By.NAME, "q")
4143
content_searchbar_text = content_searchbar.get_attribute("value")
42-
assert content_searchbar_text == search_term
44+
assert content_searchbar_text == SEARCH_TERM

tests/address_bar_and_search/test_search_code_google_non_us.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import pytest
22
from selenium.webdriver import Firefox
33
from selenium.webdriver.common.by import By
4-
from selenium.webdriver.support import expected_conditions as ec
54

6-
from modules.browser_object import ContextMenu, Navigation
5+
from modules.browser_object import ContextMenu, Navigation, TabBar
76
from modules.page_object import AboutConfig
87

98

@@ -15,6 +14,11 @@ def add_prefs():
1514
]
1615

1716

17+
# Set constants
18+
FX_SEARCH_CODE = "client=firefox-b-d"
19+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
20+
21+
1822
def test_search_code_google_us(driver: Firefox):
1923
"""
2024
C1365269 - Default Search Code: Google - non-US
@@ -26,29 +30,28 @@ def test_search_code_google_us(driver: Firefox):
2630
nav = Navigation(driver).open()
2731
ac = AboutConfig(driver)
2832
context_menu = ContextMenu(driver)
33+
tab = TabBar(driver)
2934

3035
def search_code_assert():
3136
# Function to check the search code of a Google search in US region
32-
fx_code = "client=firefox-b-d"
3337
nav.set_content_context()
3438
search_url = driver.current_url
35-
assert fx_code in search_url
39+
assert FX_SEARCH_CODE in search_url
3640
nav.clear_awesome_bar()
3741

3842
# Check code generated from the Awesome bar search
3943
nav.search("soccer")
40-
nav.expect(ec.title_contains("Google Search"))
44+
tab.expect_title_contains("Google Search")
4145
search_code_assert()
4246

4347
# Check code generated from the Search bar search
4448
# First enable search bar via about:config
45-
pref = "browser.search.widget.inNavBar"
46-
ac.toggle_true_false_config(pref)
49+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
4750
nav.clear_awesome_bar()
4851

4952
# Then run the code check
5053
nav.search_bar_search("soccer")
51-
nav.expect(ec.title_contains("Google Search"))
54+
tab.expect_title_contains("Google Search")
5255
search_code_assert()
5356

5457
# Check code generated from the context click of selected text
@@ -64,5 +67,5 @@ def search_code_assert():
6467
# Switch to the newly opened tab and run the code check
6568
window_handles = driver.window_handles
6669
driver.switch_to.window(window_handles[-1])
67-
nav.expect(ec.title_contains("Google Search"))
70+
tab.expect_title_contains("Google Search")
6871
search_code_assert()

tests/address_bar_and_search/test_search_code_google_us.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from selenium.webdriver.common.by import By
44
from selenium.webdriver.support import expected_conditions as EC
55

6-
from modules.browser_object import ContextMenu, Navigation
6+
from modules.browser_object import ContextMenu, Navigation, TabBar
77
from modules.page_object import AboutConfig
88

99

@@ -15,6 +15,11 @@ def add_prefs():
1515
]
1616

1717

18+
# Set constant
19+
FX_SEARCH_CODE = "client=firefox-b-1-d"
20+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
21+
22+
1823
def test_search_code_google_us(driver: Firefox):
1924
"""
2025
C1365268 - Default Search Code: Google - US
@@ -26,13 +31,13 @@ def test_search_code_google_us(driver: Firefox):
2631
nav = Navigation(driver).open()
2732
ac = AboutConfig(driver)
2833
context_menu = ContextMenu(driver)
34+
tab = TabBar(driver)
2935

3036
def search_code_assert():
3137
# Function to check the search code of a Google search in US region
32-
fx_code = "client=firefox-b-1-d"
3338
nav.set_content_context()
3439
search_url = driver.current_url
35-
assert fx_code in search_url
40+
assert FX_SEARCH_CODE in search_url
3641
nav.clear_awesome_bar()
3742

3843
# Check code generated from the Awesome bar search
@@ -42,13 +47,12 @@ def search_code_assert():
4247

4348
# Check code generated from the Search bar search
4449
# First enable search bar via about:config
45-
pref = "browser.search.widget.inNavBar"
46-
ac.toggle_true_false_config(pref)
50+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
4751
nav.clear_awesome_bar()
4852

4953
# Then run the code check
5054
nav.search_bar_search("soccer")
51-
nav.expect(EC.title_contains("Google Search"))
55+
tab.expect_title_contains("Google Search")
5256
search_code_assert()
5357

5458
# Check code generated from the context click of selected text
@@ -64,5 +68,5 @@ def search_code_assert():
6468
# Switch to the newly opened tab and run the code check
6569
window_handles = driver.window_handles
6670
driver.switch_to.window(window_handles[-1])
67-
nav.expect(EC.title_contains("Google Search"))
71+
tab.expect_title_contains("Google Search")
6872
search_code_assert()
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object import Navigation, TabBar
5+
from modules.page_object import AboutConfig
6+
7+
8+
# Set search region
9+
@pytest.fixture()
10+
def add_prefs():
11+
return [
12+
("browser.search.region", "US"),
13+
("browser.urlbar.showSearchTerms.enabled", True),
14+
("browser.urlbar.showSearchTerms.featureGate", True),
15+
]
16+
17+
18+
# Set constants
19+
FIRST_SEARCH = "cheetah"
20+
FIRST_RESULT = "https://www.google.com/search?client=firefox-b-1-d&q=cheetah"
21+
SECOND_SEARCH = "lion"
22+
SECOND_RESULT = "https://www.google.com/search?client=firefox-b-1-d&q=lion"
23+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
24+
25+
26+
def test_search_term_persists(driver: Firefox):
27+
"""
28+
C2153943 - Persist search term basic functionality
29+
"""
30+
31+
# Create objects
32+
nav = Navigation(driver).open()
33+
tab = TabBar(driver)
34+
35+
def toggle_legacy_search_bar():
36+
# This test requires that the old search bar is added while retaining search results.
37+
# First, open a new tab and switch to it
38+
tab.new_tab_by_button()
39+
window_handles = driver.window_handles
40+
driver.switch_to.window(window_handles[-1])
41+
# Then, toggle the old search bar via about:config
42+
ac = AboutConfig(driver)
43+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
44+
# Finally, close the about:config tab and switch context back to the original tab
45+
nav.set_chrome_context()
46+
x_icon = tab.get_element("tab-x-icon", multiple=True)
47+
x_icon[1].click()
48+
driver.switch_to.window(window_handles[0])
49+
50+
# Perform a search using the URL bar.
51+
nav.search(FIRST_SEARCH)
52+
tab.expect_title_contains("Google Search")
53+
address_bar_text = nav.get_awesome_bar_text()
54+
assert FIRST_SEARCH == address_bar_text
55+
56+
# Add the search bar to toolbar
57+
toggle_legacy_search_bar()
58+
59+
# Search term should be replaced with full url
60+
address_bar_text = nav.get_awesome_bar_text()
61+
assert FIRST_RESULT == address_bar_text
62+
nav.clear_awesome_bar()
63+
64+
# Perform a new awesome bar search, full url should be present
65+
# First, navigate away from Google
66+
nav.set_content_context()
67+
driver.get("about:robots")
68+
# Then perform another search
69+
nav.search(SECOND_SEARCH)
70+
tab.expect_title_contains("Google Search")
71+
address_bar_text = nav.get_awesome_bar_text()
72+
assert SECOND_RESULT == address_bar_text
73+
74+
# Disable the old search bar
75+
toggle_legacy_search_bar()
76+
77+
# Again, perform a search using the URL bar.
78+
nav.search(FIRST_SEARCH)
79+
tab.expect_title_contains("Google Search")
80+
address_bar_text = nav.get_awesome_bar_text()
81+
assert FIRST_SEARCH == address_bar_text

0 commit comments

Comments
 (0)