From 17a0104501f427d2c34a24b11fd39ccb48e2b5b1 Mon Sep 17 00:00:00 2001 From: dragosb01 Date: Tue, 26 Nov 2024 08:20:27 +0200 Subject: [PATCH] Fixes MTE-2812 - auto tests for toolbar changes --- .../Tests/XCUITests/FirefoxSuggestTest.swift | 1 + .../Tests/XCUITests/FxScreenGraph.swift | 11 ++++----- .../Tests/XCUITests/HomeButtonTests.swift | 8 +++---- .../XCUITests/HomePageSettingsUITest.swift | 6 ++--- .../Tests/XCUITests/NavigationTest.swift | 2 +- .../Tests/XCUITests/ReadingListTests.swift | 24 ------------------- .../Tests/XCUITests/ToolbarTest.swift | 16 ++++--------- .../XCUITests/TrackingProtectionTests.swift | 4 +--- 8 files changed, 18 insertions(+), 54 deletions(-) diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/FirefoxSuggestTest.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/FirefoxSuggestTest.swift index ba34211c5733..792c612881f0 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/FirefoxSuggestTest.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/FirefoxSuggestTest.swift @@ -8,6 +8,7 @@ class FirefoxSuggestTest: BaseTestCase { // https://mozilla.testrail.io/index.php?/cases/view/2360075 func testFirefoxSuggestExists() { navigator.openURL("www.example.com") + waitUntilPageLoad() navigator.createNewTab() navigator.goto(URLBarOpen) urlBarAddress.typeText("ex") diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/FxScreenGraph.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/FxScreenGraph.swift index 2e67c344bfae..08b16fdb64d4 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/FxScreenGraph.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/FxScreenGraph.swift @@ -310,7 +310,7 @@ func createScreenGraph(for test: XCTestCase, with app: XCUIApplication) -> MMScr screenState.tap(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton], to: TabTray) } else { screenState.gesture(to: TabTray) { - app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].tap() + app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].waitAndTap() } } makeURLBarAvailable(screenState) @@ -460,7 +460,7 @@ func createScreenGraph(for test: XCTestCase, with app: XCUIApplication) -> MMScr screenState.tap(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton], to: TabTray) } else { screenState.gesture(to: TabTray) { - app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].tap() + app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].waitAndTap() } } @@ -942,7 +942,7 @@ func createScreenGraph(for test: XCTestCase, with app: XCUIApplication) -> MMScr screenState.tap(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton], to: TabTray) } else { screenState.gesture(to: TabTray) { - app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].tap() + app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].waitAndTap() } } } @@ -991,7 +991,7 @@ func createScreenGraph(for test: XCTestCase, with app: XCUIApplication) -> MMScr screenState.tap(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton], to: TabTray) } else { screenState.gesture(to: TabTray) { - app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].tap() + app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].waitAndTap() } } @@ -1241,8 +1241,7 @@ extension MMNavigator where T == FxUserState { func createNewTab() { let app = XCUIApplication() self.goto(TabTray) - mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) - app.buttons[AccessibilityIdentifiers.TabTray.newTabButton].tap() + app.buttons[AccessibilityIdentifiers.TabTray.newTabButton].waitAndTap() self.nowAt(NewTabScreen) } diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomeButtonTests.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomeButtonTests.swift index 077bc2a1e2b1..208bcc28624c 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomeButtonTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomeButtonTests.swift @@ -37,19 +37,19 @@ class HomeButtonTests: BaseTestCase { // Switch to Homepage by taping the home button app.buttons[AccessibilityIdentifiers.Toolbar.addNewTabButton].waitAndTap() - validateHomePageAndKeyboardNotRaisedUp() + validateHomePageAndKeyboardRaisedUp() } // https://mozilla.testrail.io/index.php?/cases/view/2306881 func testAppLaunchKeyboardNotRaisedUp() { mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton]) - validateHomePageAndKeyboardNotRaisedUp() + validateHomePageAndKeyboardRaisedUp() } - private func validateHomePageAndKeyboardNotRaisedUp() { + private func validateHomePageAndKeyboardRaisedUp() { // The home page is loaded. The keyboard is not raised up navigator.nowAt(NewTabScreen) waitForTabsButton() - XCTAssertFalse(app.keyboards.element.isVisible(), "The keyboard is shown") + XCTAssertTrue(app.keyboards.element.isVisible(), "The keyboard is not shown") } } diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomePageSettingsUITest.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomePageSettingsUITest.swift index eb0b5d4b309b..a374896a582a 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomePageSettingsUITest.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/HomePageSettingsUITest.swift @@ -266,10 +266,8 @@ class HomePageSettingsUITests: BaseTestCase { bookmarkPages() addContentToReaderView() if iPad() { - mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton]) - app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].tap() - mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton]) - app.buttons[AccessibilityIdentifiers.TabTray.newTabButton].tap() + app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].waitAndTap() + app.buttons[AccessibilityIdentifiers.TabTray.newTabButton].waitAndTap() } else { navigator.performAction(Action.GoToHomePage) } diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift index 2025857f27a7..dabe11e87833 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift @@ -561,7 +561,7 @@ class NavigationTest: BaseTestCase { if iPad() { if let urlTextField = app.textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField].value as? String, - urlTextField == "ultimateqa.com/dummy-automation-websites" { + urlTextField == "ultimateqa.com" { app.links["SauceDemo.com"].firstMatch.tap(force: true) } } diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/ReadingListTests.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/ReadingListTests.swift index 61be9eedd8d1..2dd2441b72ac 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/ReadingListTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/ReadingListTests.swift @@ -44,9 +44,6 @@ class ReadingListTests: BaseTestCase { // Add item to reading list and check that it appears addContentToReaderView() navigator.goto(BrowserTabMenu) - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) // Check that there is one item @@ -73,9 +70,6 @@ class ReadingListTests: BaseTestCase { // Add item to reading list and check that it appears addContentToReaderView() navigator.goto(BrowserTabMenu) - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) // Check that there is one item @@ -119,9 +113,6 @@ class ReadingListTests: BaseTestCase { // Go to reader list view to check that there is not any item there navigator.goto(BrowserTabMenu) - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) checkReadingListNumberOfItems(items: 0) } @@ -130,9 +121,6 @@ class ReadingListTests: BaseTestCase { func testMarkAsReadAndUnreadFromReadingList() throws { addContentToReaderView() navigator.goto(BrowserTabMenu) - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) mozWaitForElementToExist(app.tables["ReadingTable"]) @@ -152,9 +140,6 @@ class ReadingListTests: BaseTestCase { func testRemoveFromReadingList() { addContentToReaderView() navigator.goto(BrowserTabMenu) - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) let savedToReadingList = app.tables["ReadingTable"].cells.staticTexts["The Book of Mozilla"] @@ -194,9 +179,6 @@ class ReadingListTests: BaseTestCase { // Add item to Reading List addContentToReaderView() - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) // Long tap on the item just saved @@ -219,9 +201,6 @@ class ReadingListTests: BaseTestCase { func testRemoveSavedForReadingLongPress() { // Add item to Reading List addContentToReaderView() - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) // Long tap on the item just saved and choose remove @@ -255,9 +234,6 @@ class ReadingListTests: BaseTestCase { // Add item to reading list and check that it appears addContentToReaderView() navigator.goto(BrowserTabMenu) - if iPad() { - app.buttons[AccessibilityIdentifiers.Toolbar.settingsMenuButton].tapOnApp() - } navigator.goto(LibraryPanel_ReadingList) let savedToReadingList = app.tables["ReadingTable"].cells.staticTexts["The Book of Mozilla"] mozWaitForElementToExist(savedToReadingList) diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/ToolbarTest.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/ToolbarTest.swift index 70e674f466e0..b31ea93dc930 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/ToolbarTest.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/ToolbarTest.swift @@ -156,22 +156,14 @@ class ToolbarTests: BaseTestCase { } private func validateAddNewTabButtonOnToolbar(isPrivate: Bool) { - mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.addNewTabButton]) + mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton]) restartInBackground() - mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.addNewTabButton]) - mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.addNewTabButton]) - restartInBackground() - mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.addNewTabButton]) + mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton]) // Swipe up to close the app does not work on iOS 15. if #available(iOS 16, *) { closeFromAppSwitcherAndRelaunch() - let addNewTabButton = app.buttons[AccessibilityIdentifiers.Toolbar.addNewTabButton] - mozWaitForElementToExist(addNewTabButton) - addNewTabButton.tapOnApp() - if !app.buttons[AccessibilityIdentifiers.Browser.UrlBar.cancelButton].exists { - addNewTabButton.tap() - } - app.buttons[AccessibilityIdentifiers.Browser.UrlBar.cancelButton].waitAndTap() + app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].waitAndTap() + app.buttons[AccessibilityIdentifiers.TabTray.newTabButton].waitAndTap() mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton]) XCTAssertEqual(app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].value as? String, "2") } diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/TrackingProtectionTests.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/TrackingProtectionTests.swift index 90fcf045bfb1..e27cbf362aed 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/TrackingProtectionTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/TrackingProtectionTests.swift @@ -211,9 +211,7 @@ class TrackingProtectionTests: BaseTestCase { waitForElementsToExist( [ app.staticTexts["mozilla.org"], - // Need to determine what message should be displayed inside TP screen - // app.staticTexts["Secure connection"] - app.staticTexts["Connection not secure"] + app.staticTexts["Secure connection"] ] ) XCTAssertEqual(