Skip to content

Commit 24dd8f4

Browse files
authored
Merge pull request #602 from mozilla/as/bookmarks-refactoring
Anca/ Bookmark suite refactoring
2 parents 14ff7cd + bd468bf commit 24dd8f4

17 files changed

+468
-296
lines changed

SELECTOR_INFO.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,13 +2734,6 @@ Location: URL bar
27342734
Path to .json: modules/data/navigation.components.json
27352735
```
27362736
```
2737-
Selector name: save-bookmark-button
2738-
Selector Data: editBookmarkPanelDoneButton
2739-
Description: Save bookmark
2740-
Location: Bookmark panel
2741-
Path to .json: modules/data/navigation.components.json
2742-
```
2743-
```
27442737
Selector name: blue-star-button
27452738
Selector Data: image[id='star-button'][starred='true']
27462739
Description: Bookmarked page
@@ -2762,13 +2755,6 @@ Location: Download panel
27622755
Path to .json: modules/data/navigation.components.json
27632756
```
27642757
```
2765-
Selector name: edit-bookmark-panel
2766-
Selector Data: editBMPanel_namePicker
2767-
Description: Edit bookmark panel
2768-
Location: Bookmark panel
2769-
Path to .json: modules/data/navigation.components.json
2770-
```
2771-
```
27722758
Selector name: remove-bookmark-button
27732759
Selector Data: editBookmarkPanelRemoveButton
27742760
Description: Remove bookmark button
@@ -2804,24 +2790,10 @@ Location: Inside the library button in the toolbar
28042790
Path to .json: modules/data/navigation.components.json
28052791
```
28062792
```
2807-
Selector name: bookmarks-type-dropdown
2808-
Selector Data: editBMPanel_folderMenuList
2809-
Description: Bookmark location
2810-
Location: Bookmark panel
2811-
Path to .json: modules/data/navigation.components.json
2812-
```
2813-
```
2814-
Selector name: bookmarks-type-dropdown-other
2815-
Selector Data: editBMPanel_unfiledRootItem
2816-
Description: Bookmark location - Other bookmarks
2817-
Location: Bookmark panel
2818-
Path to .json: modules/data/navigation.components.json
2819-
```
2820-
```
2821-
Selector name: other-bookmarks
2793+
Selector name: other-bookmarks-toolbar
28222794
Selector Data: OtherBookmarks
2823-
Description: Other bookmarks option
2824-
Location: Bookmark panel
2795+
Description: Other bookmarks folder
2796+
Location: Toolbar
28252797
Path to .json: modules/data/navigation.components.json
28262798
```
28272799
```
@@ -3246,6 +3218,27 @@ Location: On the hamburger menu > Bookmarks
32463218
Path to .json: modules/data/panel_ui.components.json
32473219
```
32483220
```
3221+
Selector name: bookmarks-type-dropdown
3222+
Selector Data: editBMPanel_folderMenuList
3223+
Description: Bookmark location
3224+
Location: Bookmark panel
3225+
Path to .json: modules/data/navigation.components.json
3226+
```
3227+
```
3228+
Selector name: bookmarks-type-dropdown-other
3229+
Selector Data: editBMPanel_unfiledRootItem
3230+
Description: Bookmark location - Other bookmarks
3231+
Location: Bookmark panel
3232+
Path to .json: modules/data/navigation.components.json
3233+
```
3234+
```
3235+
Selector name: save-bookmark-button
3236+
Selector Data: editBookmarkPanelDoneButton
3237+
Description: Save bookmark
3238+
Location: Bookmark panel
3239+
Path to .json: modules/data/navigation.components.json
3240+
```
3241+
```
32493242
Selector name: iframe
32503243
Selector Data: dialogFrame
32513244
Description: iframe
@@ -3392,6 +3385,14 @@ Description: Bookmarks toolbar
33923385
Location: Bookmarks toolbar
33933386
Path to .json: modules/data/panel_ui.components.json
33943387
```
3388+
```
3389+
Selector name: edit-bookmark-panel
3390+
Selector Data: editBMPanel_namePicker
3391+
Description: Edit bookmark panel
3392+
Location: Bookmark panel
3393+
Path to .json: modules/data/pane_ui.components.json
3394+
```
3395+
```
33953396
#### print_preview
33963397
```
33973398
Selector name: print-preview-browser

modules/browser_object_navigation.py

Lines changed: 228 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from selenium.webdriver.remote.webelement import WebElement
88
from selenium.webdriver.support import expected_conditions as EC
99

10+
from modules.browser_object_context_menu import ContextMenu
11+
from modules.browser_object_panel_ui import PanelUi
1012
from modules.classes.bookmark import Bookmark
1113
from modules.page_base import BasePage
1214
from modules.util import BrowserActions
@@ -36,6 +38,9 @@ def __init__(self, driver: Firefox, **kwargs):
3638
self.search_bar = None
3739
self.awesome_bar = None
3840
self.change_search_settings_button = None
41+
self.bookmarks_toolbar = "bookmarks-toolbar"
42+
self.context_menu = ContextMenu(self.driver)
43+
self.panel_ui = PanelUi(self.driver)
3944

4045
@BasePage.context_content
4146
def expect_in_content(self, condition) -> BasePage:
@@ -314,15 +319,22 @@ def select_element_in_nav(self, element: str) -> BasePage:
314319
self.get_element(element).click()
315320
return self
316321

322+
@BasePage.context_chrome
323+
def get_legacy_search_engine_label(self) -> str:
324+
"""Return the displayed engine name from the legacy search bar."""
325+
return self.driver.find_element(
326+
By.CSS_SELECTOR, ".searchbar-engine-name"
327+
).get_attribute("value")
328+
317329
# Bookmark
318330

319331
@BasePage.context_chrome
320332
def add_bookmark_via_star_icon(self) -> BasePage:
321333
"""
322334
Bookmark a site via star button and click save on the bookmark panel
323335
"""
324-
self.get_element("star-button").click()
325-
self.get_element("save-bookmark-button").click()
336+
self.click_on("star-button")
337+
self.panel_ui.click_on("save-bookmark-button")
326338
return self
327339

328340
@BasePage.context_chrome
@@ -334,19 +346,27 @@ def verify_star_button_is_blue(self) -> BasePage:
334346
return self
335347

336348
@BasePage.context_chrome
337-
def bookmark_page_other(self) -> BasePage:
338-
self.get_element("star-button").click()
339-
dropdown = self.get_element("bookmarks-type-dropdown")
340-
dropdown.click()
341-
self.get_element("bookmarks-type-dropdown-other").click()
342-
dropdown.click()
343-
self.get_element("save-bookmark-button").click()
349+
def bookmark_page_in_other_bookmarks(self) -> BasePage:
350+
"""
351+
Bookmark the current page in the Other Bookmarks folder via the star icon in the address bar.
352+
"""
353+
self.click_on("star-button")
354+
self.panel_ui.click_on("bookmarks-type-dropdown")
355+
self.panel_ui.click_on("bookmarks-type-dropdown-other")
356+
self.panel_ui.click_on("save-bookmark-button")
344357
return self
345358

346359
@BasePage.context_chrome
347-
def add_bookmark_via_other_bookmark_context_menu(
360+
def add_bookmark_via_toolbar_other_bookmark_context_menu(
348361
self, bookmark_data: Bookmark, ba: BrowserActions
349362
) -> BasePage:
363+
"""
364+
Add a bookmark via the toolbar's Other Bookmarks context menu.
365+
366+
Arguments:
367+
bookmark_data : A Bookmark object containing the bookmark details to be added (name, url, tags, keyword)
368+
ba : BrowserActions utility
369+
"""
350370
iframe = self.get_element("bookmark-iframe")
351371
ba.switch_to_iframe_context(iframe)
352372
# fill name
@@ -366,8 +386,9 @@ def add_bookmark_via_other_bookmark_context_menu(
366386

367387
@BasePage.context_chrome
368388
def toggle_bookmarks_toolbar_with_key_combo(self) -> BasePage:
369-
"""Use Cmd/Ctrl + B to open the Print Preview, wait for load"""
370-
389+
"""
390+
Use Cmd/Ctrl + B to open the Print Preview, wait for load
391+
"""
371392
if self.sys_platform() == "Darwin":
372393
mod_key = Keys.COMMAND
373394
else:
@@ -396,8 +417,198 @@ def confirm_bookmark_exists(self, match_string: str) -> BasePage:
396417
return self
397418

398419
@BasePage.context_chrome
399-
def get_legacy_search_engine_label(self) -> str:
400-
"""Return the displayed engine name from the legacy search bar."""
401-
return self.driver.find_element(
402-
By.CSS_SELECTOR, ".searchbar-engine-name"
403-
).get_attribute("value")
420+
def open_add_bookmark_via_toolbar_other_bookmarks_context_menu(self) -> BasePage:
421+
"""
422+
Open the context menu for Other Bookmarks in the toolbar and select Add Bookmark option.
423+
"""
424+
self.click_on("other-bookmarks-toolbar")
425+
self.context_click("other-bookmarks-popup")
426+
self.context_menu.click_on("context-menu-add-bookmark")
427+
self.context_menu.hide_popup_by_child_node("context-menu-add-bookmark")
428+
self.hide_popup("OtherBookmarksPopup")
429+
return self
430+
431+
@BasePage.context_chrome
432+
def delete_bookmark_from_other_bookmarks_via_context_menu(
433+
self, bookmark_name: str
434+
) -> BasePage:
435+
"""
436+
Deletes a bookmark from Other Bookmarks via context menu.
437+
438+
Argument:
439+
bookmark_name: The display name of the bookmark to delete
440+
"""
441+
self.click_on("other-bookmarks-toolbar")
442+
self.panel_ui.context_click("other-bookmarks-by-title", labels=[bookmark_name])
443+
self.context_menu.click_and_hide_menu("context-menu-delete-page")
444+
return self
445+
446+
@BasePage.context_chrome
447+
def delete_bookmark_from_bookmarks_toolbar(self, bookmark_name: str) -> BasePage:
448+
"""
449+
Delete bookmark from bookmarks toolbar via context menu
450+
451+
Argument:
452+
bookmark_name: The display name of the bookmark to delete
453+
"""
454+
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_name])
455+
self.context_menu.click_and_hide_menu("context-menu-delete-page")
456+
return self
457+
458+
@BasePage.context_chrome
459+
def verify_bookmark_exists_in_toolbar_other_bookmarks_folder(
460+
self, bookmark_name: str
461+
) -> BasePage:
462+
"""
463+
Verify bookmark exists in Other Bookmarks folder from toolbar
464+
465+
Argument:
466+
bookmark_name : The exact name/title of the bookmark to search for in the Other Bookmarks folder.
467+
"""
468+
self.click_on("other-bookmarks-toolbar") # Navigation selector
469+
self.panel_ui.element_visible(
470+
"other-bookmarks-by-title", labels=[bookmark_name]
471+
)
472+
return self
473+
474+
@BasePage.context_chrome
475+
def verify_bookmark_exists_in_bookmarks_toolbar(
476+
self, bookmark_name: str
477+
) -> BasePage:
478+
"""
479+
Verify bookmark exists in the bookmarks toolbar
480+
"""
481+
self.panel_ui.element_visible("bookmark-by-title", labels=[bookmark_name])
482+
return self
483+
484+
@BasePage.context_chrome
485+
def verify_bookmark_does_not_exist_in_toolbar_other_bookmarks_folder(
486+
self, bookmark_name: str
487+
) -> BasePage:
488+
"""
489+
Verify bookmark does not exist in Other Bookmarks folder from toolbar
490+
491+
Argument:
492+
bookmark_name : The exact name/title of the bookmark to search for in the Other Bookmarks folder.
493+
"""
494+
self.click_on("other-bookmarks-toolbar")
495+
self.panel_ui.element_not_visible(
496+
"other-bookmarks-by-title", labels=[bookmark_name]
497+
)
498+
return self
499+
500+
@BasePage.context_chrome
501+
def verify_bookmark_does_not_exist_in_bookmarks_toolbar(
502+
self, bookmark_name: str
503+
) -> BasePage:
504+
"""Verify bookmark does not exist in the bookmarks toolbar"""
505+
self.panel_ui.element_not_visible("bookmark-by-title", labels=[bookmark_name])
506+
return self
507+
508+
@BasePage.context_chrome
509+
def edit_bookmark_via_star_button(self, new_name: str, location: str) -> BasePage:
510+
"""
511+
Edit bookmark details by opening the edit bookmark panel via the star button
512+
513+
Arguments:
514+
new_name : The new name/title to assign to the bookmark
515+
location : The folder location where the bookmark should be saved
516+
"""
517+
self.click_on("star-button")
518+
self.panel_ui.get_element("edit-bookmark-panel").send_keys(new_name)
519+
if location == "Other Bookmarks":
520+
self.panel_ui.click_on("bookmark-location")
521+
self.panel_ui.click_on("other-bookmarks")
522+
elif location == "Bookmarks Toolbar":
523+
self.panel_ui.click_on("bookmark-location")
524+
self.panel_ui.click_on("bookmarks-toolbar")
525+
# for else add Bookmark Menu option if needed in the future
526+
self.panel_ui.click_on("save-bookmark-button")
527+
return self
528+
529+
@BasePage.context_chrome
530+
def toggle_show_editor_when_saving(self) -> BasePage:
531+
"""
532+
Toggle the show editor checkbox
533+
"""
534+
self.click_on("star-button")
535+
self.panel_ui.click_on("show-editor-when-saving-checkbox")
536+
self.panel_ui.click_on("save-bookmark-button")
537+
return self
538+
539+
@BasePage.context_chrome
540+
def verify_edit_bookmark_panel_not_visible_after_navigation(self) -> BasePage:
541+
"""
542+
Navigate to new URL and verify that edit bookmark panel is not visible when clicking star
543+
Uses the exact same pattern as the working test
544+
"""
545+
self.click_on("star-button")
546+
self.panel_ui.element_not_visible("show-editor-when-saving-checkbox")
547+
return self
548+
549+
@BasePage.context_chrome
550+
def open_bookmark_from_toolbar(self, bookmark_title: str) -> BasePage:
551+
"""
552+
Clicks a bookmark on the bookmark toolbar to open it in the current tab
553+
554+
Argument:
555+
bookmark_title: The title of the bookmark to open
556+
"""
557+
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
558+
self.panel_ui.click_on("bookmark-by-title", labels=[bookmark_title])
559+
return self
560+
561+
@BasePage.context_chrome
562+
def open_bookmark_in_new_window_via_context_menu(
563+
self, bookmark_title: str
564+
) -> BasePage:
565+
"""
566+
Right-click bookmark and opens it in a new window via context menu
567+
568+
Argument:
569+
bookmark_title: The title of the bookmark to open
570+
"""
571+
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
572+
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_title])
573+
self.context_menu.click_on("context-menu-toolbar-open-in-new-window")
574+
return self
575+
576+
@BasePage.context_chrome
577+
def open_bookmark_in_new_private_window_via_context_menu(
578+
self, bookmark_title: str
579+
) -> BasePage:
580+
"""
581+
Right-clicks bookmark and opens it in a new private window via context menu
582+
583+
Argument:
584+
bookmark_title: The title of the bookmark to open
585+
"""
586+
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
587+
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_title])
588+
self.context_menu.click_on("context-menu-toolbar-open-in-new-private-window")
589+
return self
590+
591+
@BasePage.context_chrome
592+
def open_all_bookmarks_via_context_menu(self) -> BasePage:
593+
"""
594+
Right-clicks on bookmarks toolbar and opens all bookmarks via context menu
595+
"""
596+
self.context_click("bookmarks-toolbar")
597+
self.context_menu.click_on("context-menu-toolbar-open-all-bookmarks")
598+
return self
599+
600+
@BasePage.context_chrome
601+
def expect_bookmarks_toolbar_visibility(self, expected: bool) -> None:
602+
"""
603+
Assert the visibility state of the Bookmarks Toolbar.
604+
605+
Argument:
606+
expected (bool):
607+
If True, asserts that the toolbar is visible (collapsed="false").
608+
If False, asserts that the toolbar is hidden (collapsed="true")
609+
"""
610+
611+
expected_value = "false" if expected else "true"
612+
self.expect_element_attribute_contains(
613+
self.bookmarks_toolbar, "collapsed", expected_value
614+
)

0 commit comments

Comments
 (0)