Skip to content

Commit d262b0e

Browse files
authored
Merge pull request #70 from mozilla/as/search-suggestion-for-engine-selection
As/search suggestion for engine selection
2 parents 7385970 + 1f09882 commit d262b0e

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

modules/data/navigation.components.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
]
1010
},
1111

12+
"results-dropdown": {
13+
"selectorData": "urlbar-results",
14+
"strategy": "id",
15+
"groups": [
16+
"doNotCache"
17+
]
18+
},
19+
1220
"tab-to-search-text-span": {
1321
"selectorData": "urlbarView-dynamic-onboardTabToSearch-text-container",
1422
"strategy": "class",
@@ -107,7 +115,7 @@
107115
"groups": []
108116
},
109117

110-
118+
111119
"add-extra-search-engine": {
112120
"selectorData": "[id*=urlbar-engine-one-off-item-engine--1][tooltiptext*='{0}']",
113121
"strategy": "css",
@@ -124,6 +132,13 @@
124132
"selectorData": "downloads-button",
125133
"strategy": "id",
126134
"groups": []
127-
}
135+
},
128136

137+
"search-suggestion-list": {
138+
"selectorData": "div.urlbarView-row[type='search_engine'] span.urlbarView-title",
139+
"strategy": "css",
140+
"groups": [
141+
"doNotCache"
142+
]
143+
}
129144
}

modules/page_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ def element_selected(self, name: str, labels=[]) -> Page:
345345
)
346346
return self
347347

348+
def element_has_text(self, name: str, text: str, labels=[]) -> Page:
349+
"""Expect helper: wait until element has given text"""
350+
self.expect(
351+
EC.text_to_be_present_in_element(
352+
self.get_selector(name, labels=labels), text
353+
)
354+
)
355+
return self
356+
348357
def url_contains(self, url_part: str) -> Page:
349358
"""Expect helper: wait until driver URL contains given text or timeout"""
350359
self.expect(EC.url_contains(url_part))
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
from selenium.webdriver import Firefox, Keys
3+
from selenium.webdriver.support import expected_conditions as EC
4+
5+
from modules.browser_object import Navigation
6+
7+
sites = ["Google", "Amazon", "Bing", "DuckDuckGo", "eBay"]
8+
9+
10+
@pytest.fixture()
11+
def add_prefs():
12+
return [
13+
("browser.search.region", "US"),
14+
]
15+
16+
17+
@pytest.mark.parametrize("site", sites)
18+
def test_search_suggestion_for_engine_selection(driver: Firefox, site: str):
19+
nav = Navigation(driver).open()
20+
nav.type_in_awesome_bar("@")
21+
nav.element_has_text("results-dropdown", f"Search with {site}")
22+
23+
suggestion_list_items = nav.get_elements("search-suggestion-list")
24+
25+
# Filter elements to find the one that matches the desired site
26+
suggestion_list_item = next(
27+
(item for item in suggestion_list_items if site in item.text), None
28+
)
29+
30+
if suggestion_list_item:
31+
suggestion_list_item.click()
32+
nav.type_in_awesome_bar("cobra" + Keys.ENTER)
33+
nav.expect_in_content(EC.url_contains(site.lower()))
34+
else:
35+
pytest.fail(f"No search suggestion found for site: {site}")
36+
37+
nav.clear_awesome_bar()

0 commit comments

Comments
 (0)