Skip to content

Commit 9165c50

Browse files
[MA 2747] Check keyboard existence in all foreground apps (mobile-dev-inc#2184)
* fix: check keyboard presence in all foreground apps * fix: list all running apps as well
1 parent 10019b5 commit 9165c50

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

maestro-ios-driver/src/main/kotlin/util/XCRunnerCLIUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object XCRunnerCLIUtils {
4444
val mapper = jacksonObjectMapper()
4545
val appsMap = mapper.readValue(json, Map::class.java) as Map<String, Any>
4646

47-
return appsMap.keys
47+
return appsMap.keys + runningApps(deviceId).keys
4848
}
4949

5050
fun setProxy(host: String, port: Int) {
Binary file not shown.
Binary file not shown.

maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/EraseTextHandler.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ struct EraseTextHandler: HTTPHandler {
1919
do {
2020
let start = Date()
2121

22-
let appId = RunningApp.getForegroundAppId(requestBody.appIds)
23-
if let errorResponse = await waitUntilKeyboardIsPresented(appId: appId) {
22+
if let errorResponse = await waitUntilKeyboardIsPresented(appIds: requestBody.appIds) {
2423
return errorResponse
2524
}
2625

@@ -37,10 +36,14 @@ struct EraseTextHandler: HTTPHandler {
3736
}
3837
}
3938

40-
private func waitUntilKeyboardIsPresented(appId: String?) async -> HTTPResponse? {
39+
private func waitUntilKeyboardIsPresented(appIds: [String]) async -> HTTPResponse? {
40+
let foregroundAppIds = RunningApp.getForegroundAppIds(appIds)
41+
logger.info("Foreground apps \(foregroundAppIds)")
42+
4143
let isKeyboardPresented: Bool = (try? await TimeoutHelper.repeatUntil(timeout: 1, delta: 0.2) {
42-
guard let appId = appId else { return true }
43-
return XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists
44+
return foregroundAppIds.contains { appId in
45+
XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists
46+
}
4447
}) ?? false
4548

4649
// Return an error response if the keyboard is not presented

maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/InputTextRouteHandler.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ struct InputTextRouteHandler : HTTPHandler {
1717
do {
1818
let start = Date()
1919

20-
let appId = RunningApp.getForegroundAppId(requestBody.appIds)
21-
if let errorResponse = await waitUntilKeyboardIsPresented(appId: appId) {
20+
if let errorResponse = await waitUntilKeyboardIsPresented(appIds: requestBody.appIds) {
2221
return errorResponse
2322
}
2423

@@ -32,10 +31,14 @@ struct InputTextRouteHandler : HTTPHandler {
3231
}
3332
}
3433

35-
private func waitUntilKeyboardIsPresented(appId: String?) async -> HTTPResponse? {
34+
private func waitUntilKeyboardIsPresented(appIds: [String]) async -> HTTPResponse? {
35+
let foregroundAppIds = RunningApp.getForegroundAppIds(appIds)
36+
logger.info("Foreground apps \(foregroundAppIds)")
37+
3638
let isKeyboardPresented: Bool = (try? await TimeoutHelper.repeatUntil(timeout: 1, delta: 0.2) {
37-
guard let appId = appId else { return true }
38-
return XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists
39+
return foregroundAppIds.contains { appId in
40+
XCUIApplication(bundleIdentifier: appId).keyboards.firstMatch.exists
41+
}
3942
}) ?? false
4043

4144
// Return an error response if the keyboard is not presented

maestro-ios-xctest-runner/maestro-driver-iosUITests/Routes/XCTest/RunningApp.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,14 @@ struct RunningApp {
2424
} ?? RunningApp.springboardBundleId
2525
}
2626

27-
27+
static func getForegroundAppIds(_ appIds: [String]) -> [String] {
28+
// springboard is always on foreground
29+
let allAppIds = appIds + ["com.apple.springboard"]
30+
31+
32+
return allAppIds.filter { appId in
33+
let app = XCUIApplication(bundleIdentifier: appId)
34+
return app.state == .runningForeground
35+
}
36+
}
2837
}

0 commit comments

Comments
 (0)