Skip to content

Commit 8001513

Browse files
committed
refactor(ios-runner): resolve the interaction window through one helper
The viewport, the interaction root, and the synthesized reference frame each walked app.windows with their own exists/frame rules, so a sheet or a fold could move one consumer without the others. resolveRunnerWindow is now the single walk: the first window with a non-empty frame, the application otherwise. Alert activation logs the chosen button's label and frame center so a tap that lands beside its button is visible in runner.log.
1 parent 073b568 commit 8001513

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ extension RunnerTests {
6868
guard waitUntilAlertButtonHittable(button, deadline: deadline) else {
6969
return alertVerificationResponse(.timedOut, action: action, activated: false)
7070
}
71+
let buttonFrame = button.frame
72+
NSLog(
73+
"AGENT_DEVICE_RUNNER_ALERT_ACTIVATION action=%@ label=%@ frame=(%.1f,%.1f,%.1f,%.1f) point=(%.1f,%.1f)",
74+
action,
75+
button.label,
76+
buttonFrame.origin.x, buttonFrame.origin.y, buttonFrame.size.width, buttonFrame.size.height,
77+
buttonFrame.midX, buttonFrame.midY
78+
)
7179
// The hittable read above is this activation's readiness gate, so XCTest's pre-synthesis wait
7280
// adds nothing and can cost more than the command has: the tap would land after the deadline
7381
// expired and the alert would be answered by a button the caller was told nothing about

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,25 @@ extension RunnerTests {
219219
// transformed subtrees, so a closed drawer at negative x inflates it and
220220
// out-of-window coordinates still pass containment. Falls back to app.frame
221221
// when no window frame is readable.
222-
func onScreenWindowFrame(app: XCUIApplication) -> CGRect {
223-
let window = app.windows.element(boundBy: 0)
224-
if window.exists {
222+
/// The app window interactions and captures are booked against: the first window the app
223+
/// reports with a non-empty frame, the application itself when none qualifies. The viewport,
224+
/// the interaction root, and the synthesized reference frame all resolve through here, so a
225+
/// fold, a sheet, or a rotation moves every consumer to the same window in the same pass.
226+
/// On iOS the resolved element must be the one whose `screen.displayID` a gesture routes by;
227+
/// reading the frame first is what makes that screen read mean the resolved window.
228+
func resolveRunnerWindow(app: XCUIApplication) -> (element: XCUIElement, frame: CGRect) {
229+
for window in app.windows.allElementsBoundByIndex {
230+
guard window.exists else { continue }
225231
let frame = window.frame
226232
if !frame.isEmpty {
227-
return frame
233+
return (window, frame)
228234
}
229235
}
230-
return app.frame
236+
return (app, app.frame)
237+
}
238+
239+
func onScreenWindowFrame(app: XCUIApplication) -> CGRect {
240+
resolveRunnerWindow(app: app).frame
231241
}
232242

233243
func queryElement(app: XCUIApplication, selectorKey: String, selectorValue: String) -> Response {
@@ -506,11 +516,7 @@ extension RunnerTests {
506516
}
507517

508518
private func interactionRoot(app: XCUIApplication) -> XCUIElement {
509-
let windows = app.windows.allElementsBoundByIndex
510-
if let window = windows.first(where: { $0.exists && !$0.frame.isEmpty }) {
511-
return window
512-
}
513-
return app
519+
resolveRunnerWindow(app: app).element
514520
}
515521

516522
private func performCoordinateTap(app: XCUIApplication, x: Double, y: Double) -> RunnerInteractionOutcome {

0 commit comments

Comments
 (0)