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

ci: Remove animations for UI tests #1645

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
250 changes: 145 additions & 105 deletions MailUITests/MailUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,25 @@
app.launch()
}

func testLogin() throws {
launchAppFromScratch()
login()
}

func testDisplayThread() throws {
launchAppFromScratch()
login()

app.collectionViews.staticTexts.element(boundBy: 1).firstMatch.tap()
_ = app.webViews.firstMatch.waitForExistence(timeout: defaultTimeOut)
}

func testNewMessage() throws {
launchAppFromScratch()
login()

app.buttons[MailResourcesStrings.Localizable.buttonNewMessage].firstMatch.tap()
_ = app.webViews.firstMatch.waitForExistence(timeout: defaultTimeOut)
func wait(delay: TimeInterval = 5) {
let delayExpectation = XCTestExpectation()
delayExpectation.isInverted = true
wait(for: [delayExpectation], timeout: delay)
}

// func testLogin() throws {
// launchAppFromScratch()
// login()
// }

// func testDisplayThread() throws {
// launchAppFromScratch()
// login()
//
// app.collectionViews.staticTexts.element(boundBy: 1).firstMatch.tap()
// _ = app.webViews.firstMatch.waitForExistence(timeout: defaultTimeOut)
// }
//
func testSendNewMessage() throws {
launchAppFromScratch()
login()
Expand All @@ -67,106 +65,126 @@
app.navigationBars[MailResourcesStrings.Localizable.buttonNewMessage].buttons[MailResourcesStrings.Localizable.send]
.firstMatch.tap()
_ = app.collectionViews.firstMatch.waitForExistence(timeout: defaultTimeOut)
}

Check warning on line 68 in MailUITests/MailUITests.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Insert blank line before class, struct, enum, extension, protocol or function declarations. (blankLinesBetweenScopes)

func testSaveMessage() throws {
launchAppFromScratch()
login()
writeTestMessage()

app.navigationBars[MailResourcesStrings.Localizable.buttonNewMessage]
.buttons[MailResourcesStrings.Localizable.buttonClose].firstMatch.tap()
_ = app.collectionViews.firstMatch.waitForExistence(timeout: defaultTimeOut)

let deleteDraftButton = app.buttons[MailResourcesStrings.Localizable.actionDelete].firstMatch
_ = deleteDraftButton.waitForExistence(timeout: defaultTimeOut)
deleteDraftButton.tap()
}

func testSwitchFolder() {
launchAppFromScratch()
login()

app.navigationBars.firstMatch.buttons[MailResourcesStrings.Localizable.contentDescriptionButtonMenu].firstMatch.tap()
app.scrollViews.otherElements.staticTexts[MailResourcesStrings.Localizable.archiveFolder].firstMatch.tap()
}

func testCreateFolder() {
launchAppFromScratch()
login()

app.navigationBars.firstMatch.buttons[MailResourcesStrings.Localizable.contentDescriptionButtonMenu].tap()
let newFolderButton = app.scrollViews.otherElements.buttons[MailResourcesStrings.Localizable.newFolderDialogTitle]
_ = newFolderButton.waitForExistence(timeout: defaultTimeOut)
newFolderButton.tap()

let folderNameTextField = app.textFields[MailResourcesStrings.Localizable.createFolderName]
_ = folderNameTextField.waitForExistence(timeout: defaultTimeOut)
folderNameTextField.tap()
folderNameTextField.typeText("Test-\(Date().timeIntervalSince1970)")
app.staticTexts[MailResourcesStrings.Localizable.buttonCreate].tap()
}

func testDeleteSwipeAction() {
launchAppFromScratch()
login()
swipeFirstCell()

app.collectionViews.buttons[Action.delete.accessibilityIdentifier].firstMatch.tap()

undo()
}

func testUndoDeleteAction() {
launchAppFromScratch()
login()
swipeFirstCell()

app.collectionViews.buttons[Action.delete.accessibilityIdentifier].firstMatch.tap()

undo(ignoreUndoFailure: false)
}

func testMoveAction() {
launchAppFromScratch()
login()
swipeFirstCell()

app.collectionViews.buttons[MailResourcesStrings.Localizable.settingsSwipeActionQuickActionsMenu].tap()
app.buttons[MailResourcesStrings.Localizable.actionMove].tap()

let moveFolderViewTitle = app.navigationBars.staticTexts[MailResourcesStrings.Localizable.actionMove]
_ = moveFolderViewTitle.waitForExistence(timeout: defaultTimeOut)

// Because the burger menu is in a ZStack "trash" folder appears twice, that's why we use element bound by
app.scrollViews.containing(
.staticText,
identifier: MailResourcesStrings.Localizable.trashFolder
).element(boundBy: 1).tap()

undo()
//
// func testSaveMessage() throws {
// launchAppFromScratch()
// login()
// writeTestMessage()
//
// app.navigationBars[MailResourcesStrings.Localizable.buttonNewMessage]
// .buttons[MailResourcesStrings.Localizable.buttonClose].firstMatch.tap()
//
// let deleteDraftButton = app.buttons[MailResourcesStrings.Localizable.actionDelete].firstMatch
// _ = deleteDraftButton.waitForExistence(timeout: defaultTimeOut)
// deleteDraftButton.tap()
// }
//
// func tapMenuButton() {
// let menuButton = app.navigationBars.firstMatch.buttons[MailResourcesStrings.Localizable.contentDescriptionButtonMenu]
// .firstMatch
// _ = menuButton.waitForExistence(timeout: defaultTimeOut)
// menuButton.tap()
// }
//
// func testSwitchFolder() {
// launchAppFromScratch()
// login()
//
// tapMenuButton()
//
// app.scrollViews.otherElements.staticTexts[MailResourcesStrings.Localizable.archiveFolder].firstMatch.tap()
// }
//
// func testCreateFolder() {
// launchAppFromScratch()
// login()
//
// tapMenuButton()
//
// let newFolderButton = app.scrollViews.otherElements.buttons[MailResourcesStrings.Localizable.newFolderDialogTitle]
// _ = newFolderButton.waitForExistence(timeout: defaultTimeOut)
// newFolderButton.tap()
//
// let folderNameTextField = app.textFields[MailResourcesStrings.Localizable.createFolderName]
// _ = folderNameTextField.waitForExistence(timeout: defaultTimeOut)
// folderNameTextField.tap()
// folderNameTextField.typeText("Test-\(Date().timeIntervalSince1970)")
// app.staticTexts[MailResourcesStrings.Localizable.buttonCreate].tap()
// }
//
// func testDeleteSwipeAction() {
// launchAppFromScratch()
// login()
// swipeFirstCell()
//
// let deleteButton = app.collectionViews.buttons[Action.delete.accessibilityIdentifier].firstMatch
// _ = deleteButton.waitForExistence(timeout: defaultTimeOut)
// deleteButton.tap()
//
// undo()
// }
//
// func testUndoDeleteAction() {
// launchAppFromScratch()
// login()
// swipeFirstCell()
//
// let deleteButton = app.collectionViews.buttons[Action.delete.accessibilityIdentifier].firstMatch
// _ = deleteButton.waitForExistence(timeout: defaultTimeOut)
// deleteButton.tap()
//
// undo(ignoreUndoFailure: false)
// }
//
// func testMoveAction() {
// launchAppFromScratch()
// login()
// swipeFirstCell()
//
// tapSwipeActionQuickActionsMenu()
// app.buttons[MailResourcesStrings.Localizable.actionMove].tap()
//
// let moveFolderViewTitle = app.navigationBars.staticTexts[MailResourcesStrings.Localizable.actionMove]
// _ = moveFolderViewTitle.waitForExistence(timeout: defaultTimeOut)
//
// // Because the burger menu is in a ZStack "trash" folder appears twice, that's why we use element bound by
// app.scrollViews.containing(
// .staticText,
// identifier: MailResourcesStrings.Localizable.trashFolder
// ).element(boundBy: 1).tap()
//
// undo()
// }

func tapSwipeActionQuickActionsMenu() {
let quickActionsMenuButton = app.collectionViews
.buttons[MailResourcesStrings.Localizable.settingsSwipeActionQuickActionsMenu].firstMatch
_ = quickActionsMenuButton.waitForExistence(timeout: defaultTimeOut)
quickActionsMenuButton.tap()
}

func testMoreSwipeAction() {
launchAppFromScratch()
login()
print(app.debugDescription)
swipeFirstCell()

app.collectionViews.buttons[MailResourcesStrings.Localizable.settingsSwipeActionQuickActionsMenu].firstMatch.tap()
tapSwipeActionQuickActionsMenu()
app.buttons[Action.delete.accessibilityIdentifier].tap()

undo()

swipeFirstCell()

app.collectionViews.buttons[MailResourcesStrings.Localizable.settingsSwipeActionQuickActionsMenu].firstMatch.tap()
tapSwipeActionQuickActionsMenu()
app.buttons[Action.archive.accessibilityIdentifier].firstMatch.tap()

undo()

swipeFirstCell()

app.collectionViews.buttons[MailResourcesStrings.Localizable.settingsSwipeActionQuickActionsMenu].firstMatch.tap()
tapSwipeActionQuickActionsMenu()
if app.buttons[Action.markAsRead.accessibilityIdentifier].firstMatch.exists {
app.buttons[Action.markAsRead.accessibilityIdentifier].firstMatch.tap()
} else {
Expand All @@ -175,7 +193,7 @@

swipeFirstCell()

app.collectionViews.buttons[MailResourcesStrings.Localizable.settingsSwipeActionQuickActionsMenu].firstMatch.tap()
tapSwipeActionQuickActionsMenu()
if app.buttons[MailResourcesStrings.Localizable.actionMarkAsUnread].firstMatch.exists {
app.buttons[MailResourcesStrings.Localizable.actionMarkAsUnread].firstMatch.tap()
} else {
Expand All @@ -197,25 +215,37 @@
func swipeFirstCell() {
// First cell could be the loading indicator so we get the second one
let testMailCell = app.collectionViews.containing(.button, identifier: "ThreadListCell").firstMatch
_ = testMailCell.waitForExistence(timeout: defaultTimeOut)
_ = testMailCell.exists

testMailCell.swipeLeft()

Check failure on line 220 in MailUITests/MailUITests.swift

View workflow job for this annotation

GitHub Actions / UI Tests

testMoreSwipeAction, Failed to swipe left CollectionView (First Match): No matches found for first query match sequence: `Descendants matching type CollectionView` -> `Elements containing elements matching type Button with identifier 'ThreadListCell'`, given input App element pid: 4721
}

func writeTestMessage() {
app.buttons[MailResourcesStrings.Localizable.buttonNewMessage].firstMatch.tap()
let newMessageButton = app.buttons[MailResourcesStrings.Localizable.buttonNewMessage].firstMatch
_ = newMessageButton.waitForExistence(timeout: defaultTimeOut)
newMessageButton.tap()

Check failure on line 226 in MailUITests/MailUITests.swift

View workflow job for this annotation

GitHub Actions / UI Tests

testSendNewMessage, Failed to tap "New message" Button: No matches found for first query match sequence: `Descendants matching type Button` -> `Elements matching predicate '"New message" IN identifiers'`, given input App element pid: 4819

let composeBodyView = app.webViews.firstMatch
_ = composeBodyView.waitForExistence(timeout: defaultTimeOut)

app.textFields.firstMatch.tap()
app.textFields.firstMatch.typeText(Env.testAccountEmail)
app.textFields.firstMatch.typeText("\n")
let laterButton = app.buttons[MailResourcesStrings.Localizable.buttonLater].firstMatch
if laterButton.waitForExistence(timeout: defaultTimeOut) {
laterButton.tap()
}

let toTextField = app.textFields.firstMatch
_ = toTextField.waitForExistence(timeout: defaultTimeOut)
toTextField.tap()
toTextField.typeText(Env.testAccountEmail)
toTextField.typeText("\n")

let subjectTextField = app.textFields[MailResourcesStrings.Localizable.subjectTitle].firstMatch
subjectTextField.tap()
subjectTextField.typeText(MailUITests.testSubject)

composeBodyView.tap()
composeBodyView.typeText(MailResourcesStrings.Localizable.aiPromptExample1)

Check warning on line 247 in MailUITests/MailUITests.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Remove trailing blank line at the end of a scope. (blankLinesAtEndOfScope)

}

func login() {
Expand All @@ -238,6 +268,7 @@
passwordField.typeText(Env.testAccountPassword)
passwordField.typeText("\n")


Check warning on line 271 in MailUITests/MailUITests.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Replace consecutive blank lines with a single blank line. (consecutiveBlankLines)

Check failure on line 271 in MailUITests/MailUITests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
let nowText = MailResourcesStrings.Localizable
.threadListHeaderLastUpdate(Date().formatted(.relative(presentation: .named)))
let refreshText = app.staticTexts[nowText].firstMatch
Expand Down Expand Up @@ -269,6 +300,15 @@

let refreshText = app.staticTexts[nowText].firstMatch
_ = refreshText.waitForExistence(timeout: defaultTimeOut)
}

Check warning on line 303 in MailUITests/MailUITests.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Remove trailing blank line at the end of a scope. (blankLinesAtEndOfScope)

}
}

extension XCUIElement {
func scrollToElement() {
while !isHittable {
XCUIApplication().swipeUp()
}
}
}
Loading