diff --git a/maestro-ios-driver/src/main/kotlin/util/XCRunnerCLIUtils.kt b/maestro-ios-driver/src/main/kotlin/util/XCRunnerCLIUtils.kt index b0c1577da8..986d968c79 100644 --- a/maestro-ios-driver/src/main/kotlin/util/XCRunnerCLIUtils.kt +++ b/maestro-ios-driver/src/main/kotlin/util/XCRunnerCLIUtils.kt @@ -44,7 +44,7 @@ object XCRunnerCLIUtils { val mapper = jacksonObjectMapper() val appsMap = mapper.readValue(json, Map::class.java) as Map - return appsMap.keys + return appsMap.keys + runningApps(deviceId).keys } fun setProxy(host: String, port: Int) { diff --git a/maestro-ios-driver/src/main/resources/maestro-driver-ios.zip b/maestro-ios-driver/src/main/resources/maestro-driver-ios.zip index 96c9458176..67b21b8d37 100644 Binary files a/maestro-ios-driver/src/main/resources/maestro-driver-ios.zip and b/maestro-ios-driver/src/main/resources/maestro-driver-ios.zip differ diff --git a/maestro-ios-driver/src/main/resources/maestro-driver-iosUITests-Runner.zip b/maestro-ios-driver/src/main/resources/maestro-driver-iosUITests-Runner.zip index 0dc60255e9..3fdba3de90 100644 Binary files a/maestro-ios-driver/src/main/resources/maestro-driver-iosUITests-Runner.zip and b/maestro-ios-driver/src/main/resources/maestro-driver-iosUITests-Runner.zip differ diff --git a/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/EraseTextHandler.swift b/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/EraseTextHandler.swift index 4305505d7f..945804ac07 100644 --- a/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/EraseTextHandler.swift +++ b/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/EraseTextHandler.swift @@ -19,8 +19,7 @@ struct EraseTextHandler: HTTPHandler { do { let start = Date() - let appId = RunningApp.getForegroundAppId(requestBody.appIds) - if let errorResponse = await waitUntilKeyboardIsPresented(appId: appId) { + if let errorResponse = await waitUntilKeyboardIsPresented(appIds: requestBody.appIds) { return errorResponse } @@ -37,10 +36,14 @@ struct EraseTextHandler: HTTPHandler { } } - private func waitUntilKeyboardIsPresented(appId: String?) async -> HTTPResponse? { + private func waitUntilKeyboardIsPresented(appIds: [String]) async -> HTTPResponse? { + let foregroundAppIds = RunningApp.getForegroundAppIds(appIds) + logger.info("Foreground apps \(foregroundAppIds)") + let isKeyboardPresented: Bool = (try? await TimeoutHelper.repeatUntil(timeout: 1, delta: 0.2) { - guard let appId = appId else { return true } - return XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists + return foregroundAppIds.contains { appId in + XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists + } }) ?? false // Return an error response if the keyboard is not presented diff --git a/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/InputTextRouteHandler.swift b/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/InputTextRouteHandler.swift index 1cbb77dc24..343cba0fbb 100644 --- a/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/InputTextRouteHandler.swift +++ b/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/InputTextRouteHandler.swift @@ -17,8 +17,7 @@ struct InputTextRouteHandler : HTTPHandler { do { let start = Date() - let appId = RunningApp.getForegroundAppId(requestBody.appIds) - if let errorResponse = await waitUntilKeyboardIsPresented(appId: appId) { + if let errorResponse = await waitUntilKeyboardIsPresented(appIds: requestBody.appIds) { return errorResponse } @@ -32,10 +31,14 @@ struct InputTextRouteHandler : HTTPHandler { } } - private func waitUntilKeyboardIsPresented(appId: String?) async -> HTTPResponse? { + private func waitUntilKeyboardIsPresented(appIds: [String]) async -> HTTPResponse? { + let foregroundAppIds = RunningApp.getForegroundAppIds(appIds) + logger.info("Foreground apps \(foregroundAppIds)") + let isKeyboardPresented: Bool = (try? await TimeoutHelper.repeatUntil(timeout: 1, delta: 0.2) { - guard let appId = appId else { return true } - return XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists + return foregroundAppIds.contains { appId in + XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists + } }) ?? false // Return an error response if the keyboard is not presented diff --git a/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/XCTest/RunningApp.swift b/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/XCTest/RunningApp.swift index 75d068dbf0..f42396f4de 100644 --- a/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/XCTest/RunningApp.swift +++ b/maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/XCTest/RunningApp.swift @@ -24,5 +24,14 @@ struct RunningApp { } ?? RunningApp.springboardBundleId } - + static func getForegroundAppIds(_ appIds: [String]) -> [String] { + // springboard is always on foreground + let allAppIds = appIds + ["com.apple.springboard"] + + + return allAppIds.filter { appId in + let app = XCUIApplication(bundleIdentifier: appId) + return app.state == .runningForeground + } + } }