7
7
from selenium .webdriver .remote .webelement import WebElement
8
8
from selenium .webdriver .support import expected_conditions as EC
9
9
10
+ from modules .browser_object_context_menu import ContextMenu
11
+ from modules .browser_object_panel_ui import PanelUi
10
12
from modules .classes .bookmark import Bookmark
11
13
from modules .page_base import BasePage
12
14
from modules .util import BrowserActions
@@ -36,6 +38,9 @@ def __init__(self, driver: Firefox, **kwargs):
36
38
self .search_bar = None
37
39
self .awesome_bar = None
38
40
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 )
39
44
40
45
@BasePage .context_content
41
46
def expect_in_content (self , condition ) -> BasePage :
@@ -314,15 +319,22 @@ def select_element_in_nav(self, element: str) -> BasePage:
314
319
self .get_element (element ).click ()
315
320
return self
316
321
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
+
317
329
# Bookmark
318
330
319
331
@BasePage .context_chrome
320
332
def add_bookmark_via_star_icon (self ) -> BasePage :
321
333
"""
322
334
Bookmark a site via star button and click save on the bookmark panel
323
335
"""
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" )
326
338
return self
327
339
328
340
@BasePage .context_chrome
@@ -334,19 +346,27 @@ def verify_star_button_is_blue(self) -> BasePage:
334
346
return self
335
347
336
348
@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" )
344
357
return self
345
358
346
359
@BasePage .context_chrome
347
- def add_bookmark_via_other_bookmark_context_menu (
360
+ def add_bookmark_via_toolbar_other_bookmark_context_menu (
348
361
self , bookmark_data : Bookmark , ba : BrowserActions
349
362
) -> 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
+ """
350
370
iframe = self .get_element ("bookmark-iframe" )
351
371
ba .switch_to_iframe_context (iframe )
352
372
# fill name
@@ -366,8 +386,9 @@ def add_bookmark_via_other_bookmark_context_menu(
366
386
367
387
@BasePage .context_chrome
368
388
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
+ """
371
392
if self .sys_platform () == "Darwin" :
372
393
mod_key = Keys .COMMAND
373
394
else :
@@ -396,8 +417,198 @@ def confirm_bookmark_exists(self, match_string: str) -> BasePage:
396
417
return self
397
418
398
419
@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