From e41040fc701bae3123d2b1bf0e92cb7cd371514d Mon Sep 17 00:00:00 2001 From: Juan Manuel Pereira Date: Mon, 9 Sep 2024 18:04:34 -0300 Subject: [PATCH 1/2] Fix the current issue by not tapping popover if not present --- DuckDuckGo/Menus/MainMenuActions.swift | 1 - UITests/BookmarksAndFavoritesTests.swift | 16 ++-------------- UITests/Common/XCUIApplicationExtension.swift | 10 +++++++++- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/DuckDuckGo/Menus/MainMenuActions.swift b/DuckDuckGo/Menus/MainMenuActions.swift index 354d9b0806..d642000b9a 100644 --- a/DuckDuckGo/Menus/MainMenuActions.swift +++ b/DuckDuckGo/Menus/MainMenuActions.swift @@ -810,7 +810,6 @@ extension MainViewController { @objc func resetBookmarks(_ sender: Any?) { LocalBookmarkManager.shared.resetBookmarks() UserDefaults.standard.set(false, forKey: UserDefaultsWrapper.Key.homePageContinueSetUpImport.rawValue) - UserDefaults.standard.set(false, forKey: UserDefaultsWrapper.Key.bookmarksBarPromptShown.rawValue) LocalBookmarkManager.shared.sortMode = .manual } diff --git a/UITests/BookmarksAndFavoritesTests.swift b/UITests/BookmarksAndFavoritesTests.swift index 7c9bb93673..a889b13a7e 100644 --- a/UITests/BookmarksAndFavoritesTests.swift +++ b/UITests/BookmarksAndFavoritesTests.swift @@ -47,7 +47,6 @@ class BookmarksAndFavoritesTests: XCTestCase { private var openBookmarksMenuItem: XCUIElement! private var optionsButton: XCUIElement! private var removeFavoritesContextMenuItem: XCUIElement! - private var resetBookMarksMenuItem: XCUIElement! private var settingsAppearanceButton: XCUIElement! private var showBookmarksBarPreferenceToggle: XCUIElement! private var showBookmarksBarAlways: XCUIElement! @@ -87,7 +86,6 @@ class BookmarksAndFavoritesTests: XCTestCase { openBookmarksMenuItem = app.menuItems["MoreOptionsMenu.openBookmarks"] optionsButton = app.buttons["NavigationBarViewController.optionsButton"] removeFavoritesContextMenuItem = app.menuItems["HomePage.Views.removeFavorite"] - resetBookMarksMenuItem = app.menuItems["MainMenu.resetBookmarks"] settingsAppearanceButton = app.buttons["PreferencesSidebar.appearanceButton"] showBookmarksBarAlways = app.menuItems["Preferences.AppearanceView.showBookmarksBarAlways"] showBookmarksBarPopup = app.popUpButtons["Preferences.AppearanceView.showBookmarksBarPopUp"] @@ -95,9 +93,8 @@ class BookmarksAndFavoritesTests: XCTestCase { showFavoritesPreferenceToggle = app.checkBoxes["Preferences.AppearanceView.showFavoritesToggle"] app.launch() - resetBookmarks() - app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Let's enforce a single window - app.typeKey("n", modifierFlags: .command) + app.resetBookmarks() + app.enforceSingleWindow() } func test_bookmarks_canBeAddedTo_withContextClickBookmarkThisPage() { @@ -641,15 +638,6 @@ class BookmarksAndFavoritesTests: XCTestCase { } private extension BookmarksAndFavoritesTests { - /// Reset the bookmarks so we can rely on a single bookmark's existence - func resetBookmarks() { - app.typeKey("n", modifierFlags: [.command]) // Can't use debug menu without a window - XCTAssertTrue( - resetBookMarksMenuItem.waitForExistence(timeout: UITests.Timeouts.elementExistence), - "Reset bookmarks menu item didn't become available in a reasonable timeframe." - ) - resetBookMarksMenuItem.click() - } /// Make sure that we can reply on the bookmarks bar always appearing func toggleShowBookmarksBarAlwaysOn() { diff --git a/UITests/Common/XCUIApplicationExtension.swift b/UITests/Common/XCUIApplicationExtension.swift index cad7b771cd..e0c3b97aca 100644 --- a/UITests/Common/XCUIApplicationExtension.swift +++ b/UITests/Common/XCUIApplicationExtension.swift @@ -33,11 +33,19 @@ extension XCUIApplication { static let resetBookmarksMenuItem = "MainMenu.resetBookmarks" } - /// Dismiss popover with the passed button identifier + /// Dismiss popover with the passed button identifier if exists. If it does not exist it continues the execution without failing. /// - Parameter buttonIdentifier: The button identifier we want to tap from the popover func dismissPopover(buttonIdentifier: String) { let popover = popovers.firstMatch + guard popover.exists else { + return + } + let button = popover.buttons[buttonIdentifier] + guard button.exists else { + return + } + button.tap() } From 0bb534ab92d91d4e1ed688ed3158769a31702361 Mon Sep 17 00:00:00 2001 From: Juan Manuel Pereira Date: Wed, 11 Sep 2024 17:39:26 -0300 Subject: [PATCH 2/2] Revert reset bookmarks --- UITests/BookmarksAndFavoritesTests.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/UITests/BookmarksAndFavoritesTests.swift b/UITests/BookmarksAndFavoritesTests.swift index a889b13a7e..7c9bb93673 100644 --- a/UITests/BookmarksAndFavoritesTests.swift +++ b/UITests/BookmarksAndFavoritesTests.swift @@ -47,6 +47,7 @@ class BookmarksAndFavoritesTests: XCTestCase { private var openBookmarksMenuItem: XCUIElement! private var optionsButton: XCUIElement! private var removeFavoritesContextMenuItem: XCUIElement! + private var resetBookMarksMenuItem: XCUIElement! private var settingsAppearanceButton: XCUIElement! private var showBookmarksBarPreferenceToggle: XCUIElement! private var showBookmarksBarAlways: XCUIElement! @@ -86,6 +87,7 @@ class BookmarksAndFavoritesTests: XCTestCase { openBookmarksMenuItem = app.menuItems["MoreOptionsMenu.openBookmarks"] optionsButton = app.buttons["NavigationBarViewController.optionsButton"] removeFavoritesContextMenuItem = app.menuItems["HomePage.Views.removeFavorite"] + resetBookMarksMenuItem = app.menuItems["MainMenu.resetBookmarks"] settingsAppearanceButton = app.buttons["PreferencesSidebar.appearanceButton"] showBookmarksBarAlways = app.menuItems["Preferences.AppearanceView.showBookmarksBarAlways"] showBookmarksBarPopup = app.popUpButtons["Preferences.AppearanceView.showBookmarksBarPopUp"] @@ -93,8 +95,9 @@ class BookmarksAndFavoritesTests: XCTestCase { showFavoritesPreferenceToggle = app.checkBoxes["Preferences.AppearanceView.showFavoritesToggle"] app.launch() - app.resetBookmarks() - app.enforceSingleWindow() + resetBookmarks() + app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Let's enforce a single window + app.typeKey("n", modifierFlags: .command) } func test_bookmarks_canBeAddedTo_withContextClickBookmarkThisPage() { @@ -638,6 +641,15 @@ class BookmarksAndFavoritesTests: XCTestCase { } private extension BookmarksAndFavoritesTests { + /// Reset the bookmarks so we can rely on a single bookmark's existence + func resetBookmarks() { + app.typeKey("n", modifierFlags: [.command]) // Can't use debug menu without a window + XCTAssertTrue( + resetBookMarksMenuItem.waitForExistence(timeout: UITests.Timeouts.elementExistence), + "Reset bookmarks menu item didn't become available in a reasonable timeframe." + ) + resetBookMarksMenuItem.click() + } /// Make sure that we can reply on the bookmarks bar always appearing func toggleShowBookmarksBarAlwaysOn() {