Skip to content

Commit 6e815da

Browse files
authored
Anca/Open link in new container tab (#934)
* Add open link in new container tab test * Improve test * Add selector info * Fix error * update selector
1 parent f8933c8 commit 6e815da

File tree

7 files changed

+141
-1
lines changed

7 files changed

+141
-1
lines changed

SELECTOR_INFO.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,20 @@ Description: Context menu option to search selected text with the engine set as
19151915
Location: Context menu - topsite context menu
19161916
Path to .json: modules/data/context_menu.components.json
19171917
```
1918+
```
1919+
Selector Name: context-menu-open-link-in-new_container_tab
1920+
Selector Data: context-openlinkinusercontext-menu"
1921+
Description: Open linkin new container tab context menu item
1922+
Location: Newpage topsites tile context menu
1923+
Path to .json: modules/data/context_menu.components.json
1924+
```
1925+
```
1926+
Selector Name: context-menu-open-link-in-container-work
1927+
Selector Data: menuitem[data-l10n-id='user-context-work']"
1928+
Description: Open link in container "Work" context submenu item
1929+
Location: Newpage topsites tile submenu context menu, secodn option
1930+
Path to .json: modules/data/context_menu.components.json
1931+
```
19181932
#### credit_card_fill
19191933
```
19201934
Selector Name: form-field
@@ -3329,6 +3343,13 @@ Description: Switch to clipboard
33293343
Location: Address bar
33303344
Path to .json: modules/data/navigation.components.json
33313345
```
3346+
```
3347+
Selector Name: tab-container-label
3348+
Selector Data: "userContext-label"
3349+
Description: Tab container label
3350+
Location: URL bar when a tab container is active
3351+
Path to .json: modules/data/navigation.components.json
3352+
```
33323353
#### panel_ui
33333354
```
33343355
Selector name: panel-ui-button

manifests/key.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ address_bar_and_search:
9999
result: pass
100100
splits:
101101
- functional1
102+
test_open_link_in_new_container_tab:
103+
result: pass
104+
splits:
105+
- functional1
102106
test_paste_and_go_opens_correct_url:
103107
result: pass
104108
splits:

modules/browser_object_context_menu.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def click_context_item(
2424
self.fetch(reference, labels=labels).click()
2525
return self
2626

27+
@BasePage.context_chrome
28+
def open_link_in_container(self) -> BasePage:
29+
"""Open a link from the context menu in a specific container tab."""
30+
self.click_context_item("context-menu-open-link-in-new_container_tab")
31+
self.click_context_item("context-menu-open-link-in-container-work")
32+
return self
33+
2734
@BasePage.context_chrome
2835
def verify_topsites_tile_context_menu_options(
2936
self,

modules/browser_object_navigation.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,3 +1189,46 @@ def verify_no_autofill_adaptive_elements(self) -> BasePage:
11891189
"Adaptive history autofill suggestion was not removed after deletion."
11901190
)
11911191
return self
1192+
1193+
@BasePage.context_chrome
1194+
def verify_autofill_adaptive_element(
1195+
self, expected_type: str, expected_url: str
1196+
) -> BasePage:
1197+
"""
1198+
Verify that the adaptive history autofill element has the expected type and URL text.
1199+
This method handles chrome context switching internally.
1200+
Arguments:
1201+
expected_type: Expected type attribute value
1202+
expected_url: Expected URL fragment to be contained in the element text
1203+
"""
1204+
autofill_element = self.get_element("search-result-autofill-adaptive-element")
1205+
actual_type = autofill_element.get_attribute("type")
1206+
actual_text = autofill_element.text
1207+
1208+
assert actual_type == expected_type
1209+
assert expected_url in actual_text
1210+
1211+
return self
1212+
1213+
@BasePage.context_chrome
1214+
def verify_no_autofill_adaptive_elements(self) -> BasePage:
1215+
"""Verify that no adaptive history autofill elements are present."""
1216+
autofill_elements = self.get_elements("search-result-autofill-adaptive-element")
1217+
if autofill_elements:
1218+
logging.warning(
1219+
f"Unexpected adaptive autofill elements found: {[el.text for el in autofill_elements]}"
1220+
)
1221+
assert len(autofill_elements) == 0, (
1222+
"Adaptive history autofill suggestion was not removed after deletion."
1223+
)
1224+
return self
1225+
1226+
@BasePage.context_chrome
1227+
def expect_container_label(self, label_expected: str):
1228+
"""
1229+
Verify the container label for user context (container tabs).
1230+
Argument:
1231+
label_expected: The expected label text for the user context container.
1232+
"""
1233+
actual_label = self.get_element("tab-container-label").text
1234+
assert actual_label == label_expected

modules/data/context_menu.components.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
"groups": []
122122
},
123123

124+
"context-menu-open-link-in-new_container_tab": {
125+
"selectorData": "context-openlinkinusercontext-menu",
126+
"strategy": "id",
127+
"groups": []
128+
},
129+
124130
"context-menu-toolbar-open-in-new-tab": {
125131
"selectorData": "placesContext_open:newtab",
126132
"strategy": "id",
@@ -233,6 +239,12 @@
233239
"selectorData": "context-searchselect",
234240
"strategy": "id",
235241
"groups": []
236-
}
242+
},
243+
244+
"context-menu-open-link-in-container-work": {
245+
"selectorData": "menuitem[data-l10n-id='user-context-work']",
246+
"strategy": "css",
247+
"groups": []
248+
}
237249

238250
}

modules/data/navigation.components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,12 @@
671671
"groups": ["doNotCache"]
672672
},
673673

674+
"tab-container-label": {
675+
"selectorData": "userContext-label",
676+
"strategy": "id",
677+
"groups": []
678+
},
679+
674680
"clipboard-suggestion": {
675681
"selectorData": "#urlbar-results > div.urlbarView-row[type='clipboard']",
676682
"strategy": "css",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object_context_menu import ContextMenu
5+
from modules.browser_object_navigation import Navigation
6+
from modules.browser_object_tabbar import TabBar
7+
from modules.page_object_generics import GenericPage
8+
from modules.page_object_newtab import AboutNewtab
9+
10+
11+
@pytest.fixture()
12+
def test_case():
13+
return "3029117"
14+
15+
16+
@pytest.fixture()
17+
def add_to_prefs_list():
18+
return [("privacy.userContext.enabled", True)]
19+
20+
21+
TOPSITE_TITLE = "Wikipedia"
22+
TOPSITE_URL = "www.wikipedia.org"
23+
EXPECTED_CONTAINER = "Work"
24+
25+
26+
def test_open_link_in_new_container_tab(driver: Firefox) -> None:
27+
"""
28+
C3029117 - Verify that a link opened from the context menu in a new container tab opens
29+
in the correct container and URL.
30+
"""
31+
tabs = TabBar(driver)
32+
new_tab = AboutNewtab(driver)
33+
context_menu = ContextMenu(driver)
34+
nav = Navigation(driver)
35+
page = GenericPage(driver, url="about:newtab")
36+
37+
# Open about:newtab and right-click to open context menu
38+
page.open()
39+
new_tab.open_topsite_context_menu_by_title(TOPSITE_TITLE)
40+
41+
# Click first option and verify link opens in new tab
42+
context_menu.open_link_in_container()
43+
44+
# Switch to new tab and verify URL and container
45+
tabs.switch_to_new_tab()
46+
nav.url_contains(TOPSITE_URL)
47+
nav.expect_container_label(EXPECTED_CONTAINER)

0 commit comments

Comments
 (0)