@@ -175,15 +175,10 @@ extension RunnerTests {
175175
176176 let rootFrame = privateAXRect ( root [ " frame " ] )
177177 let viewport = privateAXSnapshotViewport ( app: app, rootFrame: rootFrame)
178- var nodes : [ SnapshotNode ] = [ ]
179- appendPrivateAXNode (
180- root,
181- to: & nodes,
178+ let nodes = privateAXPresentation (
179+ rawRoot: root,
182180 options: options,
183- viewport: viewport,
184- depth: 0 ,
185- parentIndex: nil ,
186- insideMatchedScope: false
181+ viewport: viewport
187182 )
188183 if nodes. count <= 1 {
189184 NSLog ( " AGENT_DEVICE_RUNNER_PRIVATE_AX_SNAPSHOT_SPARSE=%ld " , nodes. count)
@@ -250,110 +245,7 @@ extension RunnerTests {
250245 }
251246 }
252247
253- private func appendPrivateAXNode(
254- _ rawNode: [ String : Any ] ,
255- to nodes: inout [ SnapshotNode ] ,
256- options: SnapshotOptions ,
257- viewport: CGRect ,
258- depth: Int ,
259- parentIndex: Int ? ,
260- insideMatchedScope: Bool
261- ) {
262- if let limit = options. depth, depth > limit { return }
263-
264- let rect = privateAXRect ( rawNode [ " frame " ] )
265- let label = privateAXString ( rawNode [ " label " ] )
266- let identifier = privateAXString ( rawNode [ " identifier " ] )
267- let value = privateAXString ( rawNode [ " value " ] )
268- let rawType = privateAXInt ( rawNode [ " type " ] ) ?? 0
269- let typeName = elementTypeName ( rawElementType: rawType)
270- let enabled = privateAXBool ( rawNode [ " enabled " ] ) ?? true
271- let visible = isVisibleInViewport ( rect, viewport)
272- let interactiveCandidate = privateAXInteractiveCandidate ( rawElementType: rawType)
273- let filterDecision = flatSnapshotFilterDecision (
274- FlatSnapshotFilterNode (
275- isRoot: parentIndex == nil ,
276- label: label,
277- identifier: identifier,
278- valueText: value. isEmpty ? nil : value,
279- visible: visible
280- ) ,
281- options: options,
282- insideMatchedScope: insideMatchedScope
283- )
284- let include = filterDecision. include
285- let nowInsideScope = filterDecision. insideMatchedScope
286-
287- let currentIndex : Int ?
288- if include {
289- currentIndex = nodes. count
290- nodes. append (
291- SnapshotNode (
292- index: nodes. count,
293- type: typeName,
294- label: label. isEmpty ? nil : label,
295- identifier: identifier. isEmpty ? nil : identifier,
296- value: value. isEmpty ? nil : value,
297- rect: snapshotRect ( from: rect) ,
298- enabled: enabled,
299- focused: privateAXBool ( rawNode [ " focused " ] ) == true ? true : nil ,
300- selected: privateAXBool ( rawNode [ " selected " ] ) == true ? true : nil ,
301- hittable: visible && enabled && interactiveCandidate,
302- depth: depth,
303- parentIndex: parentIndex,
304- hiddenContentAbove: nil ,
305- hiddenContentBelow: nil ,
306- actions: rawNode [ " actions " ] as? [ String ]
307- )
308- )
309- } else {
310- currentIndex = parentIndex
311- }
312-
313- guard let children = rawNode [ " children " ] as? [ [ String : Any ] ] else {
314- return
315- }
316- for child in children {
317- appendPrivateAXNode (
318- child,
319- to: & nodes,
320- options: options,
321- viewport: viewport,
322- depth: depth + 1 ,
323- parentIndex: currentIndex,
324- insideMatchedScope: nowInsideScope
325- )
326- }
327- }
328-
329- private func elementTypeName( rawElementType: Int ) -> String {
330- if let type = flatSnapshotElementType ( rawElementType: rawElementType) {
331- return elementTypeName ( type)
332- }
333- return " Element( \( rawElementType) ) "
334- }
335-
336- private func privateAXString( _ value: Any ? ) -> String {
337- guard let value else { return " " }
338- if let string = value as? String {
339- return string. trimmingCharacters ( in: . whitespacesAndNewlines)
340- }
341- return String ( describing: value) . trimmingCharacters ( in: . whitespacesAndNewlines)
342- }
343-
344- private func privateAXInt( _ value: Any ? ) -> Int ? {
345- if let value = value as? Int { return value }
346- if let value = value as? NSNumber { return value. intValue }
347- return nil
348- }
349-
350- private func privateAXBool( _ value: Any ? ) -> Bool ? {
351- if let value = value as? Bool { return value }
352- if let value = value as? NSNumber { return value. boolValue }
353- return nil
354- }
355-
356- private func privateAXRect( _ value: Any ? ) -> CGRect {
248+ func privateAXRect( _ value: Any ? ) -> CGRect {
357249 guard let frame = value as? [ String : Any ] else {
358250 return . zero
359251 }
@@ -742,15 +634,10 @@ extension RunnerTests {
742634 ] ,
743635 ] ,
744636 ]
745- var nodes : [ SnapshotNode ] = [ ]
746- appendPrivateAXNode (
747- tree,
748- to: & nodes,
637+ let nodes = privateAXPresentation (
638+ rawRoot: tree,
749639 options: SnapshotOptions ( interactiveOnly: false , depth: nil , scope: nil , raw: false ) ,
750- viewport: CGRect ( x: 0 , y: 0 , width: 390 , height: 844 ) ,
751- depth: 0 ,
752- parentIndex: nil ,
753- insideMatchedScope: false
640+ viewport: CGRect ( x: 0 , y: 0 , width: 390 , height: 844 )
754641 )
755642
756643 let card = nodes. first { $0. label == " feedItem-by-whiskers.test " }
@@ -772,15 +659,10 @@ extension RunnerTests {
772659 [ " type " : 9 , " label " : " unrelated sibling " , " children " : [ ] ] ,
773660 ] ,
774661 ]
775- var nodes : [ SnapshotNode ] = [ ]
776- appendPrivateAXNode (
777- tree,
778- to: & nodes,
662+ let nodes = privateAXPresentation (
663+ rawRoot: tree,
779664 options: SnapshotOptions ( interactiveOnly: false , depth: nil , scope: " homeScreen " , raw: false ) ,
780- viewport: . infinite,
781- depth: 0 ,
782- parentIndex: nil ,
783- insideMatchedScope: false
665+ viewport: . infinite
784666 )
785667
786668 let labels = nodes. compactMap { $0. label ?? $0. identifier }
@@ -854,15 +736,10 @@ extension RunnerTests {
854736 ]
855737 ] ,
856738 ]
857- var nodes : [ SnapshotNode ] = [ ]
858- appendPrivateAXNode (
859- tree,
860- to: & nodes,
739+ let nodes = privateAXPresentation (
740+ rawRoot: tree,
861741 options: SnapshotOptions ( interactiveOnly: true , depth: nil , scope: nil , raw: false ) ,
862- viewport: CGRect ( x: 0 , y: 0 , width: 390 , height: 844 ) ,
863- depth: 0 ,
864- parentIndex: nil ,
865- insideMatchedScope: false
742+ viewport: CGRect ( x: 0 , y: 0 , width: 390 , height: 844 )
866743 )
867744
868745 let labels = nodes. compactMap { $0. label }
0 commit comments