From 25cf8e683ac92191abef40a1b99f894b01b38d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 27 Feb 2026 20:37:11 +0100 Subject: [PATCH 1/4] fix: use snapshots for raw iOS tree traversal Fixes #147 --- .../RunnerTests.swift | 122 ++++++++---------- 1 file changed, 53 insertions(+), 69 deletions(-) diff --git a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift index 5573001ce8..4146238861 100644 --- a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +++ b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift @@ -1259,23 +1259,6 @@ final class RunnerTests: XCTestCase { center.press(forDuration: 0.05, thenDragTo: endPoint) } - private func aggregatedLabel(for element: XCUIElement, depth: Int = 0) -> String? { - if depth > 2 { return nil } - let text = element.label.trimmingCharacters(in: .whitespacesAndNewlines) - if !text.isEmpty { return text } - if let value = element.value { - let valueText = String(describing: value).trimmingCharacters(in: .whitespacesAndNewlines) - if !valueText.isEmpty { return valueText } - } - let children = element.children(matching: .any).allElementsBoundByIndex - for child in children { - if let childLabel = aggregatedLabel(for: child, depth: depth + 1) { - return childLabel - } - } - return nil - } - private func elementTypeName(_ type: XCUIElement.ElementType) -> String { switch type { case .application: return "Application" @@ -1426,55 +1409,61 @@ final class RunnerTests: XCTestCase { return blocking } - let root = options.scope.flatMap { findScopeElement(app: app, scope: $0) } ?? app + let queryRoot = options.scope.flatMap { findScopeElement(app: app, scope: $0) } ?? app var nodes: [SnapshotNode] = [] var truncated = false let viewport = app.frame - func walk(_ element: XCUIElement, depth: Int) { + let rootSnapshot: XCUIElementSnapshot + do { + rootSnapshot = try queryRoot.snapshot() + } catch { + return DataPayload(nodes: nodes, truncated: truncated) + } + + func walk(_ snapshot: XCUIElementSnapshot, depth: Int, laterSiblings: ArraySlice) { if nodes.count >= maxSnapshotElements { truncated = true return } if let limit = options.depth, depth > limit { return } - if !isVisibleInViewport(element.frame, viewport) { return } - - let label = aggregatedLabel(for: element) ?? element.label.trimmingCharacters(in: .whitespacesAndNewlines) - let identifier = element.identifier.trimmingCharacters(in: .whitespacesAndNewlines) - let valueText: String? = { - guard let value = element.value else { return nil } - let text = String(describing: value).trimmingCharacters(in: .whitespacesAndNewlines) - return text.isEmpty ? nil : text - }() - if shouldInclude(element: element, label: label, identifier: identifier, valueText: valueText, options: options) { + if !isVisibleInViewport(snapshot.frame, viewport) { return } + + let label = aggregatedLabel(for: snapshot) ?? snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) + let identifier = snapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) + let valueText = snapshotValueText(snapshot) + let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterSiblings: laterSiblings) + if shouldInclude( + snapshot: snapshot, + label: label, + identifier: identifier, + valueText: valueText, + options: options, + hittableOverride: hittable + ) { nodes.append( SnapshotNode( index: nodes.count, - type: elementTypeName(element.elementType), + type: elementTypeName(snapshot.elementType), label: label.isEmpty ? nil : label, identifier: identifier.isEmpty ? nil : identifier, value: valueText, - rect: SnapshotRect( - x: Double(element.frame.origin.x), - y: Double(element.frame.origin.y), - width: Double(element.frame.size.width), - height: Double(element.frame.size.height), - ), - enabled: element.isEnabled, - hittable: element.isHittable, + rect: snapshotRect(from: snapshot.frame), + enabled: snapshot.isEnabled, + hittable: hittable, depth: depth, ) ) } - let children = element.children(matching: .any).allElementsBoundByIndex - for child in children { - walk(child, depth: depth + 1) + let children = snapshot.children + for (index, child) in children.enumerated() { + walk(child, depth: depth + 1, laterSiblings: children.suffix(from: index + 1)) if truncated { return } } } - walk(root, depth: 0) + walk(rootSnapshot, depth: 0, laterSiblings: []) return DataPayload(nodes: nodes, truncated: truncated) } @@ -1703,50 +1692,45 @@ final class RunnerTests: XCTestCase { } private func shouldInclude( - element: XCUIElement, + snapshot: XCUIElementSnapshot, label: String, identifier: String, valueText: String?, - options: SnapshotOptions + options: SnapshotOptions, + hittableOverride: Bool? = nil ) -> Bool { - let type = element.elementType + let type = snapshot.elementType + let hittable = hittableOverride ?? snapshotHittable(snapshot) let hasContent = !label.isEmpty || !identifier.isEmpty || (valueText != nil) - if options.compact && type == .other && !hasContent && !element.isHittable { - let children = element.children(matching: .any).allElementsBoundByIndex - if children.count <= 1 { return false } + if options.compact && type == .other && !hasContent && !hittable { + if snapshot.children.count <= 1 { return false } } if options.interactiveOnly { if interactiveTypes.contains(type) { return true } - if element.isHittable && type != .other { return true } + if hittable && type != .other { return true } if hasContent { return true } return false } if options.compact { - return hasContent || element.isHittable + return hasContent || hittable } return true } - private func shouldInclude( - snapshot: XCUIElementSnapshot, - label: String, - identifier: String, - valueText: String?, - options: SnapshotOptions + private func computedSnapshotHittable( + _ snapshot: XCUIElementSnapshot, + viewport: CGRect, + laterSiblings: ArraySlice ) -> Bool { - let type = snapshot.elementType - let hasContent = !label.isEmpty || !identifier.isEmpty || (valueText != nil) - if options.compact && type == .other && !hasContent && !snapshotHittable(snapshot) { - if snapshot.children.count <= 1 { return false } - } - if options.interactiveOnly { - if interactiveTypes.contains(type) { return true } - if snapshotHittable(snapshot) && type != .other { return true } - if hasContent { return true } - return false - } - if options.compact { - return hasContent || snapshotHittable(snapshot) + guard snapshot.isEnabled else { return false } + let frame = snapshot.frame + if frame.isNull || frame.isEmpty { return false } + let center = CGPoint(x: frame.midX, y: frame.midY) + if !viewport.contains(center) { return false } + for sibling in laterSiblings { + let siblingFrame = sibling.frame + if siblingFrame.isNull || siblingFrame.isEmpty { continue } + if siblingFrame.contains(center) { return false } } return true } From d12cc78ff100353e217ff4e7bbcaa52f79e6135a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 27 Feb 2026 20:40:29 +0100 Subject: [PATCH 2/4] refactor: unify snapshot hittable computation across modes --- .../RunnerTests.swift | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift index 4146238861..45ec1ff9eb 100644 --- a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +++ b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift @@ -1320,6 +1320,7 @@ final class RunnerTests: XCTestCase { let rootLabel = aggregatedLabel(for: rootSnapshot) ?? rootSnapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let rootIdentifier = rootSnapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let rootValue = snapshotValueText(rootSnapshot) + let rootHittable = computedSnapshotHittable(rootSnapshot, viewport: viewport, laterSiblings: []) nodes.append( SnapshotNode( index: 0, @@ -1334,15 +1335,21 @@ final class RunnerTests: XCTestCase { height: Double(rootSnapshot.frame.size.height), ), enabled: rootSnapshot.isEnabled, - hittable: snapshotHittable(rootSnapshot), + hittable: rootHittable, depth: 0, ) ) var seen = Set() - var stack: [(XCUIElementSnapshot, Int, Int)] = rootSnapshot.children.map { ($0, 1, 1) } + var stack: [(XCUIElementSnapshot, Int, Int, ArraySlice)] = [] + let rootChildren = rootSnapshot.children + if !rootChildren.isEmpty { + for index in stride(from: rootChildren.count - 1, through: 0, by: -1) { + stack.append((rootChildren[index], 1, 1, rootChildren.suffix(from: index + 1))) + } + } - while let (snapshot, depth, visibleDepth) = stack.popLast() { + while let (snapshot, depth, visibleDepth, laterSiblings) = stack.popLast() { if nodes.count >= fastSnapshotLimit { truncated = true break @@ -1352,6 +1359,7 @@ final class RunnerTests: XCTestCase { let label = aggregatedLabel(for: snapshot) ?? snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let identifier = snapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let valueText = snapshotValueText(snapshot) + let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterSiblings: laterSiblings) let hasContent = !label.isEmpty || !identifier.isEmpty || (valueText != nil) if !isVisibleInViewport(snapshot.frame, viewport) && !hasContent { continue @@ -1362,7 +1370,8 @@ final class RunnerTests: XCTestCase { label: label, identifier: identifier, valueText: valueText, - options: options + options: options, + hittable: hittable ) let key = "\(snapshot.elementType)-\(label)-\(identifier)-\(snapshot.frame.origin.x)-\(snapshot.frame.origin.y)" @@ -1373,8 +1382,11 @@ final class RunnerTests: XCTestCase { if depth < maxDepth { let nextVisibleDepth = include && !isDuplicate ? visibleDepth + 1 : visibleDepth - for child in snapshot.children.reversed() { - stack.append((child, depth + 1, nextVisibleDepth)) + let children = snapshot.children + if !children.isEmpty { + for childIndex in stride(from: children.count - 1, through: 0, by: -1) { + stack.append((children[childIndex], depth + 1, nextVisibleDepth, children.suffix(from: childIndex + 1))) + } } } @@ -1394,7 +1406,7 @@ final class RunnerTests: XCTestCase { height: Double(snapshot.frame.size.height), ), enabled: snapshot.isEnabled, - hittable: snapshotHittable(snapshot), + hittable: hittable, depth: min(maxDepth, visibleDepth), ) ) @@ -1439,7 +1451,7 @@ final class RunnerTests: XCTestCase { identifier: identifier, valueText: valueText, options: options, - hittableOverride: hittable + hittable: hittable ) { nodes.append( SnapshotNode( @@ -1697,10 +1709,9 @@ final class RunnerTests: XCTestCase { identifier: String, valueText: String?, options: SnapshotOptions, - hittableOverride: Bool? = nil + hittable: Bool ) -> Bool { let type = snapshot.elementType - let hittable = hittableOverride ?? snapshotHittable(snapshot) let hasContent = !label.isEmpty || !identifier.isEmpty || (valueText != nil) if options.compact && type == .other && !hasContent && !hittable { if snapshot.children.count <= 1 { return false } @@ -1741,11 +1752,6 @@ final class RunnerTests: XCTestCase { return text.isEmpty ? nil : text } - private func snapshotHittable(_ snapshot: XCUIElementSnapshot) -> Bool { - // XCUIElementSnapshot does not expose isHittable; use enabled as a lightweight proxy. - return snapshot.isEnabled - } - private func aggregatedLabel(for snapshot: XCUIElementSnapshot, depth: Int = 0) -> String? { if depth > 4 { return nil } let text = snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) From 610489527618089aa6bd00b7fa23e59f79a15c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Feb 2026 12:37:57 +0100 Subject: [PATCH 3/4] refactor: account for cousin occlusion in hittable --- .../RunnerTests.swift | 72 ++++++++++++------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift index 45ec1ff9eb..33ccff2e0d 100644 --- a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +++ b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift @@ -1317,10 +1317,13 @@ final class RunnerTests: XCTestCase { return DataPayload(nodes: nodes, truncated: truncated) } + let (flatSnapshots, snapshotRanges) = flattenedSnapshots(rootSnapshot) + let rootRange = snapshotRanges[ObjectIdentifier(rootSnapshot)] ?? (0, 0) + let rootLaterNodes = flatSnapshots.suffix(from: rootRange.1 + 1) let rootLabel = aggregatedLabel(for: rootSnapshot) ?? rootSnapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let rootIdentifier = rootSnapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let rootValue = snapshotValueText(rootSnapshot) - let rootHittable = computedSnapshotHittable(rootSnapshot, viewport: viewport, laterSiblings: []) + let rootHittable = computedSnapshotHittable(rootSnapshot, viewport: viewport, laterNodes: rootLaterNodes) nodes.append( SnapshotNode( index: 0, @@ -1341,15 +1344,9 @@ final class RunnerTests: XCTestCase { ) var seen = Set() - var stack: [(XCUIElementSnapshot, Int, Int, ArraySlice)] = [] - let rootChildren = rootSnapshot.children - if !rootChildren.isEmpty { - for index in stride(from: rootChildren.count - 1, through: 0, by: -1) { - stack.append((rootChildren[index], 1, 1, rootChildren.suffix(from: index + 1))) - } - } + var stack: [(XCUIElementSnapshot, Int, Int)] = rootSnapshot.children.map { ($0, 1, 1) } - while let (snapshot, depth, visibleDepth, laterSiblings) = stack.popLast() { + while let (snapshot, depth, visibleDepth) = stack.popLast() { if nodes.count >= fastSnapshotLimit { truncated = true break @@ -1359,7 +1356,9 @@ final class RunnerTests: XCTestCase { let label = aggregatedLabel(for: snapshot) ?? snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let identifier = snapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let valueText = snapshotValueText(snapshot) - let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterSiblings: laterSiblings) + let snapshotRange = snapshotRanges[ObjectIdentifier(snapshot)] ?? (0, 0) + let laterNodes = flatSnapshots.suffix(from: snapshotRange.1 + 1) + let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterNodes: laterNodes) let hasContent = !label.isEmpty || !identifier.isEmpty || (valueText != nil) if !isVisibleInViewport(snapshot.frame, viewport) && !hasContent { continue @@ -1382,11 +1381,8 @@ final class RunnerTests: XCTestCase { if depth < maxDepth { let nextVisibleDepth = include && !isDuplicate ? visibleDepth + 1 : visibleDepth - let children = snapshot.children - if !children.isEmpty { - for childIndex in stride(from: children.count - 1, through: 0, by: -1) { - stack.append((children[childIndex], depth + 1, nextVisibleDepth, children.suffix(from: childIndex + 1))) - } + for child in snapshot.children.reversed() { + stack.append((child, depth + 1, nextVisibleDepth)) } } @@ -1433,7 +1429,9 @@ final class RunnerTests: XCTestCase { return DataPayload(nodes: nodes, truncated: truncated) } - func walk(_ snapshot: XCUIElementSnapshot, depth: Int, laterSiblings: ArraySlice) { + let (flatSnapshots, snapshotRanges) = flattenedSnapshots(rootSnapshot) + + func walk(_ snapshot: XCUIElementSnapshot, depth: Int) { if nodes.count >= maxSnapshotElements { truncated = true return @@ -1444,7 +1442,9 @@ final class RunnerTests: XCTestCase { let label = aggregatedLabel(for: snapshot) ?? snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let identifier = snapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let valueText = snapshotValueText(snapshot) - let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterSiblings: laterSiblings) + let snapshotRange = snapshotRanges[ObjectIdentifier(snapshot)] ?? (0, 0) + let laterNodes = flatSnapshots.suffix(from: snapshotRange.1 + 1) + let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterNodes: laterNodes) if shouldInclude( snapshot: snapshot, label: label, @@ -1469,13 +1469,13 @@ final class RunnerTests: XCTestCase { } let children = snapshot.children - for (index, child) in children.enumerated() { - walk(child, depth: depth + 1, laterSiblings: children.suffix(from: index + 1)) + for child in children { + walk(child, depth: depth + 1) if truncated { return } } } - walk(rootSnapshot, depth: 0, laterSiblings: []) + walk(rootSnapshot, depth: 0) return DataPayload(nodes: nodes, truncated: truncated) } @@ -1731,21 +1731,43 @@ final class RunnerTests: XCTestCase { private func computedSnapshotHittable( _ snapshot: XCUIElementSnapshot, viewport: CGRect, - laterSiblings: ArraySlice + laterNodes: ArraySlice ) -> Bool { guard snapshot.isEnabled else { return false } let frame = snapshot.frame if frame.isNull || frame.isEmpty { return false } let center = CGPoint(x: frame.midX, y: frame.midY) if !viewport.contains(center) { return false } - for sibling in laterSiblings { - let siblingFrame = sibling.frame - if siblingFrame.isNull || siblingFrame.isEmpty { continue } - if siblingFrame.contains(center) { return false } + for node in laterNodes { + let nodeFrame = node.frame + if nodeFrame.isNull || nodeFrame.isEmpty { continue } + if nodeFrame.contains(center) { return false } } return true } + private func flattenedSnapshots( + _ root: XCUIElementSnapshot + ) -> ([XCUIElementSnapshot], [ObjectIdentifier: (Int, Int)]) { + var ordered: [XCUIElementSnapshot] = [] + var ranges: [ObjectIdentifier: (Int, Int)] = [:] + + @discardableResult + func visit(_ snapshot: XCUIElementSnapshot) -> Int { + let start = ordered.count + ordered.append(snapshot) + var end = start + for child in snapshot.children { + end = max(end, visit(child)) + } + ranges[ObjectIdentifier(snapshot)] = (start, end) + return end + } + + _ = visit(root) + return (ordered, ranges) + } + private func snapshotValueText(_ snapshot: XCUIElementSnapshot) -> String? { guard let value = snapshot.value else { return nil } let text = String(describing: value).trimmingCharacters(in: .whitespacesAndNewlines) From 755d5429f70e0a638f0946d1b650d3e054f04b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 28 Feb 2026 12:48:37 +0100 Subject: [PATCH 4/4] refactor: tighten snapshot occlusion heuristic --- .../RunnerTests.swift | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift index 33ccff2e0d..cd626e8fcd 100644 --- a/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +++ b/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift @@ -1318,8 +1318,11 @@ final class RunnerTests: XCTestCase { } let (flatSnapshots, snapshotRanges) = flattenedSnapshots(rootSnapshot) - let rootRange = snapshotRanges[ObjectIdentifier(rootSnapshot)] ?? (0, 0) - let rootLaterNodes = flatSnapshots.suffix(from: rootRange.1 + 1) + let rootLaterNodes = laterSnapshots( + for: rootSnapshot, + in: flatSnapshots, + ranges: snapshotRanges + ) let rootLabel = aggregatedLabel(for: rootSnapshot) ?? rootSnapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let rootIdentifier = rootSnapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let rootValue = snapshotValueText(rootSnapshot) @@ -1356,8 +1359,11 @@ final class RunnerTests: XCTestCase { let label = aggregatedLabel(for: snapshot) ?? snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let identifier = snapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let valueText = snapshotValueText(snapshot) - let snapshotRange = snapshotRanges[ObjectIdentifier(snapshot)] ?? (0, 0) - let laterNodes = flatSnapshots.suffix(from: snapshotRange.1 + 1) + let laterNodes = laterSnapshots( + for: snapshot, + in: flatSnapshots, + ranges: snapshotRanges + ) let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterNodes: laterNodes) let hasContent = !label.isEmpty || !identifier.isEmpty || (valueText != nil) if !isVisibleInViewport(snapshot.frame, viewport) && !hasContent { @@ -1442,8 +1448,11 @@ final class RunnerTests: XCTestCase { let label = aggregatedLabel(for: snapshot) ?? snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines) let identifier = snapshot.identifier.trimmingCharacters(in: .whitespacesAndNewlines) let valueText = snapshotValueText(snapshot) - let snapshotRange = snapshotRanges[ObjectIdentifier(snapshot)] ?? (0, 0) - let laterNodes = flatSnapshots.suffix(from: snapshotRange.1 + 1) + let laterNodes = laterSnapshots( + for: snapshot, + in: flatSnapshots, + ranges: snapshotRanges + ) let hittable = computedSnapshotHittable(snapshot, viewport: viewport, laterNodes: laterNodes) if shouldInclude( snapshot: snapshot, @@ -1739,6 +1748,7 @@ final class RunnerTests: XCTestCase { let center = CGPoint(x: frame.midX, y: frame.midY) if !viewport.contains(center) { return false } for node in laterNodes { + if !isOccludingType(node.elementType) { continue } let nodeFrame = node.frame if nodeFrame.isNull || nodeFrame.isEmpty { continue } if nodeFrame.contains(center) { return false } @@ -1746,6 +1756,15 @@ final class RunnerTests: XCTestCase { return true } + private func isOccludingType(_ type: XCUIElement.ElementType) -> Bool { + switch type { + case .application, .window: + return false + default: + return true + } + } + private func flattenedSnapshots( _ root: XCUIElementSnapshot ) -> ([XCUIElementSnapshot], [ObjectIdentifier: (Int, Int)]) { @@ -1768,6 +1787,21 @@ final class RunnerTests: XCTestCase { return (ordered, ranges) } + private func laterSnapshots( + for snapshot: XCUIElementSnapshot, + in ordered: [XCUIElementSnapshot], + ranges: [ObjectIdentifier: (Int, Int)] + ) -> ArraySlice { + guard let (_, subtreeEnd) = ranges[ObjectIdentifier(snapshot)] else { + return ordered.suffix(from: ordered.count) + } + let nextIndex = subtreeEnd + 1 + if nextIndex >= ordered.count { + return ordered.suffix(from: ordered.count) + } + return ordered.suffix(from: nextIndex) + } + private func snapshotValueText(_ snapshot: XCUIElementSnapshot) -> String? { guard let value = snapshot.value else { return nil } let text = String(describing: value).trimmingCharacters(in: .whitespacesAndNewlines)