Post

Replies

Boosts

Views

Activity

Reply to Swift Testing UI tests (Xcode 27.3 beta 2): launch() in the second test leaves the app "notRunning" (FB25692723)
Update: I found a workaround in the test code. Terminate the app at the end of each test. Then the next test's launch() doesn't have to terminate the previous instance, and the failure goes away: private func launchAndCheck() throws { let app = XCUIApplication() defer { app.terminate() } app.launch() try #require(app.state == .runningForeground, "state right after launch(): \(app.state.rawValue)") try #require(app.staticTexts["Ready"].waitForExistence(timeout: 10)) }With this, all 4 tests in the repro passed in 3 of 3 runs, with no extra time per test. Waiting 1 second before launch() (try await Task.sleep(for: .seconds(1))) also works, but adds about 1 second to every test. Watch out for app.open(url) too. In our real app, a test that called app.open(url) (which relaunches the app with the URL) made the next test fail the same way, even though it terminated its app at the end. Opening the URL through the system fixed it: XCUIDevice.shared.system.open(url) // instead of app.open(url)With both changes, all 11 UI tests in our app now run under Swift Testing and passed in 3 of 3 runs on Xcode 27.3 beta 2. I've added these details to FB25692723.
1d
Reply to Swift Testing UI tests (Xcode 27.3 beta 2): launch() in the second test leaves the app "notRunning" (FB25692723)
Update: I found a workaround in the test code. Terminate the app at the end of each test. Then the next test's launch() doesn't have to terminate the previous instance, and the failure goes away: private func launchAndCheck() throws { let app = XCUIApplication() defer { app.terminate() } app.launch() try #require(app.state == .runningForeground, "state right after launch(): \(app.state.rawValue)") try #require(app.staticTexts["Ready"].waitForExistence(timeout: 10)) }With this, all 4 tests in the repro passed in 3 of 3 runs, with no extra time per test. Waiting 1 second before launch() (try await Task.sleep(for: .seconds(1))) also works, but adds about 1 second to every test. Watch out for app.open(url) too. In our real app, a test that called app.open(url) (which relaunches the app with the URL) made the next test fail the same way, even though it terminated its app at the end. Opening the URL through the system fixed it: XCUIDevice.shared.system.open(url) // instead of app.open(url)With both changes, all 11 UI tests in our app now run under Swift Testing and passed in 3 of 3 runs on Xcode 27.3 beta 2. I've added these details to FB25692723.
Replies
Boosts
Views
Activity
1d