Skip to content

Commit 7a2227e

Browse files
authored
Anca/Add search shortcut engine mix (#903)
* Add search shortcut engine mix * Update id and test name and method * Use the correct method name post merge main
1 parent 382e0ca commit 7a2227e

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

modules/browser_object_navigation.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import time
44
from typing import Literal
5+
from urllib.parse import urlparse
56

67
from selenium.common.exceptions import StaleElementReferenceException, TimeoutException
78
from selenium.webdriver import ActionChains, Firefox
@@ -407,6 +408,28 @@ def verify_search_mode_is_not_visible(self):
407408
self.element_not_visible("search-mode-chicklet")
408409
return self
409410

411+
@BasePage.context_chrome
412+
def verify_search_mode_label(self, engine_name: str):
413+
"""Verify that the search mode chicklet displays the correct engine."""
414+
chicklet = self.get_element("search-mode-chicklet")
415+
chip_text = (
416+
chicklet.text or chicklet.get_attribute("aria-label") or ""
417+
).lower()
418+
assert engine_name.lower() in chip_text, (
419+
f"Expected search mode engine '{engine_name}', got '{chip_text}'"
420+
)
421+
return self
422+
423+
@BasePage.context_chrome
424+
def verify_plain_text_in_input_awesome_bar(self, expected_text: str):
425+
"""Verify the awesomebar input contains the exact literal text."""
426+
input_el = self.get_element("awesome-bar")
427+
value = input_el.get_attribute("value")
428+
assert value == expected_text, (
429+
f"Expected input '{expected_text}', got '{value}'"
430+
)
431+
return self
432+
410433
def click_first_suggestion_row(self):
411434
"""
412435
Clicks the first visible suggestion row in the list, using robust scrolling and fallback.
@@ -920,6 +943,27 @@ def verify_status_panel_url(self, expected_url: str):
920943
f"Expected '{expected_url}' in status panel URL, got '{actual_url}'"
921944
)
922945

946+
@BasePage.context_content
947+
def verify_domain(self, expected_domain: str) -> None:
948+
"""
949+
Verify that the current URL's domain matches the expected domain using urlparse.
950+
This explicitly checks the domain (netloc) rather than just a substring match.
951+
Uses content context to get the actual page URL.
952+
953+
Argument:
954+
expected_domain: The expected domain (e.g., "wikipedia.org", "google.com")
955+
"""
956+
957+
def _domain_matches(_):
958+
parsed = urlparse(self.driver.current_url)
959+
return expected_domain in parsed.netloc
960+
961+
self.custom_wait(timeout=15).until(_domain_matches)
962+
parsed_url = urlparse(self.driver.current_url)
963+
assert expected_domain in parsed_url.netloc, (
964+
f"Expected '{expected_domain}' domain, got '{parsed_url.netloc}'"
965+
)
966+
923967
@BasePage.context_chrome
924968
def verify_engine_returned(self, engine: str) -> None:
925969
"""
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
from selenium.webdriver.common.keys import Keys
4+
5+
from modules.browser_object import Navigation
6+
7+
SEARCH_ENGINE = "Wikipedia"
8+
SEARCH_TERM = "@amazon"
9+
URL_DOMAIN = "wikipedia.org"
10+
11+
12+
@pytest.fixture()
13+
def test_case():
14+
return "3028851"
15+
16+
17+
def test_use_search_shortcut_for_a_different_search_engine_while_already_in_search_mode(
18+
driver: Firefox,
19+
):
20+
"""
21+
C3028851 - Verify that using a search shortcut for a different search engine while in search mode
22+
for another engine works as expected.
23+
"""
24+
# Instantiate objects
25+
nav = Navigation(driver)
26+
27+
# Enter search mode for the desired search engine in a new tab
28+
nav.open_and_switch_to_new_window("tab")
29+
nav.open_usb_and_select_option(SEARCH_ENGINE)
30+
31+
# Verify search mode is entered for the corresponding engine
32+
nav.verify_search_mode_is_visible()
33+
34+
# Type @engine shortcut
35+
nav.type_in_awesome_bar(SEARCH_TERM)
36+
37+
# Verify the search mode label matches the selected search engine and the input contains the plain search term
38+
nav.verify_search_mode_label(SEARCH_ENGINE)
39+
nav.verify_plain_text_in_input_awesome_bar(SEARCH_TERM)
40+
41+
# Perform the search by pressing Enter and expect
42+
nav.type_in_awesome_bar(Keys.ENTER)
43+
44+
# Verify the domain is explicitly wikipedia.org
45+
nav.verify_domain(URL_DOMAIN)
46+
47+
# Verify search term is also present in the URL
48+
nav.url_contains(SEARCH_TERM.lstrip("@"))

0 commit comments

Comments
 (0)