Skip to content

Commit 3b86cf0

Browse files
vs/search-mode-persists (#850)
* vs/search-mode-persists * vs/search-mode-persists * vs/search-mode-persists * vs/search-mode-persists * vs/search-mode-persists
1 parent d723368 commit 3b86cf0

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

SELECTOR_INFO.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,13 @@ Location: about:preferences#general Language subsection
935935
Path to .json: modules/data/about_prefs.components.json
936936
```
937937
```
938+
Selector Name: search-suggestion-in-private-windows
939+
Selector Data: "showSearchSuggestionsPrivateWindows"
940+
Description: Show search suggestions in Private Windows
941+
Location: about:preferences#search
942+
Path to .json: modules/data/about_prefs.components.json
943+
```
944+
```
938945
Selector Name: language-settings-search
939946
Selector Data: "menuitem[value='search']"
940947
Description: In the Language Set Alternatives dialog, the Select a language to add, Search for more languages… option

modules/browser_object_navigation.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,60 @@ def open_tracker_panel(self) -> BasePage:
291291
self.get_element("shield-icon").click()
292292
return self
293293

294+
def wait_for_suggestions_present(self, at_least: int = 1):
295+
"""Wait until the suggestion list has at least one visible item."""
296+
self.set_chrome_context()
297+
self.expect(lambda _: len(self.get_elements("suggestion-titles")) >= at_least)
298+
return self
299+
300+
def wait_for_suggestions_absent(self):
301+
"""Wait for the suggestions list to disappear (for non-general engines)."""
302+
self.set_chrome_context()
303+
self.element_not_visible("suggestion-titles")
304+
return self
305+
306+
def open_usb_and_select_engine(self, engine_title: str):
307+
"""Click the USB icon and select a search engine by its title."""
308+
self.get_element("searchmode-switcher").click()
309+
self.get_element("search-mode-switcher-option", labels=[engine_title]).click()
310+
return self
311+
312+
def assert_search_mode_chip_visible(self):
313+
"""Ensure the search mode indicator (chip) is visible on the left."""
314+
self.set_chrome_context()
315+
self.get_element("search-mode-span")
316+
return self
317+
318+
def click_first_suggestion_row(self):
319+
"""
320+
Clicks the first visible suggestion row in the list, using robust scrolling and fallback.
321+
"""
322+
from selenium.webdriver.common.by import By
323+
from selenium.webdriver.common.action_chains import ActionChains
324+
325+
self.set_chrome_context()
326+
driver = self.driver
327+
328+
try:
329+
# Prefer Firefox Suggest row if present
330+
row = self.get_element("firefox-suggest")
331+
except Exception:
332+
titles = self.get_elements("suggestion-titles")
333+
assert titles, "No visible suggestion items found."
334+
target = next((t for t in titles if t.is_displayed()), titles[0])
335+
try:
336+
row = target.find_element(By.XPATH, "ancestor::*[contains(@class,'urlbarView-row')][1]")
337+
except Exception:
338+
row = target
339+
340+
driver.execute_script("arguments[0].scrollIntoView({block:'center'});", row)
341+
try:
342+
ActionChains(driver).move_to_element(row).click().perform()
343+
except Exception:
344+
driver.execute_script("arguments[0].click();", row)
345+
346+
return self
347+
294348
@BasePage.context_chrome
295349
def click_file_download_warning_panel(self) -> BasePage:
296350
"""exit file download warning panel if present"""

modules/data/about_prefs.components.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@
370370
"selectorData": "BrowserLanguagesDialog",
371371
"strategy": "id",
372372
"groups": []
373+
},
374+
"search-suggestion-in-private-windows": {
375+
"selectorData": "showSearchSuggestionsPrivateWindows",
376+
"strategy": "id",
377+
"groups": []
373378
},
374379
"language-settings-select": {
375380
"selectorData": "[data-l10n-id='browser-languages-select-language']",

modules/page_object_prefs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ def find_in_settings(self, term: str) -> BasePage:
6565
search_input.send_keys(term)
6666
return self
6767

68+
def enable_private_window_suggestions(self):
69+
"""Enable 'Show search suggestions in Private Windows' if not already checked."""
70+
71+
checkbox = self.get_element("search-suggestion-in-private-windows")
72+
if checkbox.get_attribute("checked") != "true":
73+
checkbox.click()
74+
return self
75+
6876
def set_alternative_language(self, lang_code: str) -> BasePage:
6977
"""Changes the browser language"""
7078
self.get_element("language-set-alternative-button").click()
@@ -692,6 +700,8 @@ def handle_unknown_content_dialog(self) -> BasePage:
692700
return self
693701

694702

703+
704+
695705
class AboutAddons(BasePage):
696706
"""
697707
The POM for the about:addons page
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import pytest
2+
from selenium.webdriver.support import expected_conditions as EC
3+
4+
from modules.browser_object import Navigation
5+
from modules.page_object_prefs import AboutPrefs
6+
from modules.util import BrowserActions
7+
8+
GENERAL_ENGINE = "Bing"
9+
QUERY = "cobra kai"
10+
11+
12+
@pytest.fixture()
13+
def test_case():
14+
return "3028715"
15+
16+
17+
def test_search_mode_appears_and_suggestions_update(driver):
18+
"""
19+
Steps:
20+
1) Open a new tab.
21+
2) Start typing in the address bar.
22+
3) Suggestions list starts to populate using the default search engine.
23+
4) Click the USB and select another search engine from the list.
24+
5) Search mode appears (left side). Check suggestions list.
25+
6) Search terms are retained and new suggestions are returned.
26+
7) Click one of the search suggestions.
27+
8) A search is done using the engine selected from step 4.
28+
"""
29+
nav = Navigation(driver)
30+
actions = BrowserActions(driver)
31+
32+
# 1) Open a new tab
33+
nav.open_and_switch_to_new_window("tab")
34+
35+
# 2) Start typing (no Enter)
36+
actions.search(QUERY, with_enter=False)
37+
38+
# 3) Suggestions list populates (default engine)
39+
nav.wait_for_suggestions_present()
40+
41+
# 4) Click the USB and select another engine
42+
nav.open_usb_and_select_engine(GENERAL_ENGINE)
43+
44+
# 5) Search mode chip appears
45+
nav.assert_search_mode_chip_visible()
46+
nav.wait_for_suggestions_present()
47+
48+
# 6–7) Click a visible suggestion
49+
nav.click_first_suggestion_row()
50+
51+
# 8) Verify search executed with selected engine
52+
nav.expect_in_content(EC.url_contains(GENERAL_ENGINE.lower()))
53+
nav.clear_awesome_bar()
54+
55+
56+
def test_private_mode_repeat_after_enabling_pref(driver):
57+
"""
58+
- Enable “Show search suggestions in Private Windows”.
59+
- Open Private Window.
60+
- Repeat steps 1–5 (verify search works with selected engine).
61+
"""
62+
nav = Navigation(driver)
63+
actions = BrowserActions(driver)
64+
65+
# Enable PBM suggestions pref by its known ID
66+
AboutPrefs(driver, category="search").open().enable_private_window_suggestions()
67+
68+
# Open Private Window using BasePage method
69+
nav.open_and_switch_to_new_window("private")
70+
71+
try:
72+
# Repeat steps 1–8 in Private Mode
73+
nav.open_and_switch_to_new_window("tab")
74+
actions.search(QUERY, with_enter=False)
75+
76+
nav.wait_for_suggestions_present()
77+
nav.open_usb_and_select_engine(GENERAL_ENGINE)
78+
nav.assert_search_mode_chip_visible()
79+
nav.wait_for_suggestions_present()
80+
81+
nav.click_first_suggestion_row()
82+
nav.expect_in_content(EC.url_contains(GENERAL_ENGINE.lower()))
83+
nav.clear_awesome_bar()
84+
finally:
85+
driver.close()
86+
driver.switch_to.window(driver.window_handles[0])

0 commit comments

Comments
 (0)