Skip to content

Commit

Permalink
[MA 2747] Check keyboard existence in all foreground apps (#2184)
Browse files Browse the repository at this point in the history
* fix: check keyboard presence in all foreground apps

* fix: list all running apps as well
  • Loading branch information
amanjeetsingh150 authored Dec 12, 2024
1 parent 10019b5 commit 9165c50
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object XCRunnerCLIUtils {
val mapper = jacksonObjectMapper()
val appsMap = mapper.readValue(json, Map::class.java) as Map<String, Any>

return appsMap.keys
return appsMap.keys + runningApps(deviceId).keys
}

fun setProxy(host: String, port: Int) {
Expand Down
Binary file modified maestro-ios-driver/src/main/resources/maestro-driver-ios.zip
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 9165c50

Please sign in to comment.