Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor MTE-3733 Use waitAndTap() throughout XCUITest and SyncIntegrationTests #24050

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ActivityStreamTest: BaseTestCase {
func testTopSitesRemoveAllExceptPinnedClearPrivateData() {
waitForExistence(TopSiteCellgroup)
if iPad() {
app.textFields.element(boundBy: 0).tap()
app.textFields.element(boundBy: 0).waitAndTap()
app.typeText("mozilla.org\n")
} else {
navigator.openURL("mozilla.org")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ class AddressesTests: BaseTestCase {
navigator.goto(AddressesSettings)
let addresses = AccessibilityIdentifiers.Settings.Address.Addresses.self
mozWaitForElementToExist(app.navigationBars[addresses.title])
app.buttons[addresses.addAddress].tap()
app.buttons[addresses.addAddress].waitAndTap()
mozWaitForElementToExist(app.navigationBars[addresses.addAddress])
if !app.staticTexts["Name"].exists {
app.buttons["Close"].tap()
app.buttons[addresses.addAddress].tap()
app.buttons["Close"].waitAndTap()
app.buttons[addresses.addAddress].waitAndTap()
}
mozWaitForElementToExist(app.staticTexts["Name"])
}
Expand Down Expand Up @@ -246,50 +246,49 @@ class AddressesTests: BaseTestCase {
}

private func typeName(name: String, updateText: Bool = false) {
app.staticTexts["Name"].tap()
app.staticTexts["Name"].waitAndTap()
if updateText {
clearText()
}
app.typeText(name)
}

private func typeOrganization(organization: String, updateText: Bool = false) {
app.staticTexts["Organization"].tap()
app.staticTexts["Organization"].waitAndTap()
if updateText {
clearText()
}
app.typeText(organization)
}

private func typeStreetAddress(street: String, updateText: Bool = false) {
app.staticTexts["Street Address"].tap()
app.staticTexts["Street Address"].waitAndTap()
if updateText {
clearText()
}
app.typeText(street)
}

private func typeCity(city: String, updateText: Bool = false) {
app.staticTexts["City"].tap()
app.staticTexts["City"].waitAndTap()
if updateText {
clearText()
}
app.typeText(city)
}

private func selectCountry(country: String) {
app.staticTexts["Country or Region"].tap()
mozWaitForElementToExist(app.buttons[country])
app.buttons[country].tap()
app.staticTexts["Country or Region"].waitAndTap()
app.buttons[country].waitAndTap()
}

private func typeZIP(zip: String, updateText: Bool = false, isPostalCode: Bool = false) {
if isPostalCode {
scrollToElement(app.staticTexts["Postal Code"])
app.staticTexts["Postal Code"].tap()
app.staticTexts["Postal Code"].waitAndTap()
} else {
scrollToElement(app.staticTexts["ZIP Code"])
app.staticTexts["ZIP Code"].tap()
app.staticTexts["ZIP Code"].waitAndTap()
}
if updateText {
clearText()
Expand All @@ -299,7 +298,7 @@ class AddressesTests: BaseTestCase {

private func typePhone(phone: String, updateText: Bool = false) {
if app.buttons["Done"].isHittable {
app.buttons["Done"].tap()
app.buttons["Done"].waitAndTap()
}
app.staticTexts["Phone"].tapOnApp()
if updateText {
Expand All @@ -310,7 +309,7 @@ class AddressesTests: BaseTestCase {

private func typeEmail(email: String, updateText: Bool = false) {
scrollToElement(app.staticTexts["Email"])
app.staticTexts["Email"].tap()
app.staticTexts["Email"].waitAndTap()
if updateText {
clearText()
}
Expand All @@ -321,7 +320,7 @@ class AddressesTests: BaseTestCase {
if withRetry {
app.buttons["Save"].tapWithRetry()
} else {
app.buttons["Save"].tap()
app.buttons["Save"].waitAndTap()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AuthenticationTest: BaseTestCase {

if result != .completed {
// User already logged, tap on reload button
app.buttons["TabLocationView.reloadButton"].tap()
app.buttons["TabLocationView.reloadButton"].waitAndTap()
}
mozWaitForElementToExist(app.staticTexts[
"A username and password are being requested by jigsaw.w3.org. The site says: test"
Expand All @@ -41,7 +41,7 @@ class AuthenticationTest: BaseTestCase {
app.alerts.textFields["Username"].typeText("guest")
app.alerts.secureTextFields["Password"].tapAndTypeText("guest")
mozWaitElementHittable(element: app.alerts.buttons["Log in"], timeout: TIMEOUT)
app.alerts.buttons["Log in"].tap()
app.alerts.buttons["Log in"].waitAndTap()
/* There is no other way to verify basic auth is successful as the webview is
inaccessible after sign in to verify the success text. */
waitForNoExistence(app.alerts.buttons["Cancel"], timeoutValue: 5)
Expand Down
34 changes: 14 additions & 20 deletions firefox-ios/firefox-ios-tests/Tests/XCUITests/BaseTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ class BaseTestCase: XCTestCase {
let icon = springboard.icons.containingText("Fennec").element(boundBy: 0)
if icon.exists {
icon.press(forDuration: 1.5)
mozWaitForElementToExist(springboard.buttons["Remove App"])
springboard.buttons["Remove App"].tap()
mozWaitForElementToExist(springboard.alerts.buttons["Delete App"])
springboard.alerts.buttons["Delete App"].tap()
mozWaitForElementToExist(springboard.alerts.buttons["Delete"])
springboard.alerts.buttons["Delete"].tap()
springboard.buttons["Remove App"].waitAndTap()
springboard.alerts.buttons["Delete App"].waitAndTap()
springboard.alerts.buttons["Delete"].waitAndTap()
}
}

Expand Down Expand Up @@ -138,7 +135,7 @@ class BaseTestCase: XCTestCase {

if firstRunUI.exists {
firstRunUI.swipeLeft()
XCUIApplication().buttons["Start Browsing"].tap()
XCUIApplication().buttons["Start Browsing"].waitAndTap()
}
}

Expand Down Expand Up @@ -294,11 +291,9 @@ class BaseTestCase: XCTestCase {
userState.url = path(forTestPage: "test-mozilla-book.html")
navigator.openURL(path(forTestPage: "test-mozilla-book.html"))
waitUntilPageLoad()
mozWaitForElementToExist(app.buttons["Reader View"])
app.buttons["Reader View"].tap()
app.buttons["Reader View"].waitAndTap()
waitUntilPageLoad()
mozWaitForElementToExist(app.buttons["Add to Reading List"])
app.buttons["Add to Reading List"].tap()
app.buttons["Add to Reading List"].waitAndTap()
}

func removeContentFromReaderView() {
Expand All @@ -310,20 +305,19 @@ class BaseTestCase: XCTestCase {
// Remove the item from reading list
savedToReadingList.swipeLeft()
mozWaitForElementToExist(app.buttons["Remove"])
app.buttons["Remove"].tap()
app.buttons["Remove"].waitAndTap()
}

func selectOptionFromContextMenu(option: String) {
mozWaitForElementToExist(app.tables["Context Menu"].cells.otherElements[option])
app.tables["Context Menu"].cells.otherElements[option].tap()
app.tables["Context Menu"].cells.otherElements[option].waitAndTap()
mozWaitForElementToNotExist(app.tables["Context Menu"])
}

func loadWebPage(_ url: String, waitForLoadToFinish: Bool = true, file: String = #file, line: UInt = #line) {
let app = XCUIApplication()
UIPasteboard.general.string = url
app.textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField].press(forDuration: 2.0)
app.tables["Context Menu"].cells[AccessibilityIdentifiers.Photon.pasteAndGoAction].firstMatch.tap()
app.tables["Context Menu"].cells[AccessibilityIdentifiers.Photon.pasteAndGoAction].firstMatch.waitAndTap()

if waitForLoadToFinish {
let finishLoadingTimeout: TimeInterval = 30
Expand Down Expand Up @@ -358,7 +352,7 @@ class BaseTestCase: XCTestCase {
func unlockLoginsView() {
// Press continue button on the password onboarding if it's shown
if app.buttons[AccessibilityIdentifiers.Settings.Passwords.onboardingContinue].exists {
app.buttons[AccessibilityIdentifiers.Settings.Passwords.onboardingContinue].tap()
app.buttons[AccessibilityIdentifiers.Settings.Passwords.onboardingContinue].waitAndTap()
}

let passcodeInput = springboard.otherElements.secureTextFields.firstMatch
Expand Down Expand Up @@ -398,7 +392,7 @@ class BaseTestCase: XCTestCase {

func dismissSurveyPrompt() {
if app.buttons[AccessibilityIdentifiers.Microsurvey.Prompt.closeButton].exists {
app.buttons[AccessibilityIdentifiers.Microsurvey.Prompt.closeButton].tap()
app.buttons[AccessibilityIdentifiers.Microsurvey.Prompt.closeButton].waitAndTap()
}
}

Expand All @@ -420,11 +414,11 @@ class BaseTestCase: XCTestCase {
}
mozWaitForElementToExist(app.cells.staticTexts["Dark"])
if theme == "Dark" {
app.cells.staticTexts["Dark"].tap()
app.cells.staticTexts["Dark"].waitAndTap()
} else {
app.cells.staticTexts["Light"].tap()
app.cells.staticTexts["Light"].waitAndTap()
}
app.buttons["Settings"].tap()
app.buttons["Settings"].waitAndTap()
navigator.nowAt(SettingsScreen)
app.buttons["Done"].waitAndTap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class BookmarksTests: BaseTestCase {
app.collectionViews
.cells["Example Domain"].children(matching: .other)
.element.children(matching: .other)
.element.tap()
.element.waitAndTap()
} else {
app.cells.staticTexts["Example Domain"].tap()
app.cells.staticTexts["Example Domain"].waitAndTap()
}
navigator.nowAt(BrowserTab)
waitForTabsButton()
Expand Down Expand Up @@ -175,7 +175,7 @@ class BookmarksTests: BaseTestCase {
func testAddBookmark() {
addNewBookmark()
// Verify that clicking on bookmark opens the website
app.tables["Bookmarks List"].cells.element(boundBy: 1).tap()
app.tables["Bookmarks List"].cells.element(boundBy: 1).waitAndTap()
mozWaitForElementToExist(app.textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField])
}

Expand All @@ -187,8 +187,8 @@ class BookmarksTests: BaseTestCase {
mozWaitForElementToExist(app.navigationBars["Bookmarks"])
// XCTAssertFalse(app.buttons["Save"].isEnabled), is this a bug allowing empty folder name?
app.tables.cells.textFields.element(boundBy: 0).tapAndTypeText("Test Folder")
app.buttons["Save"].tap()
app.buttons["Done"].tap()
app.buttons["Save"].waitAndTap()
app.buttons["Done"].waitAndTap()
checkItemsInBookmarksList(items: 2)
navigator.nowAt(MobileBookmarks)
// Now remove the folder
Expand All @@ -208,7 +208,7 @@ class BookmarksTests: BaseTestCase {
navigator.goto(LibraryPanel_Bookmarks)
navigator.nowAt(MobileBookmarks)
navigator.performAction(Action.AddNewSeparator)
app.buttons["Done"].tap()
app.buttons["Done"].waitAndTap()
// There is one item plus the default Desktop Bookmarks folder
checkItemsInBookmarksList(items: 2)

Expand Down Expand Up @@ -237,7 +237,7 @@ class BookmarksTests: BaseTestCase {
// Remove by long press and select option from context menu
app.tables.staticTexts.element(boundBy: 1).press(forDuration: 1)
mozWaitForElementToExist(app.tables["Context Menu"])
app.tables.otherElements["Remove Bookmark"].tap()
app.tables.otherElements["Remove Bookmark"].waitAndTap()
// Verify that there are only 1 cell (desktop bookmark folder)
checkItemsInBookmarksList(items: 1)
}
Expand Down Expand Up @@ -307,7 +307,7 @@ class BookmarksTests: BaseTestCase {

// Delete the Bookmark added, check it is removed
app.tables["Bookmarks List"].cells.staticTexts["Example Domain"].swipeLeft()
app.buttons["Delete"].tap()
app.buttons["Delete"].waitAndTap()
mozWaitForElementToNotExist(app.tables["Bookmarks List"].cells.staticTexts["Example Domain"])
}

Expand All @@ -323,7 +323,7 @@ class BookmarksTests: BaseTestCase {
XCTAssertEqual(app.tables["Bookmarks List"].cells.count, 1)

// There is only three folders inside the desktop bookmarks
app.tables["Bookmarks List"].cells.firstMatch.tap()
app.tables["Bookmarks List"].cells.firstMatch.waitAndTap()
mozWaitForElementToExist(app.tables["Bookmarks List"])
XCTAssertEqual(app.tables["Bookmarks List"].cells.count, 3)
}
Expand All @@ -349,12 +349,12 @@ class BookmarksTests: BaseTestCase {
navigator.openURL(path(forTestPage: url_2["url"]!))
waitForTabsButton()
bookmarkPageAndTapEdit()
app.buttons["Close"].tap()
app.buttons["Close"].waitAndTap()
waitForTabsButton()
navigator.nowAt(BrowserTab)
unbookmark()
bookmarkPageAndTapEdit()
app.buttons["Save"].tap()
app.buttons["Save"].waitAndTap()
navigator.nowAt(BrowserTab)
navigator.goto(LibraryPanel_Bookmarks)
checkItemInBookmarkList(oneItemBookmarked: true)
Expand Down Expand Up @@ -399,7 +399,7 @@ class BookmarksTests: BaseTestCase {
]
)
// Tap to "Open in New Tab"
contextMenuTable.cells.otherElements[StandardImageIdentifiers.Large.plus].tap()
contextMenuTable.cells.otherElements[StandardImageIdentifiers.Large.plus].waitAndTap()
// The webpage opens in a new tab
switchToTabAndValidate(nrOfTabs: "3")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class BrowsingPDFTests: BaseTestCase {
waitUntilPageLoad()
let checkboxValidation = app.webViews["Web content"].staticTexts["Verify you are human"]
if checkboxValidation.exists {
checkboxValidation.tap()
checkboxValidation.waitAndTap()
}
mozWaitForValueContains(url, value: PDF_website["urlValue"]!)
// Let's comment the next line until that fails intermittently due to the page re-direction
// mozWaitForElementToExist(app.staticTexts["Education and schools"])

// Go back to pdf view
app.buttons[AccessibilityIdentifiers.Toolbar.backButton].tap()
app.buttons[AccessibilityIdentifiers.Toolbar.backButton].waitAndTap()
mozWaitForValueContains(url, value: PDF_website["pdfValue"]!)
}

Expand Down Expand Up @@ -93,7 +93,7 @@ class BrowsingPDFTests: BaseTestCase {
}

mozWaitForElementToExist(app.staticTexts[PDF_website["longUrlValue"]!])
app.buttons["Add to Reading List"].tap()
app.buttons["Add to Reading List"].waitAndTap()
navigator.nowAt(BrowserTab)

// Go to reading list and check that the item is there
Expand Down Expand Up @@ -124,16 +124,15 @@ class BrowsingPDFTests: BaseTestCase {
.element
.children(matching: .other)
.element(boundBy: 0)
pdfTopSite.tap()
pdfTopSite.waitAndTap()
waitUntilPageLoad()
mozWaitForValueContains(url, value: PDF_website["pdfValue"]!)

// Remove pdf pinned site
navigator.performAction(Action.OpenNewTabFromTabTray)
mozWaitForElementToExist(app.collectionViews.cells.staticTexts[PDF_website["bookmarkLabel"]!])
pdfTopSite.press(forDuration: 1)
mozWaitForElementToExist(app.tables.cells.otherElements[StandardImageIdentifiers.Large.pinSlash])
app.tables.cells.otherElements[StandardImageIdentifiers.Large.pinSlash].tap()
app.tables.cells.otherElements[StandardImageIdentifiers.Large.pinSlash].waitAndTap()
waitForElementsToExist(
[
app.links[AccessibilityIdentifiers.FirefoxHomepage.TopSites.itemCell],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ClipBoardTests: BaseTestCase {
navigator.goto(URLBarOpen)
urlBarAddress.waitAndTap()
if iPad() {
app.menuItems["Select All"].tap()
app.menuItems["Select All"].waitAndTap()
}
app.menuItems["Copy"].waitAndTap()
app.typeText("\r")
Expand All @@ -32,7 +32,7 @@ class ClipBoardTests: BaseTestCase {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let allowBtn = springboard.buttons["Allow Paste"]
if allowBtn.waitForExistence(timeout: TIMEOUT) {
allowBtn.tap()
allowBtn.waitAndTap()
}

guard var value = app.textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField].value
Expand Down Expand Up @@ -85,7 +85,7 @@ class ClipBoardTests: BaseTestCase {
let urlBar = app.textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField]
mozWaitForElementToExist(urlBar)
urlBar.press(forDuration: 1.5)
app.otherElements[AccessibilityIdentifiers.Photon.pasteAndGoAction].tap()
app.otherElements[AccessibilityIdentifiers.Photon.pasteAndGoAction].waitAndTap()
// The URL is pasted and the page is correctly loaded
mozWaitForElementToExist(urlBar)
waitForValueContains(urlBar, value: "localhost")
Expand Down Expand Up @@ -114,7 +114,7 @@ class ClipBoardTests: BaseTestCase {
// mozWaitForElementToExist(
// app.tables["Context Menu"].otherElements[AccessibilityIdentifiers.Photon.pasteAndGoAction]
// )
// app.tables["Context Menu"].otherElements[AccessibilityIdentifiers.Photon.pasteAndGoAction].tap()
// app.tables["Context Menu"].otherElements[AccessibilityIdentifiers.Photon.pasteAndGoAction].waitAndTap()
// mozWaitForElementToExist(app.textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField])
// mozWaitForValueContains(app.textFields[AccessibilityIdentifiers.Browser.AddressToolbar.searchTextField], value: "www.example.com")
}
Expand Down
Loading