Skip to content

Commit f8933c8

Browse files
authored
Anca/Adaptive history records removal test + some refactoring (#929)
* Add adaptive hitory removal * Update methods, add test to manifest * Rename confusing selector * Adjust selector * Set failing test unstable
1 parent 2654503 commit f8933c8

File tree

9 files changed

+157
-61
lines changed

9 files changed

+157
-61
lines changed

SELECTOR_INFO.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,8 @@ Path to .json: modules/data/about_prefs.components.json
12181218
```
12191219
Selector Name: clipboard-suggestion-checkbox
12201220
Selector Data: #clipboardSuggestion"
1221-
Description: The checkbox for Clipboard
1222-
Location: about:preferences#search
1221+
Description: The checkbox for Clipboard
1222+
Location: about:preferences#search
12231223
Path to .json: modules/data/about_prefs.components.json
12241224
```
12251225
```
@@ -1254,7 +1254,7 @@ Path to .json: modules/data/about_prefs.components.json
12541254
Selector Name: Browsing History
12551255
Selector Data: history-suggestion
12561256
Description: Browsing History / History Suggestion under Address bar section
1257-
Location: about:preferences#search
1257+
Location: about:preferences#search
12581258
Path to .json: modules/data/about_prefs.components.json
12591259
```
12601260
#### about_profiles
@@ -3518,6 +3518,7 @@ Location: On the hamburger menu
35183518
Path to .json: modules/data/panel_ui.components.json
35193519
```
35203520
```
3521+
Selector name: panel-menu-item-by-title
35213522
Selector Data: toolbarbutton.bookmark-item[label*='{title}']
35223523
Description: Bookmark or history item by title. This selector works for both bookmarks and history items since Firefox uses the same CSS class "bookmark-item" for both in the hamburger menu UI.
35233524
Location: On the hamburger menu > Bookmarks or History

manifests/key.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ address_bar_and_search:
66
win: pass
77
splits:
88
- smoke
9+
test_adaptive_history_removal:
10+
result: pass
11+
splits:
12+
- functional1
913
test_add_engine_address_bar:
1014
result: pass
1115
splits:
@@ -357,8 +361,8 @@ downloads:
357361
test_add_zip_type:
358362
result:
359363
linux: unstable
360-
mac: pass
361-
win: pass
364+
mac: unstable
365+
win: unstable
362366
splits:
363367
- smoke
364368
- ci-extended

modules/browser_object_navigation.py

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,18 @@ def delete_bookmark_from_other_bookmarks_via_context_menu(
727727
return self
728728

729729
@BasePage.context_chrome
730-
def delete_bookmark_from_bookmarks_toolbar(self, bookmark_name: str) -> BasePage:
730+
def delete_panel_menu_item_by_title(self, item_title: str) -> BasePage:
731731
"""
732-
Delete bookmark from bookmarks toolbar via context menu
732+
Delete a panel menu item (bookmark or history entry) via context menu.
733+
734+
This method works for both bookmarks and history items in the panel menu (hamburger menu),
735+
as Firefox uses the same UI structure for both. The caller should ensure the appropriate
736+
panel menu is open (e.g., History menu or Bookmarks menu) before calling this method.
733737
734738
Argument:
735-
bookmark_name: The display name of the bookmark to delete
739+
item_title: The display name/title of the item to delete (works for both bookmarks and history entries)
736740
"""
737-
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_name])
741+
self.panel_ui.context_click("panel-menu-item-by-title", labels=[item_title])
738742
self.context_menu.click_and_hide_menu("context-menu-delete-page")
739743
return self
740744

@@ -761,7 +765,9 @@ def verify_bookmark_exists_in_bookmarks_toolbar(
761765
"""
762766
Verify bookmark exists in the bookmarks toolbar
763767
"""
764-
self.panel_ui.element_visible("bookmark-by-title", labels=[bookmark_name])
768+
self.panel_ui.element_visible(
769+
"panel-menu-item-by-title", labels=[bookmark_name]
770+
)
765771
return self
766772

767773
@BasePage.context_chrome
@@ -785,7 +791,9 @@ def verify_bookmark_does_not_exist_in_bookmarks_toolbar(
785791
self, bookmark_name: str
786792
) -> BasePage:
787793
"""Verify bookmark does not exist in the bookmarks toolbar"""
788-
self.panel_ui.element_not_visible("bookmark-by-title", labels=[bookmark_name])
794+
self.panel_ui.element_not_visible(
795+
"panel-menu-item-by-title", labels=[bookmark_name]
796+
)
789797
return self
790798

791799
@BasePage.context_chrome
@@ -837,8 +845,10 @@ def open_bookmark_from_toolbar(self, bookmark_title: str) -> BasePage:
837845
Argument:
838846
bookmark_title: The title of the bookmark to open
839847
"""
840-
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
841-
self.panel_ui.click_on("bookmark-by-title", labels=[bookmark_title])
848+
self.panel_ui.element_clickable(
849+
"panel-menu-item-by-title", labels=[bookmark_title]
850+
)
851+
self.panel_ui.click_on("panel-menu-item-by-title", labels=[bookmark_title])
842852
return self
843853

844854
@BasePage.context_chrome
@@ -852,8 +862,10 @@ def open_bookmark_in_new_tab_via_context_menu(
852862
bookmark_title: The title of the bookmark to open
853863
"""
854864
# Right-click the bookmark and open it in new tabe via context menu item
855-
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
856-
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_title])
865+
self.panel_ui.element_clickable(
866+
"panel-menu-item-by-title", labels=[bookmark_title]
867+
)
868+
self.panel_ui.context_click("panel-menu-item-by-title", labels=[bookmark_title])
857869
self.context_menu.click_on("context-menu-toolbar-open-in-new-tab")
858870

859871
return self
@@ -868,8 +880,10 @@ def open_bookmark_in_new_window_via_context_menu(
868880
Argument:
869881
bookmark_title: The title of the bookmark to open
870882
"""
871-
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
872-
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_title])
883+
self.panel_ui.element_clickable(
884+
"panel-menu-item-by-title", labels=[bookmark_title]
885+
)
886+
self.panel_ui.context_click("panel-menu-item-by-title", labels=[bookmark_title])
873887
self.context_menu.click_on("context-menu-toolbar-open-in-new-window")
874888
return self
875889

@@ -883,8 +897,10 @@ def open_bookmark_in_new_private_window_via_context_menu(
883897
Argument:
884898
bookmark_title: The title of the bookmark to open
885899
"""
886-
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
887-
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_title])
900+
self.panel_ui.element_clickable(
901+
"panel-menu-item-by-title", labels=[bookmark_title]
902+
)
903+
self.panel_ui.context_click("panel-menu-item-by-title", labels=[bookmark_title])
888904
self.context_menu.click_on("context-menu-toolbar-open-in-new-private-window")
889905
return self
890906

@@ -1141,3 +1157,35 @@ def find_match(driver):
11411157
return True
11421158

11431159
return index
1160+
1161+
@BasePage.context_chrome
1162+
def verify_autofill_adaptive_element(
1163+
self, expected_type: str, expected_url: str
1164+
) -> BasePage:
1165+
"""
1166+
Verify that the adaptive history autofill element has the expected type and URL text.
1167+
This method handles chrome context switching internally.
1168+
Arguments:
1169+
expected_type: Expected type attribute value
1170+
expected_url: Expected URL fragment to be contained in the element text
1171+
"""
1172+
autofill_element = self.get_element("search-result-autofill-adaptive-element")
1173+
actual_type = autofill_element.get_attribute("type")
1174+
actual_text = autofill_element.text
1175+
1176+
assert actual_type == expected_type
1177+
assert expected_url in actual_text
1178+
1179+
return self
1180+
1181+
@BasePage.context_chrome
1182+
def verify_no_autofill_adaptive_elements(self) -> BasePage:
1183+
autofill_elements = self.get_elements("search-result-autofill-adaptive-element")
1184+
if autofill_elements:
1185+
logging.warning(
1186+
f"Unexpected adaptive autofill elements found: {[el.text for el in autofill_elements]}"
1187+
)
1188+
assert len(autofill_elements) == 0, (
1189+
"Adaptive history autofill suggestion was not removed after deletion."
1190+
)
1191+
return self

modules/browser_object_panel_ui.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,32 +282,26 @@ def confirm_history_clear(self):
282282
def verify_history_item_exists(self, item_title: str) -> BasePage:
283283
"""
284284
Verify that a history item with the specified title exists in the history menu.
285-
Note:
286-
This method uses the "bookmark-by-title" selector, which works for both
287-
bookmarks and history items because Firefox uses the same CSS class "bookmark-item"
288-
for both in the hamburger menu UI. This is intentional design in Firefox's UI.
285+
289286
Argument:
290287
item_title (str): The title text to look for in the history item (can be partial match)
291288
"""
292289
self.open_history_menu()
293290
self.get_all_history()
294-
self.element_visible("bookmark-by-title", labels=[item_title])
291+
self.element_visible("panel-menu-item-by-title", labels=[item_title])
295292
return self
296293

297294
@BasePage.context_chrome
298295
def verify_history_item_does_not_exist(self, item_title: str) -> BasePage:
299296
"""
300-
Verify that a history item with the specified title exists in the history menu.
301-
Note:
302-
This method uses the "bookmark-by-title" selector, which works for both
303-
bookmarks and history items because Firefox uses the same CSS class "bookmark-item"
304-
for both in the hamburger menu UI. This is intentional design in Firefox's UI.
297+
Verify that a history item with the specified title does not exist in the history menu.
298+
305299
Argument:
306300
item_title (str): The title text to look for in the history item (can be partial match)
307301
"""
308302
self.open_history_menu()
309303
self.get_all_history()
310-
self.element_not_visible("bookmark-by-title", labels=[item_title])
304+
self.element_not_visible("panel-menu-item-by-title", labels=[item_title])
311305
return self
312306

313307
# Bookmarks section
@@ -338,7 +332,7 @@ def verify_bookmark_exists_in_hamburger_menu(self, bookmark_title: str) -> BaseP
338332
Arguments:
339333
bookmark_title (str): The title text to look for in the bookmark
340334
"""
341-
self.element_visible("bookmark-by-title", labels=[bookmark_title])
335+
self.element_visible("panel-menu-item-by-title", labels=[bookmark_title])
342336
return self
343337

344338
@BasePage.context_chrome

modules/data/panel_ui.components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
"groups": []
181181
},
182182

183-
"bookmark-by-title": {
183+
"panel-menu-item-by-title": {
184184
"selectorData": "toolbarbutton.bookmark-item[label*='{title}']",
185185
"strategy": "css",
186186
"groups": []
Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
from selenium.webdriver.support import expected_conditions as EC
4-
from selenium.webdriver.support.wait import WebDriverWait
53

64
from modules.browser_object import Navigation
75
from modules.browser_object_tabbar import TabBar
86

9-
WAIT_TIMEOUT = 10
107
TEST_URL = "https://www.nationalgeographic.com/science/"
118
EXPECTED_IN_TITLE = "Science"
9+
TYPED_TEXT = "nat"
1210
EXPECTED_TYPE = "autofill_adaptive"
13-
EXPECTED_TEXT_FRAGMENT = "nationalgeographic.com/science"
11+
EXPECTED_URL = "nationalgeographic.com/science"
1412

1513

1614
@pytest.fixture()
@@ -27,38 +25,26 @@ def test_add_adaptive_history_autofill(driver: Firefox):
2725
"""
2826
C1814373 - Verify adaptive history autofill triggers from address bar input.
2927
"""
28+
# Instantiate objects
3029
nav = Navigation(driver)
3130
tabs = TabBar(driver)
3231

33-
# Step 1: Visit the test site and verify tab title
32+
# Visit the test site and verify title
3433
nav.search(TEST_URL)
35-
WebDriverWait(driver, WAIT_TIMEOUT).until(
36-
lambda d: tabs.expect_title_contains(EXPECTED_IN_TITLE)
37-
)
34+
tabs.expect_title_contains(EXPECTED_IN_TITLE)
3835

39-
# Step 2: Open new tab, close the original
36+
# Open new tab, close the original
4037
tabs.new_tab_by_button()
41-
tabs.wait_for_num_tabs(2)
4238
driver.switch_to.window(driver.window_handles[1])
4339
tabs.close_first_tab_by_icon()
4440

45-
# Step 3: Type in address bar, then click adaptive suggestion
46-
nav.type_in_awesome_bar("nat")
41+
# Type in address bar, then click adaptive suggestion
42+
nav.type_in_awesome_bar(TYPED_TEXT)
4743
nav.click_firefox_suggest()
48-
nav.expect_in_content(EC.url_contains(TEST_URL))
44+
nav.url_contains(TEST_URL)
4945

50-
# Step 4: Open new tab and check for autofill suggestion
46+
# Open new tab and check for autofill suggestion
5147
tabs.new_tab_by_button()
52-
tabs.wait_for_num_tabs(2)
5348
driver.switch_to.window(driver.window_handles[-1])
54-
nav.type_in_awesome_bar("nat")
55-
56-
tabs.set_chrome_context()
57-
autofill_element = nav.get_element("search-result-autofill-adaptive-element")
58-
59-
assert autofill_element.get_attribute("type") == EXPECTED_TYPE, (
60-
f"Expected type '{EXPECTED_TYPE}', got '{autofill_element.get_attribute('type')}'"
61-
)
62-
assert EXPECTED_TEXT_FRAGMENT in autofill_element.text, (
63-
f"Autofill text did not contain expected URL. Got: {autofill_element.text}"
64-
)
49+
nav.type_in_awesome_bar(TYPED_TEXT)
50+
nav.verify_autofill_adaptive_element(EXPECTED_TYPE, EXPECTED_URL)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object import Navigation
5+
from modules.browser_object_panel_ui import PanelUi
6+
from modules.browser_object_tabbar import TabBar
7+
8+
TEST_URL = "https://www.nationalgeographic.com/science/"
9+
TYPED_TEXT = "nat"
10+
EXPECTED_IN_TITLE = "Science"
11+
EXPECTED_TYPE = "autofill_adaptive"
12+
EXPECTED_URL = "nationalgeographic.com/science"
13+
14+
15+
@pytest.fixture()
16+
def test_case():
17+
return "3029071"
18+
19+
20+
@pytest.fixture()
21+
def add_to_prefs_list():
22+
return [("browser.urlbar.autoFill.adaptiveHistory.enabled", True)]
23+
24+
25+
def test_remove_adaptive_history_entry(driver: Firefox) -> None:
26+
"""
27+
C3029071 - Verify adaptive history entry is deleted from history and not suggested in address bar.
28+
"""
29+
# Instantiate objects
30+
nav = Navigation(driver)
31+
tabs = TabBar(driver)
32+
panel = PanelUi(driver)
33+
34+
# Visit the test site and verify title
35+
nav.search(TEST_URL)
36+
tabs.expect_title_contains(EXPECTED_IN_TITLE)
37+
38+
# Open new tab, close the original
39+
tabs.new_tab_by_button()
40+
driver.switch_to.window(driver.window_handles[1])
41+
tabs.close_first_tab_by_icon()
42+
43+
# Type in address bar, then click adaptive suggestion
44+
nav.type_in_awesome_bar(TYPED_TEXT)
45+
nav.click_firefox_suggest()
46+
nav.url_contains(TEST_URL)
47+
48+
# Open new tab and check for autofill suggestion
49+
tabs.new_tab_by_button()
50+
driver.switch_to.window(driver.window_handles[-1])
51+
nav.type_in_awesome_bar(TYPED_TEXT)
52+
nav.verify_autofill_adaptive_element(EXPECTED_TYPE, EXPECTED_URL)
53+
54+
# Delete the adaptive history entry
55+
panel.open_history_menu()
56+
nav.delete_panel_menu_item_by_title(EXPECTED_IN_TITLE)
57+
panel.confirm_history_clear()
58+
59+
# Open new tab and verify the adaptive suggestion is removed
60+
tabs.new_tab_by_button()
61+
driver.switch_to.window(driver.window_handles[1])
62+
tabs.close_first_tab_by_icon()
63+
nav.type_in_awesome_bar(TYPED_TEXT)
64+
nav.verify_no_autofill_adaptive_elements()

tests/bookmarks_and_history/test_delete_bookmarks_from_toolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_delete_bookmarks_from_toolbar(driver: Firefox):
3030
nav.verify_bookmark_exists_in_bookmarks_toolbar("Internet for people")
3131

3232
# Delete the bookmark from toolbar
33-
nav.delete_bookmark_from_bookmarks_toolbar("Internet for people")
33+
nav.delete_panel_menu_item_by_title("Internet for people")
3434

3535
# Verify bookmark was deleted
3636
nav.verify_bookmark_does_not_exist_in_bookmarks_toolbar("Internet for people")

tests/bookmarks_and_history/test_deleted_page_not_remembered.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def test_deleted_page_not_remembered(driver: Firefox, sys_platform):
2626

2727
# Open history menu and right-click on a specific history entry and delete it
2828
panel.open_history_menu()
29-
panel.context_click("bookmark-by-title", labels=["Firefox Privacy Notice"])
30-
context_menu.click_and_hide_menu("context-menu-delete-page")
29+
nav.delete_panel_menu_item_by_title("Firefox Privacy Notice")
3130

3231
# Type the deleted page name in the URL bar and verify the deleted page is not suggested
3332
nav.type_in_awesome_bar("Firefox Privacy Notice")

0 commit comments

Comments
 (0)