diff --git a/firefox-ios/firefox-ios-tests/Tests/FullFunctionalTestPlan.xctestplan b/firefox-ios/firefox-ios-tests/Tests/FullFunctionalTestPlan.xctestplan index 6b3928a970e9b..bf232e33a1231 100644 --- a/firefox-ios/firefox-ios-tests/Tests/FullFunctionalTestPlan.xctestplan +++ b/firefox-ios/firefox-ios-tests/Tests/FullFunctionalTestPlan.xctestplan @@ -115,6 +115,7 @@ "CreditCardsTests\/testEditSavedCardsUI()", "CronTabsPerformanceTest", "DataManagementTests\/testWebSiteDataEnterFirstTime()", + "DataManagementTests\/testWebSiteDataEnterFirstTime_TAE()", "DatabaseFixtureTest\/testPerBookmarks1000openMenu()", "DatabaseFixtureTest\/testPerBookmarks1000startUp()", "DatabaseFixtureTest\/testPerfHistory4000openMenu()", diff --git a/firefox-ios/firefox-ios-tests/Tests/Smoketest.xctestplan b/firefox-ios/firefox-ios-tests/Tests/Smoketest.xctestplan index a8a74762996ba..db89f7549806f 100644 --- a/firefox-ios/firefox-ios-tests/Tests/Smoketest.xctestplan +++ b/firefox-ios/firefox-ios-tests/Tests/Smoketest.xctestplan @@ -188,6 +188,7 @@ "CreditCardsTests\/testVerifyThatTheEditedCreditCardIsSaved()", "CronTabsPerformanceTest", "DataManagementTests\/testFilterWebsiteData()", + "DataManagementTests\/testWebSiteDataEnterFirstTime_TAE()", "DataManagementTests\/testWebSiteDataOptions()", "DatabaseFixtureTest", "DesktopModeTestsIphone\/testClearPrivateData()", diff --git a/firefox-ios/firefox-ios-tests/Tests/TAESmokeTestPlan.xctestplan b/firefox-ios/firefox-ios-tests/Tests/TAESmokeTestPlan.xctestplan index dcbef7673226b..6a17d0a04a593 100644 --- a/firefox-ios/firefox-ios-tests/Tests/TAESmokeTestPlan.xctestplan +++ b/firefox-ios/firefox-ios-tests/Tests/TAESmokeTestPlan.xctestplan @@ -117,7 +117,6 @@ "CreditCardsTests\/testUpdatePrompt()", "CreditCardsTests\/testVerifyThatMultipleCardsCanBeAdded()", "CreditCardsTests\/testVerifyThatTheEditedCreditCardIsSaved()", - "DataManagementTests", "DataManagementTests\/testFilterWebsiteData()", "DataManagementTests\/testWebSiteDataEnterFirstTime()", "DataManagementTests\/testWebSiteDataOptions()", diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/DataManagementTests.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/DataManagementTests.swift index acf3a4e1c7df3..5cfc10caafb6f 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/DataManagementTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/DataManagementTests.swift @@ -5,6 +5,8 @@ import XCTest class DataManagementTests: BaseTestCase { + private var webSitesDataScreen: WebsiteDataScreen! + func cleanAllData() { navigator.goto(WebsiteDataSettings) mozWaitForElementToExist(app.tables.otherElements["Website Data"]) @@ -88,6 +90,22 @@ class DataManagementTests: BaseTestCase { } } + // https://mozilla.testrail.io/index.php?/cases/view/2307017 + // Smoketest TAE + func testWebSiteDataEnterFirstTime_TAE() { + webSitesDataScreen = WebsiteDataScreen(app: app) + navigator.goto(WebsiteDataSettings) + webSitesDataScreen.clearAllWebsiteData() + navigator.nowAt(NewTabScreen) + navigator.openURL("example.com") + waitUntilPageLoad() + navigator.goto(WebsiteDataSettings) + webSitesDataScreen.waitUntilListIsReady() + webSitesDataScreen.expandShowMoreIfNeeded() + webSitesDataScreen.waitForExampleDomain() + webSitesDataScreen.assertWebsiteDataVisible() + } + // https://mozilla.testrail.io/index.php?/cases/view/2802088 func testFilterWebsiteData() { cleanAllData() diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/PageScreens/WebsiteDataScreen.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/PageScreens/WebsiteDataScreen.swift new file mode 100644 index 0000000000000..885a76d155a1a --- /dev/null +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/PageScreens/WebsiteDataScreen.swift @@ -0,0 +1,76 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/ + +import XCTest + +final class WebsiteDataScreen { + private let app: XCUIApplication + private let sel: WebsiteDataSelectorsSet + + init(app: XCUIApplication, selectors: WebsiteDataSelectorsSet = WebsiteDataSelectors()) { + self.app = app + self.sel = selectors + } + + func clearAllWebsiteData() { + BaseTestCase().mozWaitForElementToExist(sel.TABLE_WEBSITE_DATA.element(in: app)) + BaseTestCase().mozWaitForElementToNotExist(app.activityIndicators.firstMatch) + + let clearAll = sel.clearAllLabel(in: app) + BaseTestCase().mozWaitForElementToExist(clearAll) + clearAll.waitAndTap() + + let okButton = sel.ALERT_OK_BUTTON.element(in: app) + okButton.waitAndTap() + BaseTestCase().mozWaitForElementToNotExist(okButton) + sel.BUTTON_DATA_MANAGEMENT.element(in: app).waitAndTap() + sel.BUTTON_SETTINGS.element(in: app).waitAndTap() + sel.BUTTON_DONE.element(in: app).waitAndTap() + } + + func assertAllWebsiteDataCleared() { + XCTAssertEqual(app.cells.buttons.images.count, 0, "The Website data has not cleared correctly") + } + + func navigateBackToBrowser() { + Selector.buttonByLabel("Data Management", description: "Back").element(in: app).waitAndTap() + Selector.buttonByLabel("Settings", description: "Back").element(in: app).waitAndTap() + Selector.buttonByLabel("Done", description: "Done").element(in: app).waitAndTap() + } + + func waitUntilListIsReady(timeout: TimeInterval = TIMEOUT) { + BaseTestCase().mozWaitForElementToExist(sel.TABLE_WEBSITE_DATA.element(in: app), timeout: timeout) + + if #available(iOS 17, *) { + let circleInCells = sel.circleImageInsideCells(app) + BaseTestCase().mozWaitForElementToExist(circleInCells, timeout: timeout) + } else { + let anyBtn = sel.anyTableButton(app) + BaseTestCase().mozWaitForElementToExist(anyBtn, timeout: timeout) + } + } + + func expandShowMoreIfNeeded() { + let showMore = sel.CELL_SHOW_MORE.element(in: app) + if showMore.exists { + showMore.waitAndTap() + } + } + + func waitForExampleDomain(timeout: TimeInterval = TIMEOUT) { + BaseTestCase().mozWaitForElementToExist(sel.EXAMPLE_EQUAL.element(in: app), timeout: timeout) + } + + func assertWebsiteDataVisible(timeout: TimeInterval = TIMEOUT) { + if #available(iOS 17, *) { + let circle = sel.circleImageInsideCells(app) + BaseTestCase().mozWaitForElementToExist(circle, timeout: timeout) + XCTAssertTrue(circle.exists, "Expected circle image inside cells") + } else { + let exampleText = sel.STATIC_TEXT_EXAMPLE_IN_CELL.element(in: app) + BaseTestCase().mozWaitForElementToExist(exampleText, timeout: timeout) + XCTAssertTrue(exampleText.exists, "Expected a staticText 'example.com' inside a cell") + } + } +} diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorHelper.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorHelper.swift index 23e173e25964e..a18a4cfa2a54f 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorHelper.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorHelper.swift @@ -14,6 +14,8 @@ enum SelectorStrategy { case collectionViewById(String) case tableById(String) case textFieldById(String) + case imageById(String) + case otherInTablesById(String) } // Selector model (with metadata) @@ -60,6 +62,10 @@ extension Selector { return app.tables[value] case .textFieldById: return app.textFields[value] + case .imageById: + return app.images[value] + case .otherInTablesById(let id): + return app.tables.otherElements[id] } } @@ -86,6 +92,10 @@ extension Selector { return app.tables.matching(identifier: value) case .textFieldById: return app.textFields.matching(identifier: value) + case .imageById: + return app.images.matching(identifier: value) + case .otherInTablesById(let id): + return app.tables.otherElements.matching(identifier: id) } } diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorShortcuts.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorShortcuts.swift index e66146d318e89..7d022939dd5fd 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorShortcuts.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/SelectorShortcuts.swift @@ -77,4 +77,85 @@ extension Selector { let p = NSPredicate(format: "elementType == %d", XCUIElement.ElementType.table.rawValue) return Selector(strategy: .predicate(p), value: "firstTable", description: description, groups: groups) } + + static func imageId(_ id: String, description: String, groups: [String] = []) -> Selector { + Selector(strategy: .imageById(id), value: id, description: description, groups: groups) + } +/* + static func buttonByLabel(_ label: String, description: String, groups: [String] = []) -> Selector { + let predicate = NSPredicate( + format: "elementType == %d AND label == %@", + XCUIElement.ElementType.button.rawValue, + label + ) + return Selector(strategy: .predicate(predicate), value: label, description: description, groups: groups) + } +*/ + static func tableOtherById(_ id: String, description: String, groups: [String] = []) -> Selector { + Selector(strategy: .otherInTablesById(id), value: id, description: description, groups: groups) + } + + static func cellById(_ id: String, description: String, groups: [String] = []) -> Selector { + let p = NSPredicate(format: "elementType == %d AND identifier == %@", + XCUIElement.ElementType.cell.rawValue, + id) + return Selector(strategy: .predicate(p), value: id, description: description, groups: groups) + } + + static func imageById(_ id: String, description: String, groups: [String] = []) -> Selector { + Selector( + strategy: .predicate( + NSPredicate( + format: "elementType == %d AND identifier == %@", + XCUIElement.ElementType.image.rawValue, + id + ) + ), + value: id, + description: description, + groups: groups + ) + } + + static func staticTextByExactLabel(_ label: String, description: String, groups: [String] = []) -> Selector { + Selector( + strategy: .predicate( + NSPredicate( + format: "elementType == %d AND label == %@", + XCUIElement.ElementType.staticText.rawValue, + label + ) + ), + value: label, + description: description, + groups: groups + ) + } + + static func staticTextLabelContains(_ text: String, description: String, groups: [String] = []) -> Selector { + Selector( + strategy: .predicate( + NSPredicate( + format: "elementType == %d AND label CONTAINS %@", + XCUIElement.ElementType.staticText.rawValue, + text + ) + ), + value: text, + description: description, + groups: groups + ) + } + + static func cellStaticTextLabelContains(_ text: String, description: String, groups: [String] = []) -> Selector { + let predicate = NSPredicate( + format: "elementType == %d AND label CONTAINS[c] %@", + XCUIElement.ElementType.staticText.rawValue, + text + ) + return Selector(strategy: .predicate(predicate), + value: text, + description: description, + groups: groups) + } } diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/WebsiteDataSelectorSet.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/WebsiteDataSelectorSet.swift new file mode 100644 index 0000000000000..8d3895278329b --- /dev/null +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/Selectors/WebsiteDataSelectorSet.swift @@ -0,0 +1,125 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/ + +import XCTest + +protocol WebsiteDataSelectorsSet { + var TABLE_WEBSITE_DATA: Selector { get } + var CELL_CLEAR_ALL: Selector { get } + var ALERT_OK_BUTTON: Selector { get } + var BUTTON_DATA_MANAGEMENT: Selector { get } + var BUTTON_SETTINGS: Selector { get } + var BUTTON_DONE: Selector { get } + var CELL_SHOW_MORE: Selector { get } + var EXAMPLE_EQUAL: Selector { get } + var EXAMPLE_CONTAINS: Selector { get } + var CIRCLE_IMAGE_ANYWHERE: Selector { get } + var STATIC_TEXT_EXAMPLE_IN_CELL: Selector { get } + func clearAllLabel(in app: XCUIApplication) -> XCUIElement + func circleImageInsideCells(_ app: XCUIApplication) -> XCUIElement + func anyTableButton(_ app: XCUIApplication) -> XCUIElement + var all: [Selector] { get } +} + +struct WebsiteDataSelectors: WebsiteDataSelectorsSet { + private enum IDs { + static let websiteDataOther = "Website Data" + static let clearAllCell = "ClearAllWebsiteData" + static let clearAllLabel = "Clear All Website Data" + static let showMoreCell = "ShowMoreWebsiteData" + static let exampleLabel = "example.com" + static let circleImageId = "circle" + static let dataManagement = "Data Management" + static let settings = "Settings" + static let doneButton = "Done" + static let exampleUrl = "example.com" + } + + let TABLE_WEBSITE_DATA = Selector.tableOtherById( + IDs.websiteDataOther, + description: "Main Website Data table", + groups: ["settings"] + ) + + let CELL_CLEAR_ALL = Selector.cellById( + IDs.clearAllCell, + description: "Cell 'ClearAllWebsiteData'", + groups: ["settings"] + ) + + let ALERT_OK_BUTTON = Selector.buttonByLabel( + "OK", + description: "Confirmation button in clear data alert", + groups: ["settings"] + ) + + let BUTTON_DATA_MANAGEMENT = Selector.buttonByLabel( + IDs.dataManagement, + description: "Back button from Website Data to Data Management screen", + groups: ["settings"] + ) + + let BUTTON_SETTINGS = Selector.buttonByLabel( + IDs.settings, + description: "Back button to Settings screen", + groups: ["settings"] + ) + + let BUTTON_DONE = Selector.buttonByLabel( + IDs.doneButton, + description: "Done button to exit Settings", + groups: ["settings"] + ) + + let CELL_SHOW_MORE = Selector.cellById( + IDs.showMoreCell, + description: "Show more website data cell", + groups: ["settings", "websitedata"] + ) + + let EXAMPLE_EQUAL = Selector.staticTextByExactLabel( + IDs.exampleLabel, + description: "example.com exact label", + groups: ["settings", "websitedata"] + ) + + let EXAMPLE_CONTAINS = Selector.staticTextLabelContains( + IDs.exampleLabel, + description: "any staticText containing 'example.com'", + groups: ["settings", "websitedata"] + ) + + let CIRCLE_IMAGE_ANYWHERE = Selector.imageById( + IDs.circleImageId, + description: "circle image id anywhere", + groups: ["settings", "websitedata"] + ) + + let STATIC_TEXT_EXAMPLE_IN_CELL = Selector.cellStaticTextLabelContains( + IDs.exampleUrl, + description: "StaticText 'example.com' inside Website Data cell", + groups: ["settings", "websitedata"] + ) + + func clearAllLabel(in app: XCUIApplication) -> XCUIElement { + app.tables.cells[IDs.clearAllCell].staticTexts[IDs.clearAllLabel] + } + + func circleImageInsideCells(_ app: XCUIApplication) -> XCUIElement { + return app.cells.images.matching(identifier: IDs.circleImageId).firstMatch + } + + func anyTableButton(_ app: XCUIApplication) -> XCUIElement { + return app.tables.buttons.firstMatch + } + + var all: [Selector] { + [ + TABLE_WEBSITE_DATA, CELL_CLEAR_ALL, ALERT_OK_BUTTON, + BUTTON_DATA_MANAGEMENT, BUTTON_SETTINGS, BUTTON_DONE, + CELL_SHOW_MORE, EXAMPLE_EQUAL, EXAMPLE_CONTAINS, + CIRCLE_IMAGE_ANYWHERE, STATIC_TEXT_EXAMPLE_IN_CELL + ] + } +}