Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MA 2747] Check keyboard existence in all foreground apps #2184

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

@amanjeetsingh150 amanjeetsingh150 Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the runningApps as well since appsMap was not giving all the list of installed apps.

Includes runningApp as well to make sure we include any system app not in appsMap

}

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
}
}
}
Loading