Skip to content

Commit

Permalink
Make UI tests more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
philippzagar committed Jan 20, 2024
1 parent 086ecb4 commit 003df32
Showing 1 changed file with 48 additions and 39 deletions.
87 changes: 48 additions & 39 deletions Tests/UITests/TestAppUITests/TestAppUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,56 @@ class TestAppUITests: XCTestCase {

func testChatExport() throws {
let app = XCUIApplication()
app.launch()

// Entering dummy chat value
XCTAssert(app.staticTexts["SpeziChat"].waitForExistence(timeout: 1))
try app.textViews["Message Input Textfield"].enter(value: "User Message!", dismissKeyboard: false)
XCTAssert(app.buttons["Send Message"].waitForExistence(timeout: 5))
app.buttons["Send Message"].tap()

sleep(1)
XCTAssert(app.staticTexts["Assistant Message Response!"].waitForExistence(timeout: 5))

// Export chat via share sheet button
XCTAssert(app.buttons["Export the Chat"].waitForExistence(timeout: 2))
app.buttons["Export the Chat"].tap()

// Store exported chat in Files
XCTAssert(app.staticTexts["Save to Files"].waitForExistence(timeout: 10))
app.staticTexts["Save to Files"].tap()
sleep(3)
XCTAssert(app.buttons["Save"].waitForExistence(timeout: 2))
app.buttons["Save"].tap()
sleep(10) // Wait until file is saved

if app.staticTexts["Replace Existing Items?"].waitForExistence(timeout: 5) {
XCTAssert(app.buttons["Replace"].waitForExistence(timeout: 2))
app.buttons["Replace"].tap()
sleep(3) // Wait until file is saved
}

// Wait until share sheet closed and back on the chat screen
XCTAssert(app.staticTexts["SpeziChat"].waitForExistence(timeout: 10))

XCUIDevice.shared.press(.home)

// Launch the Files app
let filesApp = XCUIApplication(bundleIdentifier: "com.apple.DocumentsApp")
filesApp.launch()

// Handle already open files
if filesApp.buttons["Done"].waitForExistence(timeout: 2) {
filesApp.buttons["Done"].tap()
while(true) {

Check failure on line 43 in Tests/UITests/TestAppUITests/TestAppUITests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
app.launch()

// Entering dummy chat value
XCTAssert(app.staticTexts["SpeziChat"].waitForExistence(timeout: 1))
try app.textViews["Message Input Textfield"].enter(value: "User Message!", dismissKeyboard: false)
XCTAssert(app.buttons["Send Message"].waitForExistence(timeout: 5))
app.buttons["Send Message"].tap()

sleep(1)
XCTAssert(app.staticTexts["Assistant Message Response!"].waitForExistence(timeout: 5))

// Export chat via share sheet button
XCTAssert(app.buttons["Export the Chat"].waitForExistence(timeout: 2))
app.buttons["Export the Chat"].tap()

// Store exported chat in Files
XCTAssert(app.staticTexts["Save to Files"].waitForExistence(timeout: 10))
app.staticTexts["Save to Files"].tap()
sleep(3)
XCTAssert(app.buttons["Save"].waitForExistence(timeout: 2))
app.buttons["Save"].tap()
sleep(10) // Wait until file is saved

if app.staticTexts["Replace Existing Items?"].waitForExistence(timeout: 5) {
XCTAssert(app.buttons["Replace"].waitForExistence(timeout: 2))
app.buttons["Replace"].tap()
sleep(3) // Wait until file is saved
}

// Wait until share sheet closed and back on the chat screen
XCTAssert(app.staticTexts["SpeziChat"].waitForExistence(timeout: 10))

XCUIDevice.shared.press(.home)

// Launch the Files app
filesApp.launch()

// Handle already open files
if filesApp.buttons["Done"].waitForExistence(timeout: 2) {
filesApp.buttons["Done"].tap()
}

// Check if file exists - If not, try the export procedure again
// Saving to files is very flakey on the runners, needs multiple attempts to succeed
if filesApp.staticTexts["Exported Chat"].waitForExistence(timeout: 2) {
break
}
}

// Open File
Expand Down

0 comments on commit 003df32

Please sign in to comment.